From bb037ea8e0d2f51282e05783b858e795eceb2ab2 Mon Sep 17 00:00:00 2001 From: zhouchaobo Date: Tue, 2 Apr 2024 11:24:08 +0800 Subject: [PATCH] Event & Gesture modifier patch2 Signed-off-by: zhouchaobo Change-Id: Ie24816974450de04388dc2b044020297ec4fe9eb --- .../ark_component/src/ArkButton.ts | 3 - .../ark_component/src/ArkComponent.ts | 372 ++++++++++- .../ark_component/src/ArkImage.ts | 3 - .../ark_component/src/ArkLoadingProgress.ts | 3 - .../ark_component/src/ArkMarquee.ts | 3 - .../ark_component/src/ArkRadio.ts | 3 - .../ark_component/src/ArkRating.ts | 3 - .../ark_component/src/ArkRefresh.ts | 3 - .../ark_component/src/ArkScroll.ts | 3 - .../ark_component/src/ArkSelect.ts | 3 - .../ark_component/src/ArkSlider.ts | 3 - .../ark_component/src/ArkStack.ts | 3 - .../ark_component/src/ArkText.ts | 3 - .../ark_component/src/ArkTextInput.ts | 3 - .../ark_component/src/ArkTextPicker.ts | 3 - .../ark_component/src/ArkTimePicker.ts | 3 - .../ark_component/src/ArkToggle.ts | 3 - .../ark_component/tsconfig.json | 1 + .../ark_modifier/tsconfig.json | 1 + .../engine/arkComponent.js | 609 ++++++++++++++++-- .../engine/jsEnumStyle.js | 3 + 21 files changed, 913 insertions(+), 121 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts index 6efb00aa986..a7a8aa5b67e 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkButton.ts @@ -37,9 +37,6 @@ class ArkButtonComponent extends ArkComponent implements ButtonAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } backgroundColor(value: ResourceColor): this { modifierWithKey(this._modifiersWithKeys, ButtonBackgroundColorModifier.identity, ButtonBackgroundColorModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts index 8c8ea352295..82ad481be89 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkComponent.ts @@ -147,7 +147,7 @@ class Modifier { +class ModifierWithKey { stageValue?: T; value?: T; constructor(value: T) { @@ -1493,6 +1493,183 @@ class ForegroundColorModifier extends ModifierWithKey void; +class OnClickModifier extends ModifierWithKey { + constructor(value: ClickCallback) { + super(value); + } + static identity: Symbol = Symbol('onClick'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnClick(node); + } else { + getUINativeModule().common.setOnClick(node, this.value); + } + } +} + +declare type TouchCallback = (event: TouchEvent) => void; +class OnTouchModifier extends ModifierWithKey { + constructor(value: TouchCallback) { + super(value); + } + static identity: Symbol = Symbol('onTouch'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnTouch(node); + } else { + getUINativeModule().common.setOnTouch(node, this.value); + } + } +} + +declare type VoidCallback = () => void; +class OnAppearModifier extends ModifierWithKey { + constructor(value: VoidCallback) { + super(value); + } + static identity: Symbol = Symbol('onAppear'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnAppear(node); + } else { + getUINativeModule().common.setOnAppear(node, this.value); + } + } +} + +class OnDisappearModifier extends ModifierWithKey { + constructor(value: VoidCallback) { + super(value); + } + static identity: Symbol = Symbol('onDisappear'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnDisappear(node); + } else { + getUINativeModule().common.setOnDisappear(node, this.value); + } + } +} + +declare type KeyEventCallback = (event: KeyEvent) => void; +class OnKeyEventModifier extends ModifierWithKey { + constructor(value: KeyEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onKeyEvent'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnKeyEvent(node); + } else { + getUINativeModule().common.setOnKeyEvent(node, this.value); + } + } +} + +class OnFocusModifier extends ModifierWithKey { + constructor(value: VoidCallback) { + super(value); + } + static identity: Symbol = Symbol('onFocus'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnFocus(node); + } else { + getUINativeModule().common.setOnFocus(node, this.value); + } + } +} + +class OnBlurModifier extends ModifierWithKey { + constructor(value: VoidCallback) { + super(value); + } + static identity: Symbol = Symbol('onBlur'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnBlur(node); + } else { + getUINativeModule().common.setOnBlur(node, this.value); + } + } +} + +declare type HoverEventCallback = (isHover: boolean, event: HoverEvent) => void +class OnHoverModifier extends ModifierWithKey { + constructor(value: HoverEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onHover'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnHover(node); + } else { + getUINativeModule().common.setOnHover(node, this.value); + } + } +} + +declare type MouseEventCallback = (event: MouseEvent) => void +class OnMouseModifier extends ModifierWithKey { + constructor(value: MouseEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onMouse'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnMouse(node); + } else { + getUINativeModule().common.setOnMouse(node, this.value); + } + } +} + +declare type SizeChangeEventCallback = (oldValue: SizeOptions, newValue: SizeOptions) => void +class OnSizeChangeModifier extends ModifierWithKey { + constructor(value: SizeChangeEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onSizeChange'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnSizeChange(node); + } else { + getUINativeModule().common.setOnSizeChange(node, this.value); + } + } +} + +declare type AreaChangeEventCallback = (oldValue: Area, newValue: Area) => void +class OnAreaChangeModifier extends ModifierWithKey { + constructor(value: AreaChangeEventCallback) { + super(value); + } + static identity: Symbol = Symbol('onAreaChange'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnAreaChange(node); + } else { + getUINativeModule().common.setOnAreaChange(node, this.value); + } + } +} + +declare type GestureJudgeBeginCallback = (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult +class OnGestureJudgeBeginModifier extends ModifierWithKey { + constructor(value: GestureJudgeBeginCallback) { + super(value); + } + static identity: Symbol = Symbol('onGestureJudgeBegin'); + applyPeer(node: KNode, reset: boolean): void { + if (reset) { + getUINativeModule().common.resetOnGestureJudgeBegin(node); + } else { + getUINativeModule().common.setOnGestureJudgeBegin(node, this.value); + } + } +} + class MotionPathModifier extends ModifierWithKey { constructor(value: MotionPathOptions) { super(value); @@ -2434,6 +2611,7 @@ class ArkComponent implements CommonMethod { _weakPtr: JsPointerClass; _classType: ModifierType | undefined; _nativePtrChanged: boolean; + _gestureEvent: UIGestureEvent; constructor(nativePtr: KNode, classType?: ModifierType) { this._modifiers = new Map(); @@ -2447,6 +2625,14 @@ class ArkComponent implements CommonMethod { this._nativePtrChanged = false; } + getOrCreateGestureEvent() { + if (this._gestureEvent !== null) { + this._gestureEvent = new UIGestureEvent(); + this._gestureEvent.setNodePtr(this.nativePtr); + } + return this._gestureEvent; + } + cleanStageValue(): void { if (!this._modifiersWithKeys){ return; @@ -2485,7 +2671,12 @@ class ArkComponent implements CommonMethod { }); } onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnGestureJudgeBeginModifier.identity, OnGestureJudgeBeginModifier, callback); + return this; + } + onSizeChange(callback: (oldValue: SizeOptions, newValue: SizeOptions) => void): this { + modifierWithKey(this._modifiersWithKeys, OnSizeChangeModifier.identity, OnSizeChangeModifier, callback); + return this; } outline(value: OutlineOptions): this { modifierWithKey(this._modifiersWithKeys, OutlineModifier.identity, OutlineModifier, value); @@ -2838,11 +3029,13 @@ class ArkComponent implements CommonMethod { } onClick(event: (event?: ClickEvent) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnClickModifier.identity, OnClickModifier, event); + return this; } onHover(event: (isHover?: boolean, event?: HoverEvent) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnHoverModifier.identity, OnHoverModifier, event); + return this; } hoverEffect(value: HoverEffect): this { @@ -2851,15 +3044,18 @@ class ArkComponent implements CommonMethod { } onMouse(event: (event?: MouseEvent) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnMouseModifier.identity, OnMouseModifier, event); + return this; } onTouch(event: (event?: TouchEvent) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnTouchModifier.identity, OnTouchModifier, event); + return this; } onKeyEvent(event: (event?: KeyEvent) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnKeyEventModifier.identity, OnKeyEventModifier, event); + return this; } focusable(value: boolean): this { @@ -2872,11 +3068,13 @@ class ArkComponent implements CommonMethod { } onFocus(event: () => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnFocusModifier.identity, OnFocusModifier, event); + return this; } onBlur(event: () => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnBlurModifier.identity, OnBlurModifier, event); + return this; } tabIndex(index: number): this { @@ -3083,15 +3281,18 @@ class ArkComponent implements CommonMethod { } onAppear(event: () => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnAppearModifier.identity, OnAppearModifier, event); + return this; } onDisAppear(event: () => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnDisappearModifier.identity, OnDisappearModifier, event); + return this; } onAreaChange(event: (oldValue: Area, newValue: Area) => void): this { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnAreaChangeModifier.identity, OnAreaChangeModifier, event); + return this; } visibility(value: Visibility): this { @@ -3545,7 +3746,6 @@ const isInteger = (val: any) => Number.isInteger(val); const isNonEmptyMap = (val: any) => val instanceof Map && val.size > 0; const isTruthyString = (val: any) => typeof val === 'string' && val.trim() !== ''; - class UICommonEvent { private _nodePtr: Object | null; private _instanceId: number; @@ -3616,3 +3816,149 @@ function attributeModifierFunc(modifier: AttributeModifier, component.applyModifierPatch(); } } + +class UIGestureEvent { + private _nodePtr: Object | null; + setNodePtr(nodePtr: Object | null): void { + this._nodePtr = nodePtr; + } + addGesture(gesture: GestureHandler, priority?: GesturePriority, mask?: GestureMask): void { + switch (gesture.gestureType) { + case CommonGestureType.TAP_GESTURE: { + let tapGesture: TapGestureHandler = gesture as TapGestureHandler; + getUINativeModule().common.addTapGesture(this._nodePtr, priority, mask, tapGesture.gestureTag, + tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback); + break; + } + case CommonGestureType.LONG_PRESS_GESTURE: { + let longPressGesture: LongPressGestureHandler = gesture as LongPressGestureHandler; + getUINativeModule().common.addLongPressGesture(this._nodePtr, priority, mask, longPressGesture.gestureTag, + longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration, + longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback); + break; + } + case CommonGestureType.PAN_GESTURE: { + let panGesture: PanGestureHandler = gesture as PanGestureHandler; + getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag, + panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback, + panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback); + break; + } + case CommonGestureType.SWIPE_GESTURE: { + let swipeGesture: SwipeGestureHandler = gesture as SwipeGestureHandler; + getUINativeModule().common.addSwipeGesture(this._nodePtr, priority, mask, swipeGesture.gestureTag, + swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback); + break; + } + case CommonGestureType.PINCH_GESTURE: { + let pinchGesture: PinchGestureHandler = gesture as PinchGestureHandler; + getUINativeModule().common.addPinchGesture(this._nodePtr, priority, mask, pinchGesture.gestureTag, + pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback, + pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback); + break; + } + case CommonGestureType.ROTATION_GESTURE: { + let rotationGesture: RotationGestureHandler = gesture as RotationGestureHandler; + getUINativeModule().common.addRotationGesture(this._nodePtr, priority, mask, rotationGesture.gestureTag, + rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback, + rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback, + rotationGesture.onActionCancelCallback); + break; + } + case CommonGestureType.GESTURE_GROUP: { + let gestureGroup: GestureGroupHandler = gesture as GestureGroupHandler; + let groupPtr = getUINativeModule().common.addGestureGroup( + gestureGroup.gestureTag, gestureGroup.onCancelCallback, gestureGroup.mode); + gestureGroup.gestures.forEach((item) => { + addGestureToGroup(item, groupPtr); + }); + getUINativeModule().common.attachGestureGroup(this._nodePtr, priority, mask, groupPtr); + break; + } + default: + break; + } + } + addParallelGesture(gesture: GestureHandler, mask?: GestureMask): void { + this.addGesture(gesture, GesturePriority.PARALLEL, mask); + } + removeGestureByTag(tag: string): void { + getUINativeModule().common.removeGestureByTag(this._nodePtr, tag); + } + clearGestures(): void { + getUINativeModule().common.clearGestures(this._nodePtr); + } +} + +function addGestureToGroup(gesture: any, gestureGroupPtr: any) { + switch (gesture.gestureType) { + case CommonGestureType.TAP_GESTURE: { + let tapGesture: TapGestureHandler = gesture as TapGestureHandler; + getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag, + tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback, gestureGroupPtr); + break; + } + case CommonGestureType.LONG_PRESS_GESTURE: { + let longPressGesture: LongPressGestureHandler = gesture as LongPressGestureHandler; + getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag, + longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration, + longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.PAN_GESTURE: { + let panGesture: PanGestureHandler = gesture as PanGestureHandler; + getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag, + panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback, + panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.SWIPE_GESTURE: { + let swipeGesture: SwipeGestureHandler = gesture as SwipeGestureHandler; + getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag, + swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback, gestureGroupPtr); + break; + } + case CommonGestureType.PINCH_GESTURE: { + let pinchGesture: PinchGestureHandler = gesture as PinchGestureHandler; + getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag, + pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback, + pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.ROTATION_GESTURE: { + let rotationGesture: RotationGestureHandler = gesture as RotationGestureHandler; + getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag, + rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback, + rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback, + rotationGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.GESTURE_GROUP: { + let gestureGroup: GestureGroupHandler = gesture as GestureGroupHandler; + let groupPtr = getUINativeModule().common.addGestureGroupToGroup(gestureGroup.gestureTag, + gestureGroup.onCancelCallback, gestureGroup.mode, gestureGroupPtr); + gestureGroup.gestures.forEach((item) => { + addGestureToGroup(item, groupPtr); + }); + break; + } + default: + break; + } +} + +function applyGesture(modifier: GestureModifier, component: ArkComponent): void { + + if (modifier.applyGesture !== undefined) { + let gestureEvent: UIGestureEvent = component.getOrCreateGestureEvent(); + gestureEvent.clearGestures(); + modifier.applyGesture(gestureEvent); + } +} + +function __gestureModifier__(modifier) { + const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); + let nativeNode = getUINativeModule().getFrameNodeById(elmtId); + let component = new ArkComponent(nativeNode); + applyGesture(modifier, component); +} diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts index a139657e20b..1995fdee465 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkImage.ts @@ -473,9 +473,6 @@ class ArkImageComponent extends ArkComponent implements ImageAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback): this { - throw new Error('Method not implemented.'); - } draggable(value: boolean): this { modifierWithKey(this._modifiersWithKeys, ImageDraggableModifier.identity, ImageDraggableModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkLoadingProgress.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkLoadingProgress.ts index 2dcd13f04df..8a83030fb57 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkLoadingProgress.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkLoadingProgress.ts @@ -18,9 +18,6 @@ class ArkLoadingProgressComponent extends ArkComponent implements LoadingProgres constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } color(value: ResourceColor): this { modifierWithKey(this._modifiersWithKeys, LoadingProgressColorModifier.identity, LoadingProgressColorModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkMarquee.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkMarquee.ts index c3fe965c110..c010b59bcc2 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkMarquee.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkMarquee.ts @@ -19,9 +19,6 @@ class ArkMarqueeComponent extends ArkComponent implements MarqueeAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } fontSize(value: Length): this { modifierWithKey(this._modifiersWithKeys, MarqueeFontSizeModifier.identity, MarqueeFontSizeModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRadio.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRadio.ts index 675ceb5c405..3a8e30c34c1 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRadio.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRadio.ts @@ -19,9 +19,6 @@ class ArkRadioComponent extends ArkComponent implements RadioAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } checked(value: boolean): this { modifierWithKey(this._modifiersWithKeys, RadioCheckedModifier.identity, RadioCheckedModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRating.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRating.ts index 40863bc1f98..9daf9a8d4be 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRating.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRating.ts @@ -67,9 +67,6 @@ class ArkRatingComponent extends ArkComponent implements RatingAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } stars(value: number): this { modifierWithKey(this._modifiersWithKeys, RatingStarsModifier.identity, RatingStarsModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRefresh.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRefresh.ts index e25dce9ca85..0c714cf2d3b 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkRefresh.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkRefresh.ts @@ -19,9 +19,6 @@ class ArkRefreshComponent extends ArkComponent implements RefreshAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } onStateChange(callback: (state: RefreshStatus) => void): this { throw new Error('Method not implemented.'); } diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkScroll.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkScroll.ts index d194080db03..d84e97811ac 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkScroll.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkScroll.ts @@ -219,9 +219,6 @@ class ArkScrollComponent extends ArkComponent implements ScrollAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } scrollable(value: ScrollDirection): this { modifierWithKey(this._modifiersWithKeys, ScrollScrollableModifier.identity, ScrollScrollableModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkSelect.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkSelect.ts index 0fdb4ab8a1a..a54b7249048 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkSelect.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkSelect.ts @@ -18,9 +18,6 @@ class ArkSelectComponent extends ArkComponent implements SelectAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } optionWidth(value: Dimension | OptionWidthMode): this { modifierWithKey( this._modifiersWithKeys, SelectOptionWidthModifier.identity, SelectOptionWidthModifier, value); diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkSlider.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkSlider.ts index 1953822eb76..c912bf443b7 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkSlider.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkSlider.ts @@ -18,9 +18,6 @@ class ArkSliderComponent extends ArkComponent implements SliderAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } blockColor(value: ResourceColor): this { modifierWithKey(this._modifiersWithKeys, BlockColorModifier.identity, BlockColorModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkStack.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkStack.ts index b5fdd4c682e..5fc5ec79c20 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkStack.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkStack.ts @@ -18,9 +18,6 @@ class ArkStackComponent extends ArkComponent implements StackAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } alignContent(value: Alignment): StackAttribute { modifierWithKey(this._modifiersWithKeys, StackAlignContentModifier.identity, StackAlignContentModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts index aae0f2545db..252f0b6e74f 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkText.ts @@ -551,9 +551,6 @@ class ArkTextComponent extends ArkComponent implements TextAttribute { dataDetectorConfig(config: any): this { throw new Error('Method not implemented.'); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } font(value: Font): TextAttribute { modifierWithKey(this._modifiersWithKeys, TextFontModifier.identity, TextFontModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextInput.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextInput.ts index 9fcf26577d5..5a3291d14d9 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextInput.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextInput.ts @@ -629,9 +629,6 @@ class ArkTextInputComponent extends ArkComponent implements CommonMethod GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } selectAll(value: boolean): TextInputAttribute { throw new Error('Method not implemented.'); } diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextPicker.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextPicker.ts index 33092ce9771..7d02118d48a 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextPicker.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTextPicker.ts @@ -18,9 +18,6 @@ class ArkTextPickerComponent extends ArkComponent implements TextPickerAttribute constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } defaultPickerItemHeight(value: string | number): this { modifierWithKey( this._modifiersWithKeys, TextpickerDefaultPickerItemHeightModifier.identity, TextpickerDefaultPickerItemHeightModifier, value); diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTimePicker.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTimePicker.ts index a9ab8e68e47..7027bf46cd3 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkTimePicker.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkTimePicker.ts @@ -18,9 +18,6 @@ class ArkTimePickerComponent extends ArkComponent implements TimePickerAttribute constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } loop(value: boolean): this { throw new Error('Method not implemented.'); } diff --git a/frameworks/bridge/declarative_frontend/ark_component/src/ArkToggle.ts b/frameworks/bridge/declarative_frontend/ark_component/src/ArkToggle.ts index f5283ed8777..8409f32e8cc 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/src/ArkToggle.ts +++ b/frameworks/bridge/declarative_frontend/ark_component/src/ArkToggle.ts @@ -18,9 +18,6 @@ class ArkToggleComponent extends ArkComponent implements ToggleAttribute { constructor(nativePtr: KNode, classType?: ModifierType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback: (gestureInfo: GestureInfo, event: BaseGestureEvent) => GestureJudgeResult): this { - throw new Error('Method not implemented.'); - } onChange(callback: (isOn: boolean) => void): this { throw new Error('Method not implemented.'); } diff --git a/frameworks/bridge/declarative_frontend/ark_component/tsconfig.json b/frameworks/bridge/declarative_frontend/ark_component/tsconfig.json index 618bcdf4bb9..a414901f3b5 100644 --- a/frameworks/bridge/declarative_frontend/ark_component/tsconfig.json +++ b/frameworks/bridge/declarative_frontend/ark_component/tsconfig.json @@ -50,6 +50,7 @@ "src/ArkDatePicker.ts", "src/ArkFormComponent.ts", "src/ArkGauge.ts", + "src/ArkGesture.ts", "src/ArkMarquee.ts", "src/ArkMenu.ts", "src/ArkMenuItem.ts", diff --git a/frameworks/bridge/declarative_frontend/ark_modifier/tsconfig.json b/frameworks/bridge/declarative_frontend/ark_modifier/tsconfig.json index 1a32eb3ec1c..4d1546144e5 100644 --- a/frameworks/bridge/declarative_frontend/ark_modifier/tsconfig.json +++ b/frameworks/bridge/declarative_frontend/ark_modifier/tsconfig.json @@ -21,6 +21,7 @@ "src/flex_modifier.ts", "src/form_component_modifier.ts", "src/gauge_modifier.ts", + "src/gesture_modifier.ts", "src/grid_modifier.ts", "src/grid_col_modifier.ts", "src/griditem_modifier.ts", diff --git a/frameworks/bridge/declarative_frontend/engine/arkComponent.js b/frameworks/bridge/declarative_frontend/engine/arkComponent.js index e1a7edfc7f1..f0d613f710e 100644 --- a/frameworks/bridge/declarative_frontend/engine/arkComponent.js +++ b/frameworks/bridge/declarative_frontend/engine/arkComponent.js @@ -1429,6 +1429,163 @@ class ForegroundColorModifier extends ModifierWithKey { } } ForegroundColorModifier.identity = Symbol('foregroundColor'); +class ClickModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnClick(node); + } else { + getUINativeModule().common.setOnClick(node, this.value); + } + } +} +ClickModifier.identity = Symbol('onClick'); +class OnTouchModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnTouch(node); + } else { + getUINativeModule().common.setOnTouch(node, this.value); + } + } +} +OnTouchModifier.identity = Symbol('onTouch'); +class OnAppearModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnAppear(node); + } else { + getUINativeModule().common.setOnAppear(node, this.value); + } + } +} +OnAppearModifier.identity = Symbol('onAppear'); +class OnDisappearModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnDisappear(node); + } else { + getUINativeModule().common.setOnDisappear(node, this.value); + } + } +} +OnDisappearModifier.identity = Symbol('onDisappear'); +class OnKeyEventModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnKeyEvent(node); + } else { + getUINativeModule().common.setOnKeyEvent(node, this.value); + } + } +} +OnKeyEventModifier.identity = Symbol('onKeyEvent'); +class OnFocusModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnFocus(node); + } else { + getUINativeModule().common.setOnFocus(node, this.value); + } + } +} +OnFocusModifier.identity = Symbol('onFocus'); +class OnBlurModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnBlur(node); + } else { + getUINativeModule().common.setOnBlur(node, this.value); + } + } +} +OnBlurModifier.identity = Symbol('onBlur'); + +class OnHoverModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnHover(node); + } else { + getUINativeModule().common.setOnHover(node, this.value); + } + } +} +OnHoverModifier.identity = Symbol('onHover'); +class OnMouseModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnMouse(node); + } else { + getUINativeModule().common.setOnMouse(node, this.value); + } + } +} +OnMouseModifier.identity = Symbol('onMouse'); +class OnSizeChangeModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnSizeChange(node); + } else { + getUINativeModule().common.setOnSizeChange(node, this.value); + } + } +} +OnSizeChangeModifier.identity = Symbol('onSizeChange'); +class OnAreaChangeModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnAreaChange(node); + } else { + getUINativeModule().common.setOnAreaChange(node, this.value); + } + } +} +OnSizeChangeModifier.identity = Symbol('onAreaChange'); +class OnGestureJudgeBeginModifier extends ModifierWithKey { + constructor(value) { + super(value); + } + applyPeer(node, reset) { + if (reset) { + getUINativeModule().common.resetOnGestureJudgeBegin(node); + } else { + getUINativeModule().common.setOnGestureJudgeBegin(node, this.value); + } + } +} +OnGestureJudgeBeginModifier.identity = Symbol('onGestureJudgeBegin'); class MotionPathModifier extends ModifierWithKey { constructor(value) { super(value); @@ -2393,6 +2550,13 @@ class ArkComponent { } this._nativePtrChanged = false; } + getOrCreateGestureEvent() { + if (this._gestureEvent !== null) { + this._gestureEvent = new UIGestureEvent(); + this._gestureEvent.setNodePtr(this.nativePtr); + } + return this._gestureEvent; + } cleanStageValue(){ if (!this._modifiersWithKeys){ return; @@ -2429,7 +2593,12 @@ class ArkComponent { }); } onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnGestureJudgeBeginModifier.identity, OnGestureJudgeBeginModifier, callback); + return this; + } + onSizeChange(callback) { + modifierWithKey(this._modifiersWithKeys, OnSizeChangeModifier.identity, OnSizeChangeModifier, callback); + return this; } outline(value) { modifierWithKey(this._modifiersWithKeys, OutlineModifier.identity, OutlineModifier, value); @@ -2756,23 +2925,28 @@ class ArkComponent { return this; } onClick(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, ClickModifier.identity, ClickModifier, event); + return this; } onHover(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnHoverModifier.identity, OnHoverModifier, event); + return this; } hoverEffect(value) { modifierWithKey(this._modifiersWithKeys, HoverEffectModifier.identity, HoverEffectModifier, value); return this; } onMouse(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnMouseModifier.identity, OnMouseModifier, event); + return this; } onTouch(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnTouchModifier.identity, OnTouchModifier, event); + return this; } onKeyEvent(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnKeyEventModifier.identity, OnKeyEventModifier, event); + return this; } focusable(value) { if (typeof value === 'boolean') { @@ -2784,10 +2958,12 @@ class ArkComponent { return this; } onFocus(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnFocusModifier.identity, OnFocusModifier, event); + return this; } onBlur(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnBlurModifier.identity, OnBlurModifier, event); + return this; } tabIndex(index) { if (typeof index !== 'number') { @@ -2977,13 +3153,16 @@ class ArkComponent { return this; } onAppear(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnAppearModifier.identity, OnAppearModifier, event); + return this; } onDisAppear(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnDisappearModifier.identity, OnDisappearModifier, event); + return this; } onAreaChange(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, OnAreaChangeModifier.identity, OnAreaChangeModifier, event); + return this; } visibility(value) { modifierWithKey(this._modifiersWithKeys, VisibilityModifier.identity, VisibilityModifier, value); @@ -3372,6 +3551,219 @@ const isInteger = (val) => Number.isInteger(val); const isNonEmptyMap = (val) => val instanceof Map && val.size > 0; const isTruthyString = (val) => typeof val === 'string' && val.trim() !== ''; +var CommonGestureType; +(function (CommonGestureType) { + CommonGestureType[CommonGestureType["TAP_GESTURE"] = 0] = "TAP_GESTURE"; + CommonGestureType[CommonGestureType["LONG_PRESS_GESTURE"] = 1] = "LONG_PRESS_GESTURE"; + CommonGestureType[CommonGestureType["PAN_GESTURE"] = 2] = "PAN_GESTURE"; + CommonGestureType[CommonGestureType["SWIPE_GESTURE"] = 3] = "SWIPE_GESTURE"; + CommonGestureType[CommonGestureType["PINCH_GESTURE"] = 4] = "PINCH_GESTURE"; + CommonGestureType[CommonGestureType["ROTATION_GESTURE"] = 5] = "ROTATION_GESTURE"; + CommonGestureType[CommonGestureType["GESTURE_GROUP"] = 6] = "GESTURE_GROUP"; +})(CommonGestureType || (CommonGestureType = {})); + +class GestureHandler { + constructor(gestureType) { + this.gestureType = gestureType; + } +} + +class TapGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.TAP_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.count = options.count; + } + } + onAction(event) { + this.onActionCallback = event; + return this; + } + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class LongPressGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.LONG_PRESS_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.repeat = options.repeat; + this.duration = options.duration; + } + } + + onAction(event) { + this.onActionCallback = event; + return this; + } + + onActionEnd(event) { + this.onActionEndCallback = event; + return this; + } + + onActionCancel(event) { + this.onActionCancelCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class PanGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.PAN_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.direction = options.direction; + this.distance = options.distance; + } + } + + onActionStart(event) { + this.onActionStartCallback = event; + return this; + } + + onActionUpdate(event) { + this.onActionUpdateCallback = event; + return this; + } + + onActionEnd(event) { + this.onActionEndCallback = event; + return this; + } + + onActionCancel(event) { + this.onActionCancelCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class SwipeGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.SWIPE_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.direction = options.direction; + this.speed = options.speed; + } + } + + onAction(event) { + this.onActionCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class PinchGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.PINCH_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.distance = options.distance; + } + } + + onActionStart(event) { + this.onActionStartCallback = event; + return this; + } + + onActionUpdate(event) { + this.onActionUpdateCallback = event; + return this; + } + + onActionEnd(event) { + this.onActionEndCallback = event; + return this; + } + + onActionCancel(event) { + this.onActionCancelCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class RotationGestureHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.ROTATION_GESTURE); + if (options !== undefined) { + this.fingers = options.fingers; + this.angle = options.angle; + } + } + + onActionStart(event) { + this.onActionStartCallback = event; + return this; + } + + onActionUpdate(event) { + this.onActionUpdateCallback = event; + return this; + } + + onActionEnd(event) { + this.onActionEndCallback = event; + return this; + } + + onActionCancel(event) { + this.onActionCancelCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + +class GestureGroupHandler extends GestureHandler { + constructor(options) { + super(CommonGestureType.GESTURE_GROUP); + if (options !== undefined) { + this.mode = options.mode; + this.gestures = options.gestures; + } + } + + onCancel(event) { + this.onCancelCallback = event; + return this; + } + + tag(tag) { + this.gestureTag = tag; + return this; + } +} + class UICommonEvent { setInstanceId(instanceId) { this._instanceId = instanceId; @@ -3438,6 +3830,150 @@ function attributeModifierFunc(modifier, componentBuilder, modifierBuilder) { } } +class UIGestureEvent { + setNodePtr(nodePtr) { + this._nodePtr = nodePtr; + } + addGesture(gesture, priority, mask) { + switch (gesture.gestureType) { + case CommonGestureType.TAP_GESTURE: { + let tapGesture = gesture; + getUINativeModule().common.addTapGesture(this._nodePtr, priority, mask, tapGesture.gestureTag, + tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback); + break; + } + case CommonGestureType.LONG_PRESS_GESTURE: { + let longPressGesture = gesture; + getUINativeModule().common.addLongPressGesture(this._nodePtr, priority, mask, longPressGesture.gestureTag, + longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration, + longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback); + break; + } + case CommonGestureType.PAN_GESTURE: { + let panGesture = gesture; + getUINativeModule().common.addPanGesture(this._nodePtr, priority, mask, panGesture.gestureTag, + panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback, + panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback); + break; + } + case CommonGestureType.SWIPE_GESTURE: { + let swipeGesture = gesture; + getUINativeModule().common.addSwipeGesture(this._nodePtr, priority, mask, swipeGesture.gestureTag, + swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback); + break; + } + case CommonGestureType.PINCH_GESTURE: { + let pinchGesture = gesture; + getUINativeModule().common.addPinchGesture(this._nodePtr, priority, mask, pinchGesture.gestureTag, + pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback, + pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback); + break; + } + case CommonGestureType.ROTATION_GESTURE: { + let rotationGesture = gesture; + getUINativeModule().common.addRotationGesture(this._nodePtr, priority, mask, rotationGesture.gestureTag, + rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback, + rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback, + rotationGesture.onActionCancelCallback); + break; + } + case CommonGestureType.GESTURE_GROUP: { + let gestureGroup = gesture; + let groupPtr = getUINativeModule().common.addGestureGroup( + gestureGroup.gestureTag, gestureGroup.onCancelCallback, gestureGroup.mode); + gestureGroup.gestures.forEach((item) => { + addGestureToGroup(item, groupPtr); + }); + getUINativeModule().common.attachGestureGroup(this._nodePtr, priority, mask, groupPtr); + break; + } + default: + break; + } + } + addParallelGesture(gesture, mask) { + this.addGesture(gesture, GesturePriority.PARALLEL, mask); + } + removeGestureByTag(tag) { + getUINativeModule().common.removeGestureByTag(this._nodePtr, tag); + } + clearGestures() { + getUINativeModule().common.clearGestures(this._nodePtr); + } +} + +function addGestureToGroup(gesture, gestureGroupPtr) { + switch (gesture.gestureType) { + case CommonGestureType.TAP_GESTURE: { + let tapGesture = gesture; + getUINativeModule().common.addTapGestureToGroup(tapGesture.gestureTag, + tapGesture.fingers, tapGesture.count, tapGesture.onActionCallback, gestureGroupPtr); + break; + } + case CommonGestureType.LONG_PRESS_GESTURE: { + let longPressGesture = gesture; + getUINativeModule().common.addLongPressGestureToGroup(longPressGesture.gestureTag, + longPressGesture.fingers, longPressGesture.repeat, longPressGesture.duration, + longPressGesture.onActionCallback, longPressGesture.onActionEndCallback, longPressGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.PAN_GESTURE: { + let panGesture = gesture; + getUINativeModule().common.addPanGestureToGroup(panGesture.gestureTag, + panGesture.fingers, panGesture.direction, panGesture.distance, panGesture.onActionStartCallback, + panGesture.onActionUpdateCallback, panGesture.onActionEndCallback, panGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.SWIPE_GESTURE: { + let swipeGesture = gesture; + getUINativeModule().common.addSwipeGestureToGroup(swipeGesture.gestureTag, + swipeGesture.fingers, swipeGesture.direction, swipeGesture.speed, swipeGesture.onActionCallback, gestureGroupPtr); + break; + } + case CommonGestureType.PINCH_GESTURE: { + let pinchGesture = gesture; + getUINativeModule().common.addPinchGestureToGroup(pinchGesture.gestureTag, + pinchGesture.fingers, pinchGesture.distance, pinchGesture.onActionStartCallback, + pinchGesture.onActionUpdateCallback, pinchGesture.onActionEndCallback, pinchGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.ROTATION_GESTURE: { + let rotationGesture = gesture; + getUINativeModule().common.addRotationGestureToGroup(rotationGesture.gestureTag, + rotationGesture.fingers, rotationGesture.angle, rotationGesture.onActionStartCallback, + rotationGesture.onActionUpdateCallback, rotationGesture.onActionEndCallback, + rotationGesture.onActionCancelCallback, gestureGroupPtr); + break; + } + case CommonGestureType.GESTURE_GROUP: { + let gestureGroup = gesture; + let groupPtr = getUINativeModule().common.addGestureGroupToGroup( + gestureGroup.gestureTag, gestureGroup.onCancelCallback, gestureGroup.mode, gestureGroupPtr); + gestureGroup.gestures.forEach((item) => { + addGestureToGroup(item, groupPtr); + }); + break; + } + default: + break; + } +} + +function applyGesture(modifier, component) { + if (modifier.applyGesture !== undefined) { + let gestureEvent = component.getOrCreateGestureEvent(); + gestureEvent.clearGestures(); + modifier.applyGesture(gestureEvent); + } +} + +function __gestureModifier__(modifier) { + const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); + let nativeNode = getUINativeModule().getFrameNodeById(elmtId); + let component = new ArkComponent(nativeNode); + applyGesture(modifier, component); +} + /// class BlankColorModifier extends ModifierWithKey { constructor(value) { @@ -4831,9 +5367,6 @@ class ArkImageComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } draggable(value) { modifierWithKey(this._modifiersWithKeys, ImageDraggableModifier.identity, ImageDraggableModifier, value); return this; @@ -6621,7 +7154,8 @@ class ArkSpanComponent { throw new Error('Method not implemented.'); } onClick(event) { - throw new Error('Method not implemented.'); + modifierWithKey(this._modifiersWithKeys, ClickModifier.identity, ClickModifier, event); + return this; } onHover(event) { throw new Error('Method not implemented.'); @@ -7236,9 +7770,6 @@ class ArkStackComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } alignContent(value) { modifierWithKey(this._modifiersWithKeys, StackAlignContentModifier.identity, StackAlignContentModifier, value); return this; @@ -7816,9 +8347,6 @@ class ArkTextComponent extends ArkComponent { dataDetectorConfig(config) { throw new Error('Method not implemented.'); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } font(value) { modifierWithKey(this._modifiersWithKeys, TextFontModifier.identity, TextFontModifier, value); return this; @@ -9097,9 +9625,6 @@ class ArkTextInputComponent extends ArkComponent { cancelButton(value) { throw new Error('Method not implemented.'); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } selectAll(value) { throw new Error('Method not implemented.'); } @@ -10333,9 +10858,6 @@ class ArkButtonComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } backgroundColor(value) { modifierWithKey(this._modifiersWithKeys, ButtonBackgroundColorModifier.identity, ButtonBackgroundColorModifier, value); return this; @@ -10790,9 +11312,6 @@ class ArkLoadingProgressComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } color(value) { modifierWithKey(this._modifiersWithKeys, LoadingProgressColorModifier.identity, LoadingProgressColorModifier, value); return this; @@ -10871,9 +11390,6 @@ class ArkRefreshComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } onStateChange(callback) { throw new Error('Method not implemented.'); } @@ -11123,9 +11639,6 @@ class ArkScrollComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } scrollable(value) { modifierWithKey(this._modifiersWithKeys, ScrollScrollableModifier.identity, ScrollScrollableModifier, value); return this; @@ -11237,9 +11750,6 @@ class ArkToggleComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } onChange(callback) { throw new Error('Method not implemented.'); } @@ -11509,9 +12019,6 @@ class ArkSelectComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } optionWidth(value) { modifierWithKey(this._modifiersWithKeys, SelectOptionWidthModifier.identity, SelectOptionWidthModifier, value); return this; @@ -11957,9 +12464,6 @@ class ArkRadioComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } checked(value) { modifierWithKey(this._modifiersWithKeys, RadioCheckedModifier.identity, RadioCheckedModifier, value); return this; @@ -12218,9 +12722,6 @@ class ArkTimePickerComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } loop(value) { throw new Error('Method not implemented.'); } @@ -12401,9 +12902,6 @@ class ArkTextPickerComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } defaultPickerItemHeight(value) { modifierWithKey(this._modifiersWithKeys, TextpickerDefaultPickerItemHeightModifier.identity, TextpickerDefaultPickerItemHeightModifier, value); return this; @@ -12657,9 +13155,6 @@ class ArkSliderComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } blockColor(value) { modifierWithKey(this._modifiersWithKeys, BlockColorModifier.identity, BlockColorModifier, value); return this; @@ -13025,9 +13520,6 @@ class ArkRatingComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } stars(value) { modifierWithKey(this._modifiersWithKeys, RatingStarsModifier.identity, RatingStarsModifier, value); return this; @@ -15636,9 +16128,6 @@ class ArkMarqueeComponent extends ArkComponent { constructor(nativePtr, classType) { super(nativePtr, classType); } - onGestureJudgeBegin(callback) { - throw new Error('Method not implemented.'); - } fontSize(value) { modifierWithKey(this._modifiersWithKeys, MarqueeFontSizeModifier.identity, MarqueeFontSizeModifier, value); return this; diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index 345df23a1ce..da15d9b1dc3 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -511,8 +511,11 @@ var GestureMask; var GesturePriority; (function (GesturePriority) { GesturePriority[GesturePriority["Low"] = 0] = "Low"; + GesturePriority[GesturePriority["NORMAL"] = 0] = "NORMAL"; GesturePriority[GesturePriority["High"] = 1] = "High"; + GesturePriority[GesturePriority["PRIORITY"] = 1] = "PRIORITY"; GesturePriority[GesturePriority["Parallel"] = 2] = "Parallel"; + GesturePriority[GesturePriority["PARALLEL"] = 2] = "PARALLEL"; })(GesturePriority || (GesturePriority = {})); var Visibility; -- Gitee