HarmonyOS Tabs嵌套使用问题

两层Tab嵌套希望子tab向右滑动到最后一个index时候继续滑动,上层的tab自动滑动到下一级。文档的答案不行,只是简单禁用上级滑动不能联动。

https://developer.huawei.com/consumer/cn/doc/harmonyos-faqs-V5/faqs-arkui-19-V5

HarmonyOS
2024-12-25 12:43:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
put_get

示例参考如下:

@Entry
@Component
struct TabsExample {
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()
  @State subCurrentIndex: number = 0
  private subController: TabsController = new TabsController()
  private panOptionRight: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left })
  private panOptionLeft: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Right })

  @Builder
  tabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(16)
        .fontWeight(this.currentIndex === index ? 500 : 400)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
      Divider()
        .strokeWidth(2)
        .color('#007DFF')
        .opacity(this.currentIndex === index ? 1 : 0)
    }.width('100%')
  }

  @Builder
  subTabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.subCurrentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(16)
        .fontWeight(this.subCurrentIndex === index ? 500 : 400)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })
      Divider()
        .strokeWidth(2)
        .color('#007DFF')
        .opacity(this.subCurrentIndex === index ? 1 : 0)
    }.width('100%')
  }

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#ffb554d7')
        }.tabBar(this.tabBuilder(0, '首页'))

        TabContent() {
          Column() {
            Tabs({ barPosition: BarPosition.Start, controller: this.subController }) {
              TabContent() {
                Column().width('100%').height('100%').backgroundColor('#00CB87')// 左右拖动触发该手势事件
                  .gesture(
                    PanGesture(this.panOptionLeft)
                      .onActionStart((event?: GestureEvent) => {
                        console.info('Pan start')
                      })
                      .onActionUpdate((event?: GestureEvent) => {
                        if (event) {

                        }
                      })
                      .onActionEnd(() => {
                        this.controller.changeIndex(0)
                        console.info('Pan end')
                      })
                  )
              }.tabBar(this.subTabBuilder(0, 'green'))

              TabContent() {
                Column().width('100%').height('100%').backgroundColor('#007DFF')
              }.tabBar(this.subTabBuilder(1, 'blue'))

              TabContent() {
                Column().width('100%').height('100%').backgroundColor('#FFBF00')
              }.tabBar(this.subTabBuilder(2, 'yellow'))

              TabContent() {
                Column().width('100%').height('100%').backgroundColor('#E67C92')// 左右拖动触发该手势事件
                  .gesture(
                    PanGesture(this.panOptionRight)
                      .onActionStart((event?: GestureEvent) => {
                        console.info('Pan start')
                      })
                      .onActionUpdate((event?: GestureEvent) => {
                        if (event) {

                        }
                      })
                      .onActionEnd(() => {
                        this.controller.changeIndex(2)
                        console.info('Pan end')
                      })
                  )
              }.tabBar(this.subTabBuilder(3, 'pink'))
            }
            .vertical(false)
            .barMode(BarMode.Fixed)
            .barWidth(360)
            .barHeight(56)
            .animationDuration(400)
            .onChange((index: number) => {
              this.subCurrentIndex = index
            })
            .width(360)
            .backgroundColor('#F1F3F5')
          }
          .width('100%').height('100%').backgroundColor('#00CB87')
        }.tabBar(this.tabBuilder(1, '详情'))

        TabContent() {
          Column().width('100%').height('100%').backgroundColor('#ffc19757')
        }.tabBar(this.tabBuilder(2, '我的'))

      }
      .vertical(false)
      .barMode(BarMode.Fixed)
      .barWidth(360)
      .barHeight(56)
      .animationDuration(400)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width(360)
      .height(296)
      .margin({ top: 52 })
      .backgroundColor('#F1F3F5')
    }.width('100%')
  }
}
分享
微博
QQ
微信
回复
2024-12-25 14:46:03
相关问题
HarmonyOS Tabs组件嵌套Tabs组件问题
1045浏览 • 1回复 待解决
HarmonyOS Tabs嵌套Grid问题
231浏览 • 1回复 待解决
HarmonyOS Tabs和Web嵌套左右滑动问题
428浏览 • 1回复 待解决
HarmonyOS Tabs组件嵌套滑动
666浏览 • 1回复 待解决
HarmonyOS ListItem嵌套Tabs显示不全
127浏览 • 1回复 待解决
Tabs组件嵌套滑动组件
1760浏览 • 1回复 待解决
HarmonyOS Tabs和Swiper联合使用问题
141浏览 • 1回复 待解决
HarmonyOS Web组件和List的嵌套使用问题
574浏览 • 1回复 待解决
如何处理tabs嵌套web滑动场景
676浏览 • 1回复 待解决
HarmonyOS tabs切换问题
50浏览 • 1回复 待解决
HarmonyOS List嵌套List和List嵌套Grid问题
201浏览 • 1回复 待解决
HarmonyOS tabs对齐问题
147浏览 • 1回复 待解决
HarmonyOS Tabs位置问题
65浏览 • 1回复 待解决
HarmonyOS lazyForeach嵌套视图问题
430浏览 • 1回复 待解决
HarmonyOS Scroll嵌套RelativeContainer 问题
467浏览 • 1回复 待解决
HarmonyOS 嵌套滑动问题
480浏览 • 1回复 待解决
HarmonyOS WaterFlow嵌套问题
136浏览 • 1回复 待解决
HarmonyOS ArkUI 嵌套组件问题
212浏览 • 1回复 待解决
HarmonyOS 组件嵌套问题
483浏览 • 1回复 待解决