diff --git a/GesturesConfictPractice/README.md b/GesturesConfictPractice/README.md index b9a583fbbcafde0fd6aaa46428d78abf16f05ffd..3a83c519928091d1919f4364aaee40ca739619f1 100644 --- a/GesturesConfictPractice/README.md +++ b/GesturesConfictPractice/README.md @@ -4,6 +4,19 @@ 本代码示例展示了多个组件嵌套时同时绑定手势事件,或者同一个组件同时绑定多个手势等场景下,手势冲突问题的解决。 +### 效果说明 + +* GesturesConflictScene1:Scroll组件和List组件嵌套滑动冲突解决方案,Scroll组件和List组件实现整体滑动。 +* GesturesConflictScene2:单击手势和双击手势互斥执行,优先响应单击,无法响应双击事件。 +* GesturesConflictScene2A:单击手势和双击手势并行执行,单击和双击事件同时执行。 +* GesturesConflictScene3:系统手势覆盖自定义手势,长按Image组件,Image组件放大,自定义长按手势不会触发。 +* GesturesConflictScene3A:自定义手势使用优先级手势priorityGesture,长按Image组件,Image组件无变化,自定义长按手势触发,弹出Toast提示。 +* GesturesConflictScene4:手势事件透传,在层的红色组件上左右滑动,弹出Toast提示。 +* GesturesConflictScene5:Button1使用事件独占属性.monopolizeEvents(true)后,一个手指按住Button1,另一个手指点击Button2,不会出发Button2的点击事件。 +* GesturesConflictScene6:长按红色区域不会触发拖拽效果。 +* GesturesConflictScene7:Scroll组件嵌套Scroll组件实现联合滚动。 +* WebScrollDemo:Web组件和Scroll组件嵌套,红色区域的Text组件和Web组件一起滚动。 + #### 使用说明 安装运行应用,进入应用首页,点击不同的按钮跳转到不同的手势场景示例。 @@ -18,8 +31,8 @@ │ │ └──EntryBackupAbility.ets // 数据备份恢复类 │ └──pages │ ├──GesturesConflictScene1.ets // 滚动容器嵌套滚动容器事件冲突 -│ ├──GesturesConflictScene2.ets // 使用组合手势同时绑定多个同类型手势冲突解反例 -│ ├──GesturesConflictScene2A.ets // 使用组合手势同时绑定多个同类型手势冲突解正例 +│ ├──GesturesConflictScene2.ets // 使用组合手势同时绑定多个同类型手势冲突解反例 +│ ├──GesturesConflictScene2A.ets // 使用组合手势同时绑定多个同类型手势冲突解正例 │ ├──GesturesConflictScene3.ets // 系统手势和自定义手势之间冲突反例 │ ├──GesturesConflictScene3A.ets // 系统手势和自定义手势之间冲突正例 │ ├──GesturesConflictScene4.ets // 手势事件透传 @@ -27,13 +40,13 @@ │ ├──GesturesConflictScene6.ets // 动态控制自定义手势是否响应 │ ├──GesturesConflictScene7.ets // 父组件如何管理子组件手势 │ ├──Index.ets // 应用首页 -│ └──TestCode.ets // Web组件示例 +│ └──WebScrollDemo.ets // Web组件和Scroll组件嵌套示例 └──entry/src/main/resources // 应用资源目录 ``` ### 相关权限 -不涉及 +* 允许使用Internet网络:ohos.permission.INTERNET。 ## 约束与限制 diff --git a/GesturesConfictPractice/build-profile.json5 b/GesturesConfictPractice/build-profile.json5 index 6e060d8e071b22b3a986264720ffd7e92b4d20aa..b2ca56e35558b0dc7ca91989b68a1ea65b49a7a2 100644 --- a/GesturesConfictPractice/build-profile.json5 +++ b/GesturesConfictPractice/build-profile.json5 @@ -1,20 +1,6 @@ { "app": { - "signingConfigs": [ - { - "name": "default", - "type": "HarmonyOS", - "material": { - "certpath": "C:\\Users\\kl\\.ohos\\config\\default_GesturesConfictPractice_KFdURs0XiEcbni4lqvihGLgRTxLgrZwBY9K9w_2bgF4=.cer", - "keyAlias": "debugKey", - "keyPassword": "0000001B98687470C41AD5D2395DCA999D14C0AAD483063F11D9A44283733D9145D8FAB29F7075B9E1C485", - "profile": "C:\\Users\\kl\\.ohos\\config\\default_GesturesConfictPractice_KFdURs0XiEcbni4lqvihGLgRTxLgrZwBY9K9w_2bgF4=.p7b", - "signAlg": "SHA256withECDSA", - "storeFile": "C:\\Users\\kl\\.ohos\\config\\default_GesturesConfictPractice_KFdURs0XiEcbni4lqvihGLgRTxLgrZwBY9K9w_2bgF4=.p12", - "storePassword": "0000001B2E7BF5B01846D1CD2407B30E356F865D761E823FC9734C4605952FCDAEF60A27691C417B37D324" - } - } - ], + "signingConfigs": [], "products": [ { "name": "default", diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets index 815a2148fabaf2cbe445b50a972d582d964a9d46..f116addb5e4b087c26afa4af1f49ae2cafa593a6 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets @@ -22,8 +22,7 @@ struct GesturesConflictScene2 { build() { Column() { - Text('Exclusive gesture\n' + 'tapGesture count is 1:' + this.count1 + '\ntapGesture count is 2:' + this.count2 + - '\n') + Text('Exclusive gesture\n' + 'Click count is:' + this.count1 + '\nDouble click count is:' + this.count2 + '\n') .fontSize(28) } .height(200) diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2A.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2A.ets index 46336a52e6742ecb66189015f9549e1ccf34c4a2..c38b082cefe7c7fd96287e036208eff4383ba93e 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2A.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2A.ets @@ -21,8 +21,7 @@ struct GesturesConflictScene21 { build() { Column() { - Text('Exclusive gesture\n' + 'tapGesture count is 1:' + this.count1 + '\ntapGesture count is 2:' + this.count2 + - '\n') + Text('Exclusive gesture\n' + 'Click count is:' + this.count1 + '\nDouble click count is:' + this.count2 + '\n') .fontSize(28) } .height(200) diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets index e3c2e18204bb702571be75527286d7a57dda7e31..af7d20b2315490d1cc985de20373298d5960c942 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets @@ -14,6 +14,9 @@ */ // [Start gestures_conflict_scene4] +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; + @Entry @Component struct GesturesConflictScene4 { @@ -27,7 +30,12 @@ struct GesturesConflictScene4 { SwipeGesture({ direction: SwipeDirection.Horizontal })//水平方向滑动手势 .onAction((event) => { if (event) { - console.info('Column SwipeGesture'); + try { + this.getUIContext().getPromptAction().showToast({ message: 'SwipeGesture' }); + } catch (err) { + let error = err as BusinessError; + hilog.error(0x0000, 'testTag', `showToast err, code: ${error.code}, mesage: ${error.message}`); + } } }) ) diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene5.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene5.ets index 28ab0eb677cd9fc7c59d45e454f6e2e9d96099e2..724afc43ff8e1c82e457b616a5263eed8ed809ee 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene5.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene5.ets @@ -14,6 +14,9 @@ */ // [Start gestures_conflict_scene5] +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + @Entry @Component struct GesturesConflictScene5 { @@ -30,7 +33,12 @@ struct GesturesConflictScene5 { .width(200) .height(50) .onClick(() => { - console.info('GesturesConflictScene5 Button2 click'); + try { + this.getUIContext().getPromptAction().showToast({ message: 'GesturesConflictScene5 Button2 click' }); + } catch (err) { + let error = err as BusinessError; + hilog.error(0x0000, 'testTag', `showToast err, code: ${error.code}, mesage: ${error.message}`); + } }) } .margin(20) @@ -39,9 +47,6 @@ struct GesturesConflictScene5 { .margin(15) } .width('100%') - .onDragStart(() => { - console.info('GesturesConflictScene5 Drag start.'); - }) .gesture( TapGesture({ count: 1 }) .onAction(() => { diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/Index.ets b/GesturesConfictPractice/entry/src/main/ets/pages/Index.ets index 79c2917678c1278d5a65953338e8fdf253a7b7fe..a84d417d2654b0fc7a9e4b76f5adaa334d6fc6bb 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/Index.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/Index.ets @@ -83,6 +83,12 @@ struct Index { .onClick(() => { this.jumperPage('GesturesConflictScene7'); }) + + Button('WebDemo') + .width('100%') + .onClick(() => { + this.jumperPage('TestCode'); + }) } .height('100%') .width('100%') diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets b/GesturesConfictPractice/entry/src/main/ets/pages/WebScrollDemo.ets similarity index 58% rename from GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets rename to GesturesConfictPractice/entry/src/main/ets/pages/WebScrollDemo.ets index 0660c014c3346296b63df1e0f7d726c74b1f7d9f..664d8d56c906c8fdf2f5977b5b3601d24443cbfa 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/WebScrollDemo.ets @@ -15,21 +15,32 @@ import { webview } from '@kit.ArkWeb'; +@Entry @Component -struct StackA { +struct WebScrollDemo { controller: webview.WebviewController = new webview.WebviewController(); build() { // [Start web_nested_scroll] - Web( - // [StartExclude web_nested_scroll] - { src: 'https://developer.huawei.com/consumer/cn/', controller: this.controller } - // [EndExclude web_nested_scroll] - ) - .nestedScroll({ - scrollForward: NestedScrollMode.PARENT_FIRST, - scrollBackward: NestedScrollMode.SELF_FIRST - }) + Scroll() { + Column() { + Text('Text') + .fontSize(50) + .backgroundColor(Color.Red) + .width('100%') + .height('40%') + Web( + // [StartExclude web_nested_scroll] + { src: 'https://developer.huawei.com/consumer/cn/', controller: this.controller } + // [EndExclude web_nested_scroll] + ) + .nestedScroll({ + scrollForward: NestedScrollMode.PARENT_FIRST, + scrollBackward: NestedScrollMode.SELF_FIRST + }) + + } + } // [End web_nested_scroll] } } \ No newline at end of file diff --git a/GesturesConfictPractice/entry/src/main/module.json5 b/GesturesConfictPractice/entry/src/main/module.json5 index ad219d733f6afa5ea07f85f580208b08cc3b9041..dd39cd499613b5fbf11765616bd1431c52fb8d82 100644 --- a/GesturesConfictPractice/entry/src/main/module.json5 +++ b/GesturesConfictPractice/entry/src/main/module.json5 @@ -43,7 +43,12 @@ "name": "ohos.extension.backup", "resource": "$profile:backup_config" } - ], + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET" } ] } diff --git a/GesturesConfictPractice/entry/src/main/resources/base/profile/main_pages.json b/GesturesConfictPractice/entry/src/main/resources/base/profile/main_pages.json index 1d6b935f7409cf9e7c4da7b0b7702952e2bbc012..57174054964056e515f8c0ab1873fa8e1975236c 100644 --- a/GesturesConfictPractice/entry/src/main/resources/base/profile/main_pages.json +++ b/GesturesConfictPractice/entry/src/main/resources/base/profile/main_pages.json @@ -9,6 +9,7 @@ "pages/GesturesConflictScene6", "pages/GesturesConflictScene7", "pages/GesturesConflictScene2A", - "pages/GesturesConflictScene3A" + "pages/GesturesConflictScene3A", + "pages/WebScrollDemo" ] } \ No newline at end of file