HarmonyOS SideBarContainer使用问题

SideBarContainer设置showControlButton = false,隐藏自带的按钮,自定义展开和收起时,没有动画效果,只有自带的ControlButton点击才会有动画效果,这个是什么原因,如果自定义按钮,需要自己写动画吗?

HarmonyOS
2024-12-24 16:48:34
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

可以参考demo:

@Entry
@Component
struct SideBarContainerDemo {
  @State arr: number[] = [1, 2, 3]
  @State current: number = 1
  @State showSideBar: boolean = false
  @State showFlag: Visibility = Visibility.Hidden;

  // 延迟关闭侧边栏,让自定义的出场动画显示
  cancel() {
    this.showFlag = Visibility.Hidden
    setTimeout(() => {
      this.showSideBar = !this.showSideBar
    }, 1000)
  }

  build() {
    SideBarContainer(SideBarContainerType.Overlay) {
      Column() {
        ForEach(this.arr, (item: number) => {
          Column({ space: 5 }) {
            Text("Index0" + item )
              .fontSize(25)
              .fontColor(this.current === item ? '#0A59F7' : '#999')
              .fontFamily('source-sans-pro,cursive,sans-serif')
          }

          .onClick(() => {
            this.current = item
          })
        }, (item: string) => item)
      }
      .visibility(this.showFlag)
      .transition(TransitionEffect.OPACITY.animation({ duration: 1000 })
        .combine(TransitionEffect.translate({ x: 100 })))
      .width('100%')
      .justifyContent(FlexAlign.SpaceEvenly)
      .backgroundColor(Color.Pink)

      Column() {
        Button('打开侧边栏').onClick(() => {
          this.showFlag = Visibility.Visible
          this.showSideBar = true
        }
        )
        Button('关闭侧边栏').onClick(() => {
          this.cancel()
        })
      }
    }
    .divider(null)
    .sideBarPosition(SideBarPosition.End)
    .showSideBar(this.showSideBar)
    .showControlButton(false)
    .sideBarWidth(150)
    .minSideBarWidth(50)
    .maxSideBarWidth(300)
    .minContentWidth(0)
    .onChange((value: boolean) => {
      console.info('status:' + value)
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
分享
微博
QQ
微信
回复
2024-12-24 18:59:46


相关问题
HarmonyOS SideBarContainer 转场动画
546浏览 • 1回复 待解决
SideBarContainer如何设置controlButton属性
2489浏览 • 1回复 待解决
SideBarContainer如何设置透明度?
2984浏览 • 1回复 待解决
HarmonyOS RichEditor 使用问题
1190浏览 • 1回复 待解决
HarmonyOS Navigation使用问题
1257浏览 • 1回复 待解决
HarmonyOS AudioCapturer使用问题
609浏览 • 1回复 待解决
HarmonyOS RSA使用问题
474浏览 • 1回复 待解决
HarmonyOS Navigation 使用问题
1177浏览 • 1回复 待解决
HarmonyOS CustomDialogController使用问题
518浏览 • 1回复 待解决
HarmonyOS resourceManager使用问题
1298浏览 • 1回复 待解决
HarmonyOS Worker使用问题
658浏览 • 1回复 待解决
HarmonyOS地图使用问题
977浏览 • 1回复 待解决
HarmonyOS soundpool使用问题
1160浏览 • 1回复 待解决
HarmonyOS @Link使用问题
667浏览 • 1回复 待解决
HarmonyOS lottie使用问题
1029浏览 • 1回复 待解决
HarmonyOS websocket使用问题
1036浏览 • 1回复 待解决