1e41f4b71Sopenharmony_ci# Gesture Blocking Enhancement 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciGesture blocking enhancement offers components the capability to block gestures. You can handle built-in gestures in parallel with gestures that have a higher priority as needed, and can dynamically control the triggering of gesture events. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## shouldBuiltInRecognizerParallelWith 10e41f4b71Sopenharmony_cishouldBuiltInRecognizerParallelWith(callback: ShouldBuiltInRecognizerParallelWithCallback): T 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**Parameters** 13e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 14e41f4b71Sopenharmony_ci| ---------- | -------------------------- | ------- | ----------------------------- | 15e41f4b71Sopenharmony_ci| callback | [ShouldBuiltInRecognizerParallelWithCallback](#shouldbuiltinrecognizerparallelwithcallback) | Yes | Callback used to set the parallel relationship between the system's built-in gestures and the gestures of other components within the response chain. When the current component undergoes touch collision detection, a custom callback is triggered to establish the gesture parallel relationship.| 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci**Return value** 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci| Type| Description| 20e41f4b71Sopenharmony_ci| -------- | -------- | 21e41f4b71Sopenharmony_ci| T | Current component.| 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci## ShouldBuiltInRecognizerParallelWithCallback 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_citype ShouldBuiltInRecognizerParallelWithCallback = (current: GestureRecognizer, others: Array\<GestureRecognizer\>) => GestureRecognizer 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciRepresents the callback used to set the parallel relationship between the system's built-in gestures and the gestures of other components within the response chain. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**Parameters** 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 36e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 37e41f4b71Sopenharmony_ci| current | [GestureRecognizer](#gesturerecognizer) | Yes | Built-in gesture recognizer of the current component. Currently only a built-in gesture recognizer of the [PAN_GESTURE](ts-gesture-customize-judge.md#gesturejudgeresult11) type is supported.| 38e41f4b71Sopenharmony_ci| others | Array\<[GestureRecognizer](#gesturerecognizer)\> | Yes | Other gesture recognizers of the same category from components with higher priority in the response chain.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Return value** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci| Type | Description | 43e41f4b71Sopenharmony_ci| ------ | --------- | 44e41f4b71Sopenharmony_ci| [GestureRecognizer](#gesturerecognizer) | Gesture recognizer that is bound in parallel with the current recognizer.| 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci## GestureRecognizer 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciDefines a gesture recognizer object. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci### getTag 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_cigetTag(): string 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciObtains the tag of this gesture recognizer. 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Return value** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci| Type | Description | 61e41f4b71Sopenharmony_ci| ------ | --------- | 62e41f4b71Sopenharmony_ci| string | Tag of the current gesture recognizer.| 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci### getType 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_cigetType(): GestureControl.GestureType 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ciObtains the type of this gesture recognizer. 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci**Return value** 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci| Type | Description | 75e41f4b71Sopenharmony_ci| ------ | --------- | 76e41f4b71Sopenharmony_ci| [GestureControl.GestureType](ts-gesture-customize-judge.md#gesturetype11) | Type of the current gesture recognizer.| 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci### isBuiltIn 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciisBuiltIn(): boolean 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ciObtains whether this gesture recognizer is a built-in gesture. 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Return value** 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci| Type | Description | 89e41f4b71Sopenharmony_ci| ------ | --------- | 90e41f4b71Sopenharmony_ci| boolean | Whether this gesture recognizer is a built-in gesture.| 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci### setEnabled 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_cisetEnabled(isEnabled: boolean): void 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciSets the enabled state of this gesture recognizer. 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**Parameters** 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 103e41f4b71Sopenharmony_ci| ------- | ---------------------------------- | ---- | ----- | 104e41f4b71Sopenharmony_ci| isEnabled | boolean | Yes | Enabled state to set.| 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci### isEnabled 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ciisEnabled(): boolean 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ciObtains the enabled state of this gesture recognizer. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**Return value** 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci| Type | Description | 117e41f4b71Sopenharmony_ci| ------ | --------- | 118e41f4b71Sopenharmony_ci| boolean | Enabled state of the gesture recognizer.| 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci### getState 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_cigetState(): GestureRecognizerState 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ciObtains the state of this gesture recognizer. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**Return value** 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci| Type | Description | 131e41f4b71Sopenharmony_ci| ------ | --------- | 132e41f4b71Sopenharmony_ci| [GestureRecognizerState](#gesturerecognizerstate) | State of the gesture recognizer.| 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci### getEventTargetInfo 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_cigetEventTargetInfo(): EventTargetInfo 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ciObtains the information about the component corresponding to this gesture recognizer. 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**Return value** 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| Type | Description | 145e41f4b71Sopenharmony_ci| ------ | --------- | 146e41f4b71Sopenharmony_ci| [EventTargetInfo](#eventtargetinfo) | Information about the component corresponding to the current gesture recognizer.| 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci## GestureRecognizerState 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ciEnumerates the gesture recognizer states. 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci| Name | Value | Description | 155e41f4b71Sopenharmony_ci| ------- | ---- | ---------------------------------- | 156e41f4b71Sopenharmony_ci| READY | 0 | Ready.| 157e41f4b71Sopenharmony_ci| DETECTING | 1 | Detecting.| 158e41f4b71Sopenharmony_ci| PENDING | 2 | Pending.| 159e41f4b71Sopenharmony_ci| BLOCKED | 3 | Blocked.| 160e41f4b71Sopenharmony_ci| SUCCESSFUL | 4 | Successful.| 161e41f4b71Sopenharmony_ci| FAILED | 5 | Failed.| 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci## EventTargetInfo 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ciProvides the information about the component corresponding to the gesture recognizer. 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci### getId 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_cigetId(): string 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ciObtains the ID of this component. 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Return value** 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci| Type | Description | 178e41f4b71Sopenharmony_ci| ------ | --------- | 179e41f4b71Sopenharmony_ci| string | [ID](./ts-universal-attributes-component-id.md#id) of the current component.| 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci## ScrollableTargetInfo 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ciProvides the information about the scroll container component corresponding to the gesture recognizer. It inherits from [EventTargetInfo](#eventtargetinfo). 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci### isBegin 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ciisBegin(): boolean 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ciChecks whether this scroll container is scrolled to the top. If the container is a **Swiper** component and is in loop mode, **false** is returned. 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Return value** 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci| Type | Description | 196e41f4b71Sopenharmony_ci| ------ | --------- | 197e41f4b71Sopenharmony_ci| boolean | Whether the current scroll container is scrolled to the top.| 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci### isEnd 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ciisEnd(): boolean 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ciChecks whether this scroll container is scrolled to the bottom. If the container is a **Swiper** component and is in loop mode, **false** is returned. 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**Return value** 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci| Type | Description | 210e41f4b71Sopenharmony_ci| ------ | --------- | 211e41f4b71Sopenharmony_ci| boolean | Whether the scroll container is scrolled to the bottom.| 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci## PanRecognizer 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ciDefines a pan gesture recognizer object. It inherits from [GestureRecognizer](#gesturerecognizer). 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci### getPanGestureOptions 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_cigetPanGestureOptions(): PanGestureOptions 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ciObtains the properties of this pan gesture recognizer. 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**Return value** 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci| Type | Description | 228e41f4b71Sopenharmony_ci| ------ | --------- | 229e41f4b71Sopenharmony_ci| [PanGestureOptions](./ts-basic-gestures-pangesture.md#pangestureoptions) | Properties of the current pan gesture recognizer.| 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci## onGestureRecognizerJudgeBegin 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_cionGestureRecognizerJudgeBegin(callback: GestureRecognizerJudgeBeginCallback): T 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**Parameters** 236e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 237e41f4b71Sopenharmony_ci| ---------- | -------------------------- | ------- | ----------------------------- | 238e41f4b71Sopenharmony_ci| callback | [GestureRecognizerJudgeBeginCallback](#gesturerecognizerjudgebegincallback) | Yes | Custom gesture recognizer judgment callback to bind to the component. When the gesture bound to the current component is accepted, a custom callback is triggered to obtain the result.| 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**Return value** 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci| Type| Description| 243e41f4b71Sopenharmony_ci| -------- | -------- | 244e41f4b71Sopenharmony_ci| T | Current component.| 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci## GestureRecognizerJudgeBeginCallback 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_citype GestureRecognizerJudgeBeginCallback = (event: BaseGestureEvent, current: GestureRecognizer, recognizers: Array\<GestureRecognizer\>) => GestureJudgeResult 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ciRepresents a custom gesture recognizer judgment callback. 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**Parameters** 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 259e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 260e41f4b71Sopenharmony_ci| event | [BaseGestureEvent](./ts-gesture-customize-judge.md#basegestureevent) | Yes | Information about the current basic gesture event.| 261e41f4b71Sopenharmony_ci| current | [GestureRecognizer](#gesturerecognizer) | Yes | Gesture recognizer object that is about to respond.| 262e41f4b71Sopenharmony_ci| others | Array\<[GestureRecognizer](#gesturerecognizer)\> | Yes | Other gesture recognizer objects in the response chain.| 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci**Return value** 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci| Type | Description | 267e41f4b71Sopenharmony_ci| ------ | --------- | 268e41f4b71Sopenharmony_ci| [GestureJudgeResult](ts-gesture-customize-judge.md#gesturejudgeresult11) | Result of whether the gesture judgment is successful.| 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci## Example 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci```ts 273e41f4b71Sopenharmony_ci// xxx.ets 274e41f4b71Sopenharmony_ci@Entry 275e41f4b71Sopenharmony_ci@Component 276e41f4b71Sopenharmony_cistruct FatherControlChild { 277e41f4b71Sopenharmony_ci scroller: Scroller = new Scroller() 278e41f4b71Sopenharmony_ci scroller2: Scroller = new Scroller() 279e41f4b71Sopenharmony_ci private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 280e41f4b71Sopenharmony_ci private childRecognizer: GestureRecognizer = new GestureRecognizer() 281e41f4b71Sopenharmony_ci private currentRecognizer: GestureRecognizer = new GestureRecognizer() 282e41f4b71Sopenharmony_ci private lastOffset: number = 0 283e41f4b71Sopenharmony_ci 284e41f4b71Sopenharmony_ci build() { 285e41f4b71Sopenharmony_ci Stack({ alignContent: Alignment.TopStart }) { 286e41f4b71Sopenharmony_ci Scroll(this.scroller) { // External scroll container. 287e41f4b71Sopenharmony_ci Column() { 288e41f4b71Sopenharmony_ci Text("Scroll Area") 289e41f4b71Sopenharmony_ci .width('90%') 290e41f4b71Sopenharmony_ci .height(150) 291e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 292e41f4b71Sopenharmony_ci .borderRadius(15) 293e41f4b71Sopenharmony_ci .fontSize(16) 294e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 295e41f4b71Sopenharmony_ci .margin({ top: 10 }) 296e41f4b71Sopenharmony_ci Scroll(this.scroller2) { // Internal scroll container. 297e41f4b71Sopenharmony_ci Column() { 298e41f4b71Sopenharmony_ci Text("Scroll Area2") 299e41f4b71Sopenharmony_ci .width('90%') 300e41f4b71Sopenharmony_ci .height(150) 301e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 302e41f4b71Sopenharmony_ci .borderRadius(15) 303e41f4b71Sopenharmony_ci .fontSize(16) 304e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 305e41f4b71Sopenharmony_ci .margin({ top: 10 }) 306e41f4b71Sopenharmony_ci Column() { 307e41f4b71Sopenharmony_ci ForEach(this.arr, (item: number) => { 308e41f4b71Sopenharmony_ci Text(item.toString()) 309e41f4b71Sopenharmony_ci .width('90%') 310e41f4b71Sopenharmony_ci .height(150) 311e41f4b71Sopenharmony_ci .backgroundColor(0xFFFFFF) 312e41f4b71Sopenharmony_ci .borderRadius(15) 313e41f4b71Sopenharmony_ci .fontSize(16) 314e41f4b71Sopenharmony_ci .textAlign(TextAlign.Center) 315e41f4b71Sopenharmony_ci .margin({ top: 10 }) 316e41f4b71Sopenharmony_ci }, (item: string) => item) 317e41f4b71Sopenharmony_ci }.width('100%') 318e41f4b71Sopenharmony_ci } 319e41f4b71Sopenharmony_ci } 320e41f4b71Sopenharmony_ci .id("inner") 321e41f4b71Sopenharmony_ci .width('100%') 322e41f4b71Sopenharmony_ci .height(800) 323e41f4b71Sopenharmony_ci }.width('100%') 324e41f4b71Sopenharmony_ci } 325e41f4b71Sopenharmony_ci .id("outer") 326e41f4b71Sopenharmony_ci .height(600) 327e41f4b71Sopenharmony_ci .scrollable(ScrollDirection.Vertical) // The scrollbar scrolls in the vertical direction. 328e41f4b71Sopenharmony_ci .scrollBar(BarState.On) // The scrollbar is always displayed. 329e41f4b71Sopenharmony_ci .scrollBarColor(Color.Gray) // The scrollbar color is gray. 330e41f4b71Sopenharmony_ci .scrollBarWidth(10) // The scrollbar width is 10. 331e41f4b71Sopenharmony_ci .edgeEffect(EdgeEffect.None) 332e41f4b71Sopenharmony_ci .shouldBuiltInRecognizerParallelWith((current: GestureRecognizer, others: Array<GestureRecognizer>) => { 333e41f4b71Sopenharmony_ci for (let i = 0; i < others.length; i++) { 334e41f4b71Sopenharmony_ci let target = others[i].getEventTargetInfo(); 335e41f4b71Sopenharmony_ci if (target) { 336e41f4b71Sopenharmony_ci if (target.getId() == "inner" && others[i].isBuiltIn() && others[i].getType() == GestureControl.GestureType.PAN_GESTURE) { // Find the recognizer that will form the parallel gesture recognition. 337e41f4b71Sopenharmony_ci this.currentRecognizer = current; // Save the recognizer of the current component. 338e41f4b71Sopenharmony_ci this.childRecognizer = others[i]; // Save the recognizer that will form the parallel gesture recognition. 339e41f4b71Sopenharmony_ci return others[i]; // Return the recognizer that will form the parallel gesture recognition. 340e41f4b71Sopenharmony_ci } 341e41f4b71Sopenharmony_ci } 342e41f4b71Sopenharmony_ci } 343e41f4b71Sopenharmony_ci return undefined; 344e41f4b71Sopenharmony_ci }) 345e41f4b71Sopenharmony_ci .onGestureRecognizerJudgeBegin((event: BaseGestureEvent, current: GestureRecognizer, others: Array<GestureRecognizer>) => { // When the recognizer is about to succeed, set the enabled state of the recognizer based on the current component state. 346e41f4b71Sopenharmony_ci if (current) { 347e41f4b71Sopenharmony_ci let target = current.getEventTargetInfo(); 348e41f4b71Sopenharmony_ci if (target) { 349e41f4b71Sopenharmony_ci if (target.getId() == "outer" && current.isBuiltIn() && current.getType() == GestureControl.GestureType.PAN_GESTURE) { 350e41f4b71Sopenharmony_ci if (others) { 351e41f4b71Sopenharmony_ci for (let i = 0; i < others.length; i++) { 352e41f4b71Sopenharmony_ci let target = others[i].getEventTargetInfo() as ScrollableTargetInfo; 353e41f4b71Sopenharmony_ci if (target instanceof ScrollableTargetInfo && target.getId() == "inner") { // Find the corresponding parallel recognizer in the response chain. 354e41f4b71Sopenharmony_ci let panEvent = event as PanGestureEvent; 355e41f4b71Sopenharmony_ci if (target.isEnd()) {// Dynamically control the enabled state of the recognizer based on the current component state and movement direction. 356e41f4b71Sopenharmony_ci if (panEvent && panEvent.offsetY < 0) { 357e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(false) 358e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(true) 359e41f4b71Sopenharmony_ci } else { 360e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 361e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 362e41f4b71Sopenharmony_ci } 363e41f4b71Sopenharmony_ci } else if (target.isBegin()) { 364e41f4b71Sopenharmony_ci if (panEvent.offsetY > 0) { 365e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(false) 366e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(true) 367e41f4b71Sopenharmony_ci } else { 368e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 369e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 370e41f4b71Sopenharmony_ci } 371e41f4b71Sopenharmony_ci } else { 372e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 373e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 374e41f4b71Sopenharmony_ci } 375e41f4b71Sopenharmony_ci } 376e41f4b71Sopenharmony_ci } 377e41f4b71Sopenharmony_ci } 378e41f4b71Sopenharmony_ci } 379e41f4b71Sopenharmony_ci } 380e41f4b71Sopenharmony_ci } 381e41f4b71Sopenharmony_ci return GestureJudgeResult.CONTINUE; 382e41f4b71Sopenharmony_ci }) 383e41f4b71Sopenharmony_ci .parallelGesture( // Bind a pan gesture as a dynamic controller. 384e41f4b71Sopenharmony_ci PanGesture() 385e41f4b71Sopenharmony_ci .onActionUpdate((event: GestureEvent)=>{ 386e41f4b71Sopenharmony_ci if (this.childRecognizer.getState() != GestureRecognizerState.SUCCESSFUL || this.currentRecognizer.getState() != GestureRecognizerState.SUCCESSFUL) { // If the recognizer's state is not SUCCESSFUL, do not perform control. 387e41f4b71Sopenharmony_ci return; 388e41f4b71Sopenharmony_ci } 389e41f4b71Sopenharmony_ci let target = this.childRecognizer.getEventTargetInfo() as ScrollableTargetInfo; 390e41f4b71Sopenharmony_ci let currentTarget = this.currentRecognizer.getEventTargetInfo() as ScrollableTargetInfo; 391e41f4b71Sopenharmony_ci if (target instanceof ScrollableTargetInfo && currentTarget instanceof ScrollableTargetInfo) { 392e41f4b71Sopenharmony_ci if (target.isEnd()) { // Based on the component state during the movement, control the enabled state of the recognizer. 393e41f4b71Sopenharmony_ci if ((event.offsetY - this.lastOffset) < 0) { 394e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(false) 395e41f4b71Sopenharmony_ci if (currentTarget.isEnd()) { 396e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 397e41f4b71Sopenharmony_ci } else { 398e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(true) 399e41f4b71Sopenharmony_ci } 400e41f4b71Sopenharmony_ci } else { 401e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 402e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 403e41f4b71Sopenharmony_ci } 404e41f4b71Sopenharmony_ci } else if (target.isBegin()) { 405e41f4b71Sopenharmony_ci if ((event.offsetY - this.lastOffset) > 0) { 406e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(false) 407e41f4b71Sopenharmony_ci if (currentTarget.isBegin()) { 408e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 409e41f4b71Sopenharmony_ci } else { 410e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(true) 411e41f4b71Sopenharmony_ci } 412e41f4b71Sopenharmony_ci } else { 413e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 414e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 415e41f4b71Sopenharmony_ci } 416e41f4b71Sopenharmony_ci } else { 417e41f4b71Sopenharmony_ci this.childRecognizer.setEnabled(true) 418e41f4b71Sopenharmony_ci this.currentRecognizer.setEnabled(false) 419e41f4b71Sopenharmony_ci } 420e41f4b71Sopenharmony_ci } 421e41f4b71Sopenharmony_ci this.lastOffset = event.offsetY 422e41f4b71Sopenharmony_ci }) 423e41f4b71Sopenharmony_ci ) 424e41f4b71Sopenharmony_ci }.width('100%').height('100%').backgroundColor(0xDCDCDC) 425e41f4b71Sopenharmony_ci } 426e41f4b71Sopenharmony_ci} 427e41f4b71Sopenharmony_ci``` 428