Skip to content

Commit d71c630

Browse files
committed
feat(android): disallowInterceptTouch
1 parent cf2e1ba commit d71c630

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/gesturehandler/gesturehandler.common.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ export const exclusiveTouchProperty = new CssProperty<Style, boolean>({
260260
defaultValue: false,
261261
valueConverter: booleanConverter,
262262
});
263-
263+
export const disallowInterceptTouchProperty = new CssProperty<Style, boolean>({
264+
name: 'disallowInterceptTouch',
265+
cssName: 'disallow-intercept-touch',
266+
defaultValue: false,
267+
valueConverter: booleanConverter,
268+
});
264269
export const ViewInitEvent = 'ViewInitEvent';
265270
export const ViewDisposeEvent = 'ViewDisposeEvent';
266271

@@ -291,7 +296,6 @@ class ViewGestureExtended extends View {
291296
this.notify({ eventName: ViewDisposeEvent, object: this });
292297
}
293298
[exclusiveTouchProperty.setNative](value: boolean) {
294-
// console.log('exclusiveTouchProperty', this, value);
295299
if (value) {
296300
if (!this.exclusiveTouchGestureHandler) {
297301
const gestureHandler = Manager.getInstance().createGestureHandler(HandlerType.NATIVE_VIEW, NATIVE_GESTURE_TAG++, {
@@ -306,9 +310,34 @@ class ViewGestureExtended extends View {
306310
this.exclusiveTouchGestureHandler.detachFromView();
307311
}
308312
}
313+
onTouch(event) {
314+
if (__ANDROID__) {
315+
const mask = event.android.getActionMasked();
316+
if (mask === 0 /* android.view.MotionEvent.ACTION_DOWN */) {
317+
this.nativeViewProtected.requestDisallowInterceptTouchEvent(true);
318+
} else if (mask === 3 /* android.view.MotionEvent.ACTION_CANCEL */ || mask === 1 /* android.view.MotionEvent.ACTION_UP */) {
319+
this.nativeViewProtected.requestDisallowInterceptTouchEvent(false);
320+
}
321+
}
322+
}
323+
disallowInterceptTouchEventRegistered = false;
324+
[disallowInterceptTouchProperty.setNative](value) {
325+
if (__ANDROID__) {
326+
if (value) {
327+
if (!this.disallowInterceptTouchEventRegistered) {
328+
this.disallowInterceptTouchEventRegistered = true;
329+
this.on('touch', this.onTouch, this);
330+
}
331+
} else if (this.disallowInterceptTouchEventRegistered) {
332+
this.disallowInterceptTouchEventRegistered = false;
333+
this.off('touch', this.onTouch, this);
334+
}
335+
}
336+
}
309337
}
310338

311339
exclusiveTouchProperty.register(Style);
340+
disallowInterceptTouchProperty.register(Style);
312341

313342
let installed = false;
314343
export function overrideViewBase() {

0 commit comments

Comments
 (0)