From 60a111bf643c8384cf7c6c9809e95d7130ed243a Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Mon, 26 May 2025 17:21:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20GesturesConflictPractice=20=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/GesturesConflictScene1.ets | 2 - .../main/ets/pages/GesturesConflictScene2.ets | 6 +- .../main/ets/pages/GesturesConflictScene3.ets | 4 +- .../ets/pages/GesturesConflictScene3A.ets | 6 +- .../main/ets/pages/GesturesConflictScene4.ets | 4 +- .../main/ets/pages/GesturesConflictScene6.ets | 2 +- .../main/ets/pages/GesturesConflictScene7.ets | 26 ++++---- .../entry/src/main/ets/pages/TestCode.ets | 62 +++++++++++++++++++ 8 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene1.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene1.ets index 6f6c1640..7bb59e01 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene1.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene1.ets @@ -41,12 +41,10 @@ struct GesturesConflictScene1 { }, (item: number) => item.toString()) } .edgeEffect(EdgeEffect.None) - // [Start nested_scroll] .nestedScroll({ scrollForward: NestedScrollMode.PARENT_FIRST, scrollBackward: NestedScrollMode.SELF_FIRST }) - // [End nested_scroll] .height('100%') .width('100%') } diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets index 7bc5f1e6..c33a5ae5 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene2.ets @@ -34,9 +34,9 @@ struct GesturesConflictScene2 { } .height(200) .width('100%') - //以下组合手势为互斥并别,单击手势识别成功后,双击手势会识别失败 + // The following gestures are mutually exclusive. After the gesture is successfully recognized, the gesture cannot be recognized by double-clicking + // [Start getture_group2] .gesture( - // [Start getture_group2] GestureGroup(GestureMode.Exclusive, TapGesture({ count: 1 }) .onAction(() => { @@ -47,8 +47,8 @@ struct GesturesConflictScene2 { this.count2++; }) ) - // [End getture_group2] ) + // [End getture_group2] } } diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3.ets index 352c5fd9..4b0a60d8 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3.ets @@ -38,14 +38,12 @@ struct GesturesConflictScene3 { .width(360) .height(360) .gesture( - // [Start long_press_gesture] LongPressGesture({ repeat: true }) .onAction((event: GestureEvent) => { - })// 长按动作一结束触发 + })// The long press action ends .onActionEnd(() => { this.getUIContext().getPromptAction().showToast({ message: 'Long Press' }); }) - // [End long_press_gesture] ) } .width('100%') diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3A.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3A.ets index 61feda53..14d2474b 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3A.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene3A.ets @@ -37,16 +37,16 @@ struct GesturesConflictScene3A { .margin({ top: 100 }) .width(360) .height(360) - // DocsCode 1 + // [Start long_press_gesture] .priorityGesture( LongPressGesture({ repeat: true }) .onAction((event: GestureEvent) => { - })// 长按动作一结束触发 + })// The long press action ends .onActionEnd(() => { this.getUIContext().getPromptAction().showToast({ message: 'Long Press' }); }) ) - // DocsCode 1 + // [End long_press_gesture] } .width('100%') } diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets index e978308c..fd980c01 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene4.ets @@ -25,7 +25,7 @@ struct GesturesConflictScene4 { build() { Stack() { - Column()//底层的Column + Column()// The bottom column .width('100%') .height('100%') .backgroundColor(Color.Black) @@ -37,7 +37,7 @@ struct GesturesConflictScene4 { } }) ) - Column()//上层的Column + Column()// The upper-level column .width(300) .height(100) .backgroundColor(Color.Red) diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene6.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene6.ets index f782489d..4a1b3350 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene6.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene6.ets @@ -46,7 +46,7 @@ struct GesturesConflictScene6 { console.info('GesturesConflictScene6: ' + longPressEvent.repeat); } if (gestureInfo.type === GestureControl.GestureType.DRAG) { - // 返回 REJECT 会使拖动手势失败 + // Returning to the REJECT will fail the drag gesture return GestureJudgeResult.REJECT; } else if (gestureInfo.tag === 'tap1' && event.pressure > 10) { return GestureJudgeResult.CONTINUE diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene7.ets b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene7.ets index 90957c21..7f42ce2c 100644 --- a/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene7.ets +++ b/GesturesConfictPractice/entry/src/main/ets/pages/GesturesConflictScene7.ets @@ -31,7 +31,7 @@ struct GesturesConflictScene7 { build() { Stack({ alignContent: Alignment.TopStart }) { - Scroll(this.scroller) { // 外部滚动容器 + Scroll(this.scroller) { // External rolling container Column() { Text('Scroll Area') .width('100%') @@ -41,7 +41,7 @@ struct GesturesConflictScene7 { .fontSize(16) .textAlign(TextAlign.Center) .margin({ top: 10 }) - Scroll(this.scroller2) { // 内部滚动容器 + Scroll(this.scroller2) { // internal rolling container Column() { Text('Scroll Area2') .width('100%') @@ -67,30 +67,30 @@ struct GesturesConflictScene7 { } } .id('innerScroll') - .scrollBar(BarState.Off) // 滚动条常驻显示 + .scrollBar(BarState.Off) // The scroll bar is always displayed .width('100%') .height(800) }.width('100%') } .id('outerScroll') .height(600) - .scrollBar(BarState.Off) // 滚动条常驻显示 + .scrollBar(BarState.Off) // The scroll bar is always displayed .shouldBuiltInRecognizerParallelWith((current: GestureRecognizer, others: Array) => { for (let i = 0; i < others.length; i++) { let target = others[i].getEventTargetInfo(); if (target) { if (target.getId() === 'innerScroll' && others[i].isBuiltIn() && - others[i].getType() === GestureControl.GestureType.PAN_GESTURE) { // 找到将要组成并行手势的识别器 - this.currentRecognizer = current; // 保存当前组件的识别器 - this.childRecognizer = others[i]; // 保存将要组成并行手势的识别器 - return others[i]; // 返回将要组成并行手势的识别器 + others[i].getType() === GestureControl.GestureType.PAN_GESTURE) { // Find the recognizer that will form the parallel gesture + this.currentRecognizer = current; // Save the recognizer of the current component + this.childRecognizer = others[i]; // Save the recognizer that will form the parallel gesture + return others[i]; // Return the recognizer that will form the parallel gesture } } } return undefined; }) .onGestureRecognizerJudgeBegin((event: BaseGestureEvent, current: GestureRecognizer, - others: Array) => { // 在识别器即将要成功时,根据当前组件状态,设置识别器使能状态 + others: Array) => { // When the recognizer is about to succeed, set the recognizer enabling status according to the current component status if (current) { let target = current.getEventTargetInfo(); if (target) { @@ -99,18 +99,18 @@ struct GesturesConflictScene7 { if (others) { for (let i = 0; i < others.length; i++) { let target = others[i].getEventTargetInfo() as ScrollableTargetInfo; - if (target instanceof ScrollableTargetInfo && target.getId() == 'innerScroll') { // 找到响应链上对应并行的识别器 + if (target instanceof ScrollableTargetInfo && target.getId() == 'innerScroll') { // Find the corresponding parallel recognizer on the response chain let panEvent = event as PanGestureEvent; - if (target.isEnd()) { // isEnd返回当前滚动类容器组件是否在底部 根据当前组件状态以及移动方向动态控制识别器使能状态 + if (target.isEnd()) { // isEnd returns whether the current rolling container component is at the bottom of the dynamic control status of the recognizer based on the current component status and movement direction if (panEvent && panEvent.offsetY < 0) { - this.childRecognizer.setEnabled(false) // 到底上拉 + this.childRecognizer.setEnabled(false) // When it's the end, pull up this.currentRecognizer.setEnabled(true) } else { this.childRecognizer.setEnabled(true) this.currentRecognizer.setEnabled(false) } } else if (target.isBegin()) { - if (panEvent.offsetY > 0) { // 开始的时候下拉 + if (panEvent.offsetY > 0) { // Pull down at the beginning this.childRecognizer.setEnabled(false) this.currentRecognizer.setEnabled(true) } else { diff --git a/GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets b/GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets new file mode 100644 index 00000000..16b8c401 --- /dev/null +++ b/GesturesConfictPractice/entry/src/main/ets/pages/TestCode.ets @@ -0,0 +1,62 @@ +import { webview } from '@kit.ArkWeb'; + +@Component +struct Index { + @State message: string = 'Hello World'; + // [Start test_code_build] + build() { + StackA() { + ComponentB() { + ComponentC() + } + + ComponentD() { + ComponentE() + } + } + // [End test_code_build] + } +} + +@Component +struct StackA { + 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 + }) + // [End web_nested_scroll] + } +} +@Component +struct ComponentB { + build() { + + } +} +@Component +struct ComponentC { + build() { + + } +} +@Component +struct ComponentD { + build() { + + } +} +@Component +struct ComponentE { + build() { + + } +} \ No newline at end of file -- Gitee