Skip to content

Commit

Permalink
feat(android): disallowInterceptTouch
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed May 3, 2022
1 parent cf2e1ba commit d71c630
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/gesturehandler/gesturehandler.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,12 @@ export const exclusiveTouchProperty = new CssProperty<Style, boolean>({
defaultValue: false,
valueConverter: booleanConverter,
});

export const disallowInterceptTouchProperty = new CssProperty<Style, boolean>({
name: 'disallowInterceptTouch',
cssName: 'disallow-intercept-touch',
defaultValue: false,
valueConverter: booleanConverter,
});
export const ViewInitEvent = 'ViewInitEvent';
export const ViewDisposeEvent = 'ViewDisposeEvent';

Expand Down Expand Up @@ -291,7 +296,6 @@ class ViewGestureExtended extends View {
this.notify({ eventName: ViewDisposeEvent, object: this });
}
[exclusiveTouchProperty.setNative](value: boolean) {
// console.log('exclusiveTouchProperty', this, value);
if (value) {
if (!this.exclusiveTouchGestureHandler) {
const gestureHandler = Manager.getInstance().createGestureHandler(HandlerType.NATIVE_VIEW, NATIVE_GESTURE_TAG++, {
Expand All @@ -306,9 +310,34 @@ class ViewGestureExtended extends View {
this.exclusiveTouchGestureHandler.detachFromView();
}
}
onTouch(event) {
if (__ANDROID__) {
const mask = event.android.getActionMasked();
if (mask === 0 /* android.view.MotionEvent.ACTION_DOWN */) {
this.nativeViewProtected.requestDisallowInterceptTouchEvent(true);
} else if (mask === 3 /* android.view.MotionEvent.ACTION_CANCEL */ || mask === 1 /* android.view.MotionEvent.ACTION_UP */) {
this.nativeViewProtected.requestDisallowInterceptTouchEvent(false);
}
}
}
disallowInterceptTouchEventRegistered = false;
[disallowInterceptTouchProperty.setNative](value) {
if (__ANDROID__) {
if (value) {
if (!this.disallowInterceptTouchEventRegistered) {
this.disallowInterceptTouchEventRegistered = true;
this.on('touch', this.onTouch, this);
}
} else if (this.disallowInterceptTouchEventRegistered) {
this.disallowInterceptTouchEventRegistered = false;
this.off('touch', this.onTouch, this);
}
}
}
}

exclusiveTouchProperty.register(Style);
disallowInterceptTouchProperty.register(Style);

let installed = false;
export function overrideViewBase() {
Expand Down

0 comments on commit d71c630

Please sign in to comment.