HarmonyOS tabs组件如何取消最左侧和最右侧回弹效果?

用tabs组件写界面切换,最左侧和最右侧不存在界面时,需求取消回弹效果,要求不能继续滑动

阅读 476
1 个回答

边缘tab继续滑动可以通过给TabContent添加手势进行限制。

具体方案如下:

最左侧的TabContent添加.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Right })))。

对最右侧的TabContent添加.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Left })))。

demo:

@Entry
@Component
struct Index {
  private controller: TabsController = new TabsController()
  build() {
    Tabs({barPosition: BarPosition.Start, controller: this.controller}){
      TabContent(){
        Text("123")
      }.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Right })))
      TabContent(){
        Text("456")
      }.gesture(PanGesture(new PanGestureOptions({ direction: PanDirection.Left })))
    }
    .barHeight(0)
    .vertical(false)
    .scrollable(true)
    .onChange((index: number) => {

    })

  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进