react-native-gesture-handler 3.5.0 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apple/RNGestureHandler.h +2 -0
- package/apple/RNGestureHandler.mm +23 -2
- package/apple/RNGestureHandlerManager.mm +32 -15
- package/apple/RNGestureHandlerModule.mm +21 -4
- package/lib/module/RNGestureHandlerModule.web.js +3 -0
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/module/v3/components/GestureButtons.js +7 -0
- package/lib/module/v3/components/GestureButtons.js.map +1 -1
- package/lib/module/v3/components/GestureComponents.js +10 -0
- package/lib/module/v3/components/GestureComponents.js.map +1 -1
- package/lib/module/v3/components/GestureComponents.web.js +8 -0
- package/lib/module/v3/components/GestureComponents.web.js.map +1 -1
- package/lib/module/v3/components/PressableWithTouchable.js +15 -6
- package/lib/module/v3/components/PressableWithTouchable.js.map +1 -1
- package/lib/module/v3/components/ScrollViewResponderInterceptor.js +45 -1
- package/lib/module/v3/components/ScrollViewResponderInterceptor.js.map +1 -1
- package/lib/module/v3/components/StatefulPressable.js +18 -7
- package/lib/module/v3/components/StatefulPressable.js.map +1 -1
- package/lib/module/v3/components/Touchable/Touchable.js +27 -8
- package/lib/module/v3/components/Touchable/Touchable.js.map +1 -1
- package/lib/module/v3/detectors/NativeDetector.js +7 -2
- package/lib/module/v3/detectors/NativeDetector.js.map +1 -1
- package/lib/module/v3/detectors/VirtualDetector/InterceptingGestureDetector.js +7 -2
- package/lib/module/v3/detectors/VirtualDetector/InterceptingGestureDetector.js.map +1 -1
- package/lib/module/v3/detectors/VirtualDetector/VirtualDetector.js +2 -0
- package/lib/module/v3/detectors/VirtualDetector/VirtualDetector.js.map +1 -1
- package/lib/module/v3/nativeWrapperGuard.js +48 -0
- package/lib/module/v3/nativeWrapperGuard.js.map +1 -0
- package/lib/module/v3/scrollViewInterop.js +9 -0
- package/lib/module/v3/scrollViewInterop.js.map +1 -1
- package/lib/module/web/constants.js +3 -1
- package/lib/module/web/constants.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +15 -4
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +6 -6
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +42 -9
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/PointerTracker.js +10 -6
- package/lib/module/web/tools/PointerTracker.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.web.d.ts.map +1 -1
- package/lib/typescript/v3/components/GestureButtons.d.ts.map +1 -1
- package/lib/typescript/v3/components/GestureComponents.d.ts.map +1 -1
- package/lib/typescript/v3/components/GestureComponents.web.d.ts.map +1 -1
- package/lib/typescript/v3/components/PressableWithTouchable.d.ts.map +1 -1
- package/lib/typescript/v3/components/ScrollViewResponderInterceptor.d.ts +2 -1
- package/lib/typescript/v3/components/ScrollViewResponderInterceptor.d.ts.map +1 -1
- package/lib/typescript/v3/components/StatefulPressable.d.ts.map +1 -1
- package/lib/typescript/v3/components/Touchable/Touchable.d.ts.map +1 -1
- package/lib/typescript/v3/detectors/NativeDetector.d.ts.map +1 -1
- package/lib/typescript/v3/detectors/VirtualDetector/InterceptingGestureDetector.d.ts.map +1 -1
- package/lib/typescript/v3/detectors/VirtualDetector/VirtualDetector.d.ts.map +1 -1
- package/lib/typescript/v3/nativeWrapperGuard.d.ts +5 -0
- package/lib/typescript/v3/nativeWrapperGuard.d.ts.map +1 -0
- package/lib/typescript/v3/scrollViewInterop.d.ts +1 -0
- package/lib/typescript/v3/scrollViewInterop.d.ts.map +1 -1
- package/lib/typescript/web/constants.d.ts +1 -1
- package/lib/typescript/web/constants.d.ts.map +1 -1
- package/lib/typescript/web/handlers/GestureHandler.d.ts +4 -3
- package/lib/typescript/web/handlers/GestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/handlers/IGestureHandler.d.ts +1 -1
- package/lib/typescript/web/handlers/IGestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts +2 -3
- package/lib/typescript/web/handlers/LongPressGestureHandler.d.ts.map +1 -1
- package/lib/typescript/web/interfaces.d.ts +1 -1
- package/lib/typescript/web/interfaces.d.ts.map +1 -1
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +3 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts.map +1 -1
- package/lib/typescript/web/tools/PointerTracker.d.ts +1 -1
- package/lib/typescript/web/tools/PointerTracker.d.ts.map +1 -1
- package/package.json +12 -4
- package/src/RNGestureHandlerModule.web.ts +3 -0
- package/src/v3/components/GestureButtons.tsx +3 -0
- package/src/v3/components/GestureComponents.tsx +11 -1
- package/src/v3/components/GestureComponents.web.tsx +9 -0
- package/src/v3/components/PressableWithTouchable.tsx +16 -6
- package/src/v3/components/ScrollViewResponderInterceptor.tsx +57 -0
- package/src/v3/components/StatefulPressable.tsx +20 -6
- package/src/v3/components/Touchable/Touchable.tsx +33 -8
- package/src/v3/detectors/NativeDetector.tsx +5 -1
- package/src/v3/detectors/VirtualDetector/InterceptingGestureDetector.tsx +5 -1
- package/src/v3/detectors/VirtualDetector/VirtualDetector.tsx +2 -0
- package/src/v3/nativeWrapperGuard.ts +74 -0
- package/src/v3/scrollViewInterop.ts +10 -0
- package/src/web/constants.ts +3 -1
- package/src/web/handlers/GestureHandler.ts +16 -6
- package/src/web/handlers/IGestureHandler.ts +1 -1
- package/src/web/handlers/LongPressGestureHandler.ts +7 -20
- package/src/web/interfaces.ts +1 -1
- package/src/web/tools/GestureHandlerWebDelegate.ts +65 -14
- package/src/web/tools/PointerTracker.ts +13 -6
|
@@ -12,6 +12,7 @@ import { findNodeHandle, Platform } from 'react-native';
|
|
|
12
12
|
import { tagMessage } from '../../../utils';
|
|
13
13
|
import { useJSResponderHandler } from '../../hooks/useJSResponderHandler';
|
|
14
14
|
import { isComposedGesture } from '../../hooks/utils/relationUtils';
|
|
15
|
+
import { warnIfNativeGestureWrapsNativeWrapper } from '../../nativeWrapperGuard';
|
|
15
16
|
import type { DetectorCallbacks, VirtualChild } from '../../types';
|
|
16
17
|
import type { VirtualDetectorProps } from '../common';
|
|
17
18
|
import { useDetectorAttachmentGuard } from '../useDetectorAttachmentGuard';
|
|
@@ -80,6 +81,7 @@ export function VirtualDetector<
|
|
|
80
81
|
);
|
|
81
82
|
|
|
82
83
|
useNativeGestureRole(viewRef, props.children);
|
|
84
|
+
warnIfNativeGestureWrapsNativeWrapper(props.gesture, props.children);
|
|
83
85
|
|
|
84
86
|
// Dev-only: no host instance after a commit means the child did not hand
|
|
85
87
|
// its `ref` to one. A child that renders null first is reported as well.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { tagMessage } from '../utils';
|
|
5
|
+
import { isComposedGesture } from './hooks/utils/relationUtils';
|
|
6
|
+
import type { Gesture } from './types';
|
|
7
|
+
import { SingleGestureName } from './types';
|
|
8
|
+
|
|
9
|
+
// Exported components that already come with a Native gesture attached
|
|
10
|
+
const nativeWrappers = new Map<unknown, string>();
|
|
11
|
+
// Places in the app that the warning was already logged for
|
|
12
|
+
const reportedPlaces = new Set<string>();
|
|
13
|
+
|
|
14
|
+
export function registerNativeWrappers(components: Record<string, unknown>) {
|
|
15
|
+
if (__DEV__) {
|
|
16
|
+
for (const [name, Component] of Object.entries(components)) {
|
|
17
|
+
nativeWrappers.set(Component, name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Turns an owner stack into the `in Component` lines React uses in its warnings
|
|
23
|
+
function describeOwners(ownerStack: string) {
|
|
24
|
+
const owners = [
|
|
25
|
+
...ownerStack.matchAll(/^\s*at ([A-Z][\w$]*)(?:\.render)? \(/gm),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
return owners
|
|
29
|
+
.slice(0, 5)
|
|
30
|
+
.map(([, name]) => `\n in ${name}`)
|
|
31
|
+
.join('');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function containsNativeGesture(gesture: Gesture): boolean {
|
|
35
|
+
return isComposedGesture(gesture)
|
|
36
|
+
? gesture.gestures.some(containsNativeGesture)
|
|
37
|
+
: gesture.type === SingleGestureName.Native;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function warnIfNativeGestureWrapsNativeWrapper<TConfig, THandlerData>(
|
|
41
|
+
gesture: Gesture<TConfig, THandlerData> | undefined,
|
|
42
|
+
children: ReactNode
|
|
43
|
+
) {
|
|
44
|
+
if (!__DEV__ || !gesture || !containsNativeGesture(gesture as Gesture)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const child = (
|
|
49
|
+
Array.isArray(children) && children.length === 1 ? children[0] : children
|
|
50
|
+
) as { type?: unknown } | null | undefined;
|
|
51
|
+
|
|
52
|
+
const childName = nativeWrappers.get(child?.type);
|
|
53
|
+
|
|
54
|
+
if (!childName) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Identifies the place rendering the detector, so each one is reported once
|
|
59
|
+
// eslint-disable-next-line @eslint-react/no-misused-capture-owner-stack -- guarded by __DEV__
|
|
60
|
+
const ownerStack = React.captureOwnerStack?.() ?? '';
|
|
61
|
+
const place = childName + ownerStack;
|
|
62
|
+
|
|
63
|
+
if (reportedPlaces.has(place)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
reportedPlaces.add(place);
|
|
68
|
+
|
|
69
|
+
console.warn(
|
|
70
|
+
tagMessage(
|
|
71
|
+
`${childName} already has a Native gesture attached by Gesture Handler. Wrapping it with a GestureDetector that uses a Native gesture may result in unexpected behavior. Configure the gesture through the props of ${childName}, or use a component that is not wrapped (e.g. the one exported from \`react-native\`).${describeOwners(ownerStack)}`
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -60,3 +60,13 @@ export function isKeyboardDismissingTap(
|
|
|
60
60
|
TextInput.State.currentlyFocusedInput?.() != null)
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
// A button activating mid-press cancels the JS responder, so RN ScrollView's
|
|
65
|
+
// release-time blur never runs - the button that dropped the press dismisses
|
|
66
|
+
export function dismissKeyboardForDroppedTap() {
|
|
67
|
+
const focusedInput = TextInput.State.currentlyFocusedInput?.();
|
|
68
|
+
|
|
69
|
+
if (focusedInput != null) {
|
|
70
|
+
TextInput.State.blurTextInput(focusedInput);
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/web/constants.ts
CHANGED
|
@@ -6,4 +6,6 @@ export const NATIVE_GESTURE_ROLE_ATTRIBUTE = 'rngh-role';
|
|
|
6
6
|
// not set.
|
|
7
7
|
export const DEFAULT_TOUCH_ACTION = 'none';
|
|
8
8
|
export const DEFAULT_USER_SELECT = 'none';
|
|
9
|
-
|
|
9
|
+
// `null` clears `enableContextMenu`, so the handler decides: the browser menu
|
|
10
|
+
// stays unless the gesture listens to the right mouse button.
|
|
11
|
+
export const DEFAULT_ENABLE_CONTEXT_MENU = null;
|
|
@@ -60,7 +60,7 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
60
60
|
private needsPointerData: boolean = false;
|
|
61
61
|
private _tracker: PointerTracker = new PointerTracker();
|
|
62
62
|
|
|
63
|
-
private _enableContextMenu
|
|
63
|
+
private _enableContextMenu?: boolean | undefined = undefined;
|
|
64
64
|
private _activeCursor?: ActiveCursor | undefined = undefined;
|
|
65
65
|
private _touchAction?: TouchAction | undefined = undefined;
|
|
66
66
|
private _userSelect?: UserSelect | undefined = undefined;
|
|
@@ -822,6 +822,9 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
822
822
|
|
|
823
823
|
if (config.mouseButton !== undefined) {
|
|
824
824
|
this.mouseButton = config.mouseButton;
|
|
825
|
+
// Without `enableContextMenu`, the button decides whether the context
|
|
826
|
+
// menu is blocked, so the listener has to follow it.
|
|
827
|
+
this.needsDOMUpdate = true;
|
|
825
828
|
}
|
|
826
829
|
|
|
827
830
|
if (config.needsPointerData !== undefined) {
|
|
@@ -836,8 +839,9 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
836
839
|
this._activeCursor = config.activeCursor;
|
|
837
840
|
}
|
|
838
841
|
|
|
842
|
+
// An explicit `null` clears the value, so the handler's default applies again.
|
|
839
843
|
if (config.enableContextMenu !== undefined) {
|
|
840
|
-
this.enableContextMenu = config.enableContextMenu;
|
|
844
|
+
this.enableContextMenu = config.enableContextMenu ?? undefined;
|
|
841
845
|
this.needsDOMUpdate = true;
|
|
842
846
|
}
|
|
843
847
|
|
|
@@ -967,7 +971,7 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
967
971
|
// defaults) through partial updates only. Legacy handlers carry them in the
|
|
968
972
|
// full config and still get the reset.
|
|
969
973
|
if (!this.usesNativeOrVirtualDetector()) {
|
|
970
|
-
this.enableContextMenu =
|
|
974
|
+
this.enableContextMenu = undefined;
|
|
971
975
|
this._touchAction = undefined;
|
|
972
976
|
this._userSelect = undefined;
|
|
973
977
|
}
|
|
@@ -1071,10 +1075,16 @@ export default abstract class GestureHandler implements IGestureHandler {
|
|
|
1071
1075
|
this._shouldResetProgress = value;
|
|
1072
1076
|
}
|
|
1073
1077
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1078
|
+
// `undefined` keeps the browser's context menu, unless the gesture listens to
|
|
1079
|
+
// the right mouse button (see `GestureHandlerWebDelegate`).
|
|
1080
|
+
protected get defaultEnableContextMenu(): boolean | undefined {
|
|
1081
|
+
return undefined;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
public get enableContextMenu(): boolean | undefined {
|
|
1085
|
+
return this._enableContextMenu ?? this.defaultEnableContextMenu;
|
|
1076
1086
|
}
|
|
1077
|
-
protected set enableContextMenu(value) {
|
|
1087
|
+
protected set enableContextMenu(value: boolean | undefined) {
|
|
1078
1088
|
this._enableContextMenu = value;
|
|
1079
1089
|
}
|
|
1080
1090
|
|
|
@@ -32,7 +32,7 @@ export default interface IGestureHandler {
|
|
|
32
32
|
shouldResetProgress: boolean;
|
|
33
33
|
readonly enabled: boolean | null;
|
|
34
34
|
readonly pointerType: PointerType;
|
|
35
|
-
enableContextMenu: boolean;
|
|
35
|
+
readonly enableContextMenu: boolean | undefined;
|
|
36
36
|
readonly activeCursor?: ActiveCursor | undefined;
|
|
37
37
|
readonly touchAction?: TouchAction | undefined;
|
|
38
38
|
readonly userSelect?: UserSelect | undefined;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type { ActionType } from '../../ActionType';
|
|
2
1
|
import { State } from '../../State';
|
|
3
2
|
import { SingleGestureName } from '../../v3/types';
|
|
4
|
-
import type {
|
|
5
|
-
AdaptedEvent,
|
|
6
|
-
Config,
|
|
7
|
-
HostDetector,
|
|
8
|
-
PropsRef,
|
|
9
|
-
} from '../interfaces';
|
|
3
|
+
import type { AdaptedEvent, Config } from '../interfaces';
|
|
10
4
|
import type { GestureHandlerDelegate } from '../tools/GestureHandlerDelegate';
|
|
11
5
|
import GestureHandler from './GestureHandler';
|
|
12
6
|
import type IGestureHandler from './IGestureHandler';
|
|
@@ -38,19 +32,6 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
38
32
|
this.name = SingleGestureName.LongPress;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
public override init(
|
|
42
|
-
ref: number,
|
|
43
|
-
propsRef: React.RefObject<PropsRef>,
|
|
44
|
-
actionType: ActionType,
|
|
45
|
-
hostDetector: HostDetector | null = null
|
|
46
|
-
) {
|
|
47
|
-
if (this.enableContextMenu === undefined) {
|
|
48
|
-
this.enableContextMenu = false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
super.init(ref, propsRef, actionType, hostDetector);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
35
|
protected override transformNativeEvent() {
|
|
55
36
|
return {
|
|
56
37
|
...super.transformNativeEvent(),
|
|
@@ -193,4 +174,10 @@ export default class LongPressGestureHandler extends GestureHandler {
|
|
|
193
174
|
this.fail();
|
|
194
175
|
}
|
|
195
176
|
}
|
|
177
|
+
|
|
178
|
+
// A long press opens the context menu on touch devices, so block it unless
|
|
179
|
+
// `enableContextMenu` is set.
|
|
180
|
+
protected override get defaultEnableContextMenu() {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
196
183
|
}
|
package/src/web/interfaces.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface Config extends Record<string, ConfigArgs> {
|
|
|
44
44
|
userSelect?: UserSelect | undefined;
|
|
45
45
|
activeCursor?: ActiveCursor | undefined;
|
|
46
46
|
mouseButton?: MouseButton | undefined;
|
|
47
|
-
enableContextMenu?: boolean | undefined;
|
|
47
|
+
enableContextMenu?: boolean | null | undefined;
|
|
48
48
|
touchAction?: TouchAction | undefined;
|
|
49
49
|
manualActivation?: boolean | undefined;
|
|
50
50
|
dispatchesAnimatedEvents?: false | undefined;
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
MeasureResult,
|
|
20
20
|
} from './GestureHandlerDelegate';
|
|
21
21
|
import KeyboardEventManager from './KeyboardEventManager';
|
|
22
|
+
import NodeManager from './NodeManager';
|
|
22
23
|
import PointerEventManager from './PointerEventManager';
|
|
23
24
|
import ScrollEventManager from './ScrollEventManager';
|
|
24
25
|
import WheelEventManager from './WheelEventManager';
|
|
@@ -59,10 +60,20 @@ export class GestureHandlerWebDelegate
|
|
|
59
60
|
? (viewRef as unknown as HTMLElement)
|
|
60
61
|
: (findNodeHandle(viewRef) as unknown as HTMLElement);
|
|
61
62
|
|
|
62
|
-
this
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
// A handler already on this view may have overwritten the styles, so take
|
|
64
|
+
// the original snapshot from it instead of reading the view.
|
|
65
|
+
const alreadyAttachedHandler = this.findOtherHandlerOnView(
|
|
66
|
+
(handler) => handler.attached
|
|
67
|
+
);
|
|
68
|
+
this.defaultViewStyles = alreadyAttachedHandler
|
|
69
|
+
? {
|
|
70
|
+
...(alreadyAttachedHandler.delegate as GestureHandlerWebDelegate)
|
|
71
|
+
.defaultViewStyles,
|
|
72
|
+
}
|
|
73
|
+
: {
|
|
74
|
+
userSelect: this.view.style.userSelect,
|
|
75
|
+
touchAction: this.view.style.touchAction,
|
|
76
|
+
};
|
|
66
77
|
|
|
67
78
|
const shouldSendHoverEvents = handler.name === SingleGestureName.Hover;
|
|
68
79
|
const shouldSendWheelEvents = handler.name === SingleGestureName.Pan;
|
|
@@ -108,6 +119,13 @@ export class GestureHandlerWebDelegate
|
|
|
108
119
|
restoreDefaultViewStyles(): void {
|
|
109
120
|
this.ensureView(this.view);
|
|
110
121
|
|
|
122
|
+
// Another enabled handler on this view still needs its styles.
|
|
123
|
+
const enabledHandler = this.findOtherEnabledHandlerOnView();
|
|
124
|
+
if (enabledHandler) {
|
|
125
|
+
enabledHandler.delegate.updateDOM();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
111
129
|
this.setViewStyle('userSelect', this.defaultViewStyles.userSelect);
|
|
112
130
|
this.setViewStyle('webkitUserSelect', this.defaultViewStyles.userSelect);
|
|
113
131
|
this.setViewStyle('touchAction', this.defaultViewStyles.touchAction);
|
|
@@ -222,21 +240,24 @@ export class GestureHandlerWebDelegate
|
|
|
222
240
|
}
|
|
223
241
|
}
|
|
224
242
|
|
|
225
|
-
|
|
243
|
+
// Arrow functions, so that each delegate registers its own listener. With a
|
|
244
|
+
// shared prototype method, handlers on the same view would add one listener
|
|
245
|
+
// between them, and the first to remove it would remove it for all.
|
|
246
|
+
private disableContextMenu = (e: MouseEvent): void => {
|
|
226
247
|
e.preventDefault();
|
|
227
|
-
}
|
|
248
|
+
};
|
|
228
249
|
|
|
229
|
-
private enableContextMenu
|
|
250
|
+
private enableContextMenu = (e: MouseEvent): void => {
|
|
230
251
|
e.stopPropagation();
|
|
231
|
-
}
|
|
252
|
+
};
|
|
232
253
|
|
|
233
254
|
private setUserSelect() {
|
|
234
|
-
const
|
|
255
|
+
const styleOwner = this.findStyleOwner();
|
|
235
256
|
|
|
236
257
|
this.ensureView(this.view);
|
|
237
258
|
|
|
238
|
-
const value =
|
|
239
|
-
? (userSelect ?? DEFAULT_USER_SELECT)
|
|
259
|
+
const value = styleOwner
|
|
260
|
+
? (styleOwner.userSelect ?? DEFAULT_USER_SELECT)
|
|
240
261
|
: this.defaultViewStyles.userSelect;
|
|
241
262
|
|
|
242
263
|
this.setViewStyle('userSelect', value);
|
|
@@ -244,18 +265,48 @@ export class GestureHandlerWebDelegate
|
|
|
244
265
|
}
|
|
245
266
|
|
|
246
267
|
private setTouchAction() {
|
|
247
|
-
const
|
|
268
|
+
const styleOwner = this.findStyleOwner();
|
|
248
269
|
|
|
249
270
|
this.ensureView(this.view);
|
|
250
271
|
|
|
251
|
-
const value =
|
|
252
|
-
? (touchAction ?? DEFAULT_TOUCH_ACTION)
|
|
272
|
+
const value = styleOwner
|
|
273
|
+
? (styleOwner.touchAction ?? DEFAULT_TOUCH_ACTION)
|
|
253
274
|
: this.defaultViewStyles.touchAction;
|
|
254
275
|
|
|
255
276
|
this.setViewStyle('touchAction', value);
|
|
256
277
|
this.setViewStyle('WebkitTouchCallout', value);
|
|
257
278
|
}
|
|
258
279
|
|
|
280
|
+
// The handler whose styles the view shows. Handlers sharing a view all write
|
|
281
|
+
// its styles, so a disabled handler defers to an enabled one and restores
|
|
282
|
+
// the defaults only when none is left.
|
|
283
|
+
private findStyleOwner(): IGestureHandler | null {
|
|
284
|
+
return this.gestureHandler.enabled
|
|
285
|
+
? this.gestureHandler
|
|
286
|
+
: this.findOtherEnabledHandlerOnView();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
private findOtherEnabledHandlerOnView(): IGestureHandler | null {
|
|
290
|
+
return this.findOtherHandlerOnView(
|
|
291
|
+
(handler) => handler.attached && !!handler.enabled
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private findOtherHandlerOnView(
|
|
296
|
+
predicate: (handler: IGestureHandler) => boolean
|
|
297
|
+
): IGestureHandler | null {
|
|
298
|
+
// The registry holds the concrete handler classes, which NodeManager also
|
|
299
|
+
// exposes as the interface.
|
|
300
|
+
return (
|
|
301
|
+
(Object.values(NodeManager.nodes) as IGestureHandler[]).find(
|
|
302
|
+
(handler) =>
|
|
303
|
+
handler !== this.gestureHandler &&
|
|
304
|
+
handler.delegate.view === this.view &&
|
|
305
|
+
predicate(handler)
|
|
306
|
+
) ?? null
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
259
310
|
private setContextMenu() {
|
|
260
311
|
// Enabling and disabling the context menu use different listeners, so
|
|
261
312
|
// drop the current one before attaching the right one.
|
|
@@ -11,7 +11,10 @@ export interface TrackerElement {
|
|
|
11
11
|
const MAX_POINTERS = 20;
|
|
12
12
|
|
|
13
13
|
export default class PointerTracker {
|
|
14
|
-
private
|
|
14
|
+
private readonly velocityTrackers: Map<number, VelocityTracker> = new Map<
|
|
15
|
+
number,
|
|
16
|
+
VelocityTracker
|
|
17
|
+
>();
|
|
15
18
|
private readonly _trackedPointers: Map<number, TrackerElement> = new Map<
|
|
16
19
|
number,
|
|
17
20
|
TrackerElement
|
|
@@ -51,6 +54,7 @@ export default class PointerTracker {
|
|
|
51
54
|
};
|
|
52
55
|
|
|
53
56
|
this.trackedPointers.set(event.pointerId, newElement);
|
|
57
|
+
this.velocityTrackers.set(event.pointerId, new VelocityTracker());
|
|
54
58
|
this.mapTouchEventId(event.pointerId);
|
|
55
59
|
|
|
56
60
|
this.cachedAbsoluteAverages = this.getAbsoluteCoordsAverage();
|
|
@@ -59,20 +63,22 @@ export default class PointerTracker {
|
|
|
59
63
|
|
|
60
64
|
public removeFromTracker(pointerId: number): void {
|
|
61
65
|
this.trackedPointers.delete(pointerId);
|
|
66
|
+
this.velocityTrackers.delete(pointerId);
|
|
62
67
|
this.removeMappedTouchId(pointerId);
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
public track(event: AdaptedEvent): void {
|
|
66
71
|
const pointerData = this.trackedPointers.get(event.pointerId);
|
|
72
|
+
const velocityTracker = this.velocityTrackers.get(event.pointerId);
|
|
67
73
|
|
|
68
|
-
if (!pointerData) {
|
|
74
|
+
if (!pointerData || !velocityTracker) {
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
this.lastMovedPointerId = event.pointerId;
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
const [velocityX, velocityY] =
|
|
80
|
+
velocityTracker.add(event);
|
|
81
|
+
const [velocityX, velocityY] = velocityTracker.velocity;
|
|
76
82
|
|
|
77
83
|
pointerData.velocityX = velocityX;
|
|
78
84
|
pointerData.velocityY = velocityY;
|
|
@@ -129,7 +135,8 @@ export default class PointerTracker {
|
|
|
129
135
|
return null;
|
|
130
136
|
}
|
|
131
137
|
|
|
132
|
-
const
|
|
138
|
+
const velocityTracker = this.velocityTrackers.get(pointerId);
|
|
139
|
+
const [x, y] = velocityTracker ? velocityTracker.velocityAt(time) : [0, 0];
|
|
133
140
|
return { x, y };
|
|
134
141
|
}
|
|
135
142
|
|
|
@@ -203,7 +210,7 @@ export default class PointerTracker {
|
|
|
203
210
|
}
|
|
204
211
|
|
|
205
212
|
public resetTracker(): void {
|
|
206
|
-
this.
|
|
213
|
+
this.velocityTrackers.clear();
|
|
207
214
|
this.trackedPointers.clear();
|
|
208
215
|
this.lastMovedPointerId = NaN;
|
|
209
216
|
|