1、问题描述:
swiper嵌套子组件,子组件里面有PanGesture,有冲突swiper消费了滑动手势,该如何解决?
demo如下:
- // @ts-nocheck
-
- @Entry
-
- @Component
-
- struct PanGestureExample {
-
- @State offsetX: number = 0
-
- @State offsetY: number = 0
-
- build() {
-
- Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
-
- Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY)
-
- }
-
- .height(100).width(200).padding(20).border({ width: 1 }).margin(80)
-
- .translate({ x: this.offsetX, y: this.offsetY, z: 5 })
-
- .gesture(
-
- PanGesture({})
-
- .onActionStart((event: GestureEvent) => {
-
- console.info('Pan start')
-
- })
-
- .onActionUpdate((event: GestureEvent) => {
-
- this.offsetX = event.offsetX
-
- this.offsetY = event.offsetY
-
- })
-
- .onActionEnd(() => {
-
- console.info('Pan end')
-
- })
-
- )
-
- }
-
- }
解决方案:
建议在PhotoView的父组件Swiper上设置priorityGesture属性,默认情况下,子组件优先于父组件识别手势,当父组件配置priorityGesture时,父组件优先于子组件进行识别。参考如下代码:
- Swiper()
-
- ...
-
- .priorityGesture(
-
- TapGesture()
-
- .onAction(() => {
-
- }), GestureMask.IgnoreInternal
-
- )
2、问题描述:
eTS scroll 组件,设置scrollable(ScrollDirection.Horizontal)时,为什么横向滚动滚动条不显示?
demo如下:
- @Entry
-
- @Component
-
- struct scrollerPage {
-
- scroller: Scroller = new Scroller()
-
- private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-
- build() {
-
- Stack({ alignContent: Alignment.TopStart }) {
-
- Scroll(this.scroller) {
-
- Row({ space: 20 }) {
-
- Row().width(150).height(50).backgroundColor(0xAFEEEE)
-
- Row().width(150).height(50).backgroundColor(0x00FFFF)
-
- }.width("200%").height(52).border({ width: 1 }).margin({ top: 20 })
-
- }
-
- .scrollable(ScrollDirection.Horizontal).scrollBar(BarState.On)
-
- .scrollBarColor(Color.Red).scrollBarWidth(30)
-
- .onScroll((xOffset: number, yOffset: number) => {
-
- console.info(xOffset + ' ' + yOffset)
-
- })
-
- .onScrollEdge((side: Edge) => {
-
- console.info('To the edge')
-
- })
-
- .onScrollEnd(() => {
-
- console.info('Scroll Stop')
-
- })
-
- }.width('100%').height('100%').backgroundColor(0xDCDCDC)
-
- }
-
- }
解决方案:
横向的Scroll是没有滑动条显示的,如果需要可以用ScrollBar组件自定义
js中类似于scrollview是list和list-item组件联合使用,示例如下:
1、对应hml中遍历js中定义的imageList数据:
- <list class="text_container">
-
- <list-item type="listItem" for="{{imageList}}">
-
- <image class="img" src="{{$item.value}}">image>
-
- list-item>
-
- list>
2、对应js中的imageList定义:
- data: {
-
- imageList: [{value: "/common/1.jpg"}, {value: "/common/2.jpg"}, {value: "/common/3.jpg"}, {value: "/common/4.jpg"}],
-
- }
3、可将步骤1中image标签改为div等标签自行定义
4、默认为纵向,横向、纵向属性分别如下:
- style="flex-direction:row"
-
- style="flex-direction:column"
3、问题描述:
设备的DVID有什么方式可以校验是否是真实的设备吗?
解决方案:
DVID不是某个设备的ID,是指由同一个鸿蒙账号的多个设备组成一个超级终端后的虚拟ID
相关参考链接:文档中心
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh