【关键字】
swipe/ 嵌套 / web / list / 滚动 / 禁用滑动
【问题描述】
在swipe嵌套web/list存在垂直滚动时,在用户垂直滚动,能否禁用swipe的左右滑动?
【解决方案】
可以使用disableSwipe方法禁用组件滑动切换功能。
简单示例如下:
import web_webview from '@ohos.web.webview'
@Entry
@Component
struct SwiperPage {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
private swiperController: SwiperController = new SwiperController()
controller: web_webview.WebviewController = new web_webview.WebviewController()
@State canSwipe: boolean = false
build() {
Column() {
Swiper(this.swiperController) {
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item: number) => {
ListItem() {
Text('' + item)
.width('100%')
.height(100)
.fontSize(16)
.textAlign(TextAlign.Center)
}
}, (item: string) => item)
}.width('90%')
.height('90%')
Text('1')
.width('90%')
.height('90%')
.textAlign(TextAlign.Center)
.fontSize(30)
Web({ src: 'https://www.taobao.com/', controller: this.controller })
.width('90%')
.height('90%')
.onTouch((event?: TouchEvent) => { // 具体处理逻辑根据实际需求修改,这里仅作为示例参考
if (event) {
if (event.type === TouchType.Down || event.type === TouchType.Move) {
this.canSwipe = true
} else {
this.canSwipe = false
}
}
})
}
.interval(3000)
.autoPlay(true)
.disableSwipe(this.canSwipe)
}
.width('100%')
.height('100%')
}
}