@hanzogui/native 4.3.1 → 7.0.0
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/.turbo/turbo-build.log +1 -1
- package/dist/cjs/PressBoundary.cjs +92 -0
- package/dist/cjs/PressBoundary.native.js +105 -0
- package/dist/cjs/PressBoundary.native.js.map +1 -0
- package/dist/cjs/gesture-handler.cjs +36 -0
- package/dist/cjs/gesture-handler.native.js +39 -0
- package/dist/cjs/gesture-handler.native.js.map +1 -0
- package/dist/cjs/gestureState.cjs +94 -5
- package/dist/cjs/gestureState.native.js +98 -13
- package/dist/cjs/gestureState.native.js.map +1 -1
- package/dist/cjs/index.cjs +4 -1
- package/dist/cjs/index.native.js +4 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/setup-gesture-handler.cjs +44 -8
- package/dist/cjs/setup-gesture-handler.native.js +44 -8
- package/dist/cjs/setup-gesture-handler.native.js.map +1 -1
- package/dist/esm/PressBoundary.mjs +56 -0
- package/dist/esm/PressBoundary.mjs.map +1 -0
- package/dist/esm/PressBoundary.native.js +66 -0
- package/dist/esm/PressBoundary.native.js.map +1 -0
- package/dist/esm/gesture-handler.mjs +6 -0
- package/dist/esm/gesture-handler.mjs.map +1 -0
- package/dist/esm/gesture-handler.native.js +6 -0
- package/dist/esm/gesture-handler.native.js.map +1 -0
- package/dist/esm/gestureState.mjs +92 -5
- package/dist/esm/gestureState.mjs.map +1 -1
- package/dist/esm/gestureState.native.js +96 -13
- package/dist/esm/gestureState.native.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/setup-gesture-handler.mjs +17 -8
- package/dist/esm/setup-gesture-handler.mjs.map +1 -1
- package/dist/esm/setup-gesture-handler.native.js +17 -8
- package/dist/esm/setup-gesture-handler.native.js.map +1 -1
- package/gesture-handler/index.cjs +1 -0
- package/gesture-handler/index.js +1 -0
- package/gesture-handler/index.native.cjs +1 -0
- package/gesture-handler/index.native.js +1 -0
- package/gesture-handler.cjs +1 -0
- package/package.json +17 -4
- package/src/PressBoundary.tsx +81 -0
- package/src/gesture-handler.ts +17 -0
- package/src/gestureState.ts +137 -6
- package/src/index.ts +12 -1
- package/src/setup-gesture-handler.ts +38 -11
- package/types/PressBoundary.d.ts +14 -0
- package/types/PressBoundary.d.ts.map +11 -0
- package/types/gesture-handler.d.ts +8 -0
- package/types/gesture-handler.d.ts.map +11 -0
- package/types/gestureState.d.ts +4 -0
- package/types/gestureState.d.ts.map +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.d.ts.map +2 -2
- package/types/setup-gesture-handler.d.ts +8 -1
- package/types/setup-gesture-handler.d.ts.map +2 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getPortal } from "./portalState.mjs";
|
|
2
2
|
import { getGestureHandler } from "./gestureState.mjs";
|
|
3
|
+
import { claimExternalPressOwnership, releaseExternalPressOwnership } from "./gestureState.mjs";
|
|
3
4
|
import { getWorklets } from "./workletsState.mjs";
|
|
4
5
|
import { getSafeArea } from "./safeAreaState.mjs";
|
|
5
6
|
import { getLinearGradient } from "./linearGradientState.mjs";
|
|
@@ -8,5 +9,5 @@ import { getZeego } from "./zeegoState.mjs";
|
|
|
8
9
|
import { NativeMenuContext } from "./nativeMenuContext.mjs";
|
|
9
10
|
import { getBurnt } from "./burntState.mjs";
|
|
10
11
|
import { NativePortal, NativePortalHost, NativePortalProvider } from "./components.mjs";
|
|
11
|
-
export { NativeMenuContext, NativePortal, NativePortalHost, NativePortalProvider, getBurnt, getGestureHandler, getKeyboardControllerState, getLinearGradient, getPortal, getSafeArea, getWorklets, getZeego, isKeyboardControllerEnabled, setKeyboardControllerState };
|
|
12
|
+
export { NativeMenuContext, NativePortal, NativePortalHost, NativePortalProvider, getBurnt, getGestureHandler, getKeyboardControllerState, getLinearGradient, getPortal, getSafeArea, getWorklets, getZeego, isKeyboardControllerEnabled, setKeyboardControllerState, claimExternalPressOwnership as unstable_claimExternalPressOwnership, releaseExternalPressOwnership as unstable_releaseExternalPressOwnership };
|
|
12
13
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getPortal","getGestureHandler","getWorklets","getSafeArea","getLinearGradient","isKeyboardControllerEnabled","getKeyboardControllerState","setKeyboardControllerState","getZeego","NativeMenuContext","getBurnt","NativePortal","NativePortalHost","NativePortalProvider"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAuCA,SAASA,SAAA,QAAiB;AAI1B,SAASC,iBAAA,QAAyB;
|
|
1
|
+
{"version":3,"names":["getPortal","getGestureHandler","claimExternalPressOwnership","releaseExternalPressOwnership","getWorklets","getSafeArea","getLinearGradient","isKeyboardControllerEnabled","getKeyboardControllerState","setKeyboardControllerState","getZeego","NativeMenuContext","getBurnt","NativePortal","NativePortalHost","NativePortalProvider"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAuCA,SAASA,SAAA,QAAiB;AAI1B,SAASC,iBAAA,QAAyB;AAClC,SACiCC,2BAAA,EACEC,6BAAA,QAC5B;AAWP,SAASC,WAAA,QAAmB;AAI5B,SAASC,WAAA,QAAmB;AAI5B,SAASC,iBAAA,QAAyB;AAIlC,SACEC,2BAAA,EACAC,0BAAA,EACAC,0BAAA,QACK;AAIP,SAASC,QAAA,QAAgB;AAEzB,SAASC,iBAAA,QAAyB;AAGlC,SAASC,QAAA,QAAgB;AAIzB,SAASC,YAAA,EAAcC,gBAAA,EAAkBC,oBAAA,QAA4B","ignoreList":[]}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getPortal } from "./portalState.native.js";
|
|
2
2
|
import { getGestureHandler } from "./gestureState.native.js";
|
|
3
|
+
import { claimExternalPressOwnership, releaseExternalPressOwnership } from "./gestureState.native.js";
|
|
3
4
|
import { getWorklets } from "./workletsState.native.js";
|
|
4
5
|
import { getSafeArea } from "./safeAreaState.native.js";
|
|
5
6
|
import { getLinearGradient } from "./linearGradientState.native.js";
|
|
@@ -8,5 +9,5 @@ import { getZeego } from "./zeegoState.native.js";
|
|
|
8
9
|
import { NativeMenuContext } from "./nativeMenuContext.native.js";
|
|
9
10
|
import { getBurnt } from "./burntState.native.js";
|
|
10
11
|
import { NativePortal, NativePortalHost, NativePortalProvider } from "./components.native.js";
|
|
11
|
-
export { NativeMenuContext, NativePortal, NativePortalHost, NativePortalProvider, getBurnt, getGestureHandler, getKeyboardControllerState, getLinearGradient, getPortal, getSafeArea, getWorklets, getZeego, isKeyboardControllerEnabled, setKeyboardControllerState };
|
|
12
|
+
export { NativeMenuContext, NativePortal, NativePortalHost, NativePortalProvider, getBurnt, getGestureHandler, getKeyboardControllerState, getLinearGradient, getPortal, getSafeArea, getWorklets, getZeego, isKeyboardControllerEnabled, setKeyboardControllerState, claimExternalPressOwnership as unstable_claimExternalPressOwnership, releaseExternalPressOwnership as unstable_releaseExternalPressOwnership };
|
|
12
13
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getPortal","getGestureHandler","getWorklets","getSafeArea","getLinearGradient","isKeyboardControllerEnabled","getKeyboardControllerState","setKeyboardControllerState","getZeego","NativeMenuContext","getBurnt","NativePortal","NativePortalHost","NativePortalProvider"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAuCA,SAASA,SAAA,QAAiB;AAI1B,SAASC,iBAAA,QAAyB;
|
|
1
|
+
{"version":3,"names":["getPortal","getGestureHandler","claimExternalPressOwnership","releaseExternalPressOwnership","getWorklets","getSafeArea","getLinearGradient","isKeyboardControllerEnabled","getKeyboardControllerState","setKeyboardControllerState","getZeego","NativeMenuContext","getBurnt","NativePortal","NativePortalHost","NativePortalProvider"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAuCA,SAASA,SAAA,QAAiB;AAI1B,SAASC,iBAAA,QAAyB;AAClC,SAAAC,2BAAA,EAAAC,6BAAA;AAAA,SACiCC,WAAA;AAAA,SACEC,WAAA;AAAA,SAC5BC,iBAAA;AAWP,SAASC,2BAAmB,EAAAC,0BAAA,EAAAC,0BAAA;AAI5B,SAASC,QAAA,gCAAmB;AAI5B,SAASC,iBAAA,QAAyB;AAIlC,SAAAC,QAAA;AAAA,SACEC,YAAA,EAAAC,gBAAA,EAAAC,oBAAA;AAAA,SAEAJ,iBAAA,EAAAE,YACK,EAIPC,gBAAS,EAETC,oBAAS,EAGTH,QAAS,EAITX,iBAAS,E","ignoreList":[]}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { getGestureHandler } from "./gestureState.mjs";
|
|
2
|
-
|
|
2
|
+
let currentConfig = {
|
|
3
|
+
pressEvents: true,
|
|
4
|
+
sheet: true
|
|
5
|
+
};
|
|
6
|
+
function getGestureHandlerConfig() {
|
|
7
|
+
return currentConfig;
|
|
8
|
+
}
|
|
9
|
+
function setupGestureHandler(config) {
|
|
3
10
|
const g = globalThis;
|
|
4
|
-
if (
|
|
5
|
-
|
|
11
|
+
if (config) {
|
|
12
|
+
currentConfig = config;
|
|
6
13
|
}
|
|
7
|
-
|
|
14
|
+
const isFirstRun = !g.__tamagui_native_gesture_setup_complete;
|
|
15
|
+
g.__tamagui_native_gesture_setup_complete = true;
|
|
8
16
|
try {
|
|
9
17
|
const rngh = require("react-native-gesture-handler");
|
|
10
18
|
const {
|
|
@@ -14,13 +22,13 @@ function setup() {
|
|
|
14
22
|
} = rngh;
|
|
15
23
|
if (Gesture && GestureDetector) {
|
|
16
24
|
getGestureHandler().set({
|
|
17
|
-
enabled:
|
|
25
|
+
enabled: currentConfig.pressEvents !== false,
|
|
18
26
|
Gesture,
|
|
19
27
|
GestureDetector,
|
|
20
28
|
ScrollView: ScrollView || null
|
|
21
29
|
});
|
|
22
|
-
g.
|
|
23
|
-
enabled:
|
|
30
|
+
g.__tamagui_sheet_gesture_state__ = {
|
|
31
|
+
enabled: currentConfig.sheet !== false,
|
|
24
32
|
Gesture,
|
|
25
33
|
GestureDetector,
|
|
26
34
|
ScrollView: ScrollView || null
|
|
@@ -28,5 +36,6 @@ function setup() {
|
|
|
28
36
|
}
|
|
29
37
|
} catch {}
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
setupGestureHandler();
|
|
40
|
+
export { getGestureHandlerConfig, setupGestureHandler };
|
|
32
41
|
//# sourceMappingURL=setup-gesture-handler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getGestureHandler","
|
|
1
|
+
{"version":3,"names":["getGestureHandler","currentConfig","pressEvents","sheet","getGestureHandlerConfig","setupGestureHandler","config","g","globalThis","isFirstRun","__tamagui_native_gesture_setup_complete","rngh","require","Gesture","GestureDetector","ScrollView","set","enabled","__tamagui_sheet_gesture_state__"],"sources":["../../src/setup-gesture-handler.ts"],"sourcesContent":[null],"mappings":"AAmBA,SAASA,iBAAA,QAAyB;AASlC,IAAIC,aAAA,GAAsC;EACxCC,WAAA,EAAa;EACbC,KAAA,EAAO;AACT;AAEO,SAASC,wBAAA,EAAgD;EAC9D,OAAOH,aAAA;AACT;AAEO,SAASI,oBAAoBC,MAAA,EAAqC;EACvE,MAAMC,CAAA,GAAIC,UAAA;EAGV,IAAIF,MAAA,EAAQ;IACVL,aAAA,GAAgBK,MAAA;EAClB;EAGA,MAAMG,UAAA,GAAa,CAACF,CAAA,CAAEG,uCAAA;EACtBH,CAAA,CAAEG,uCAAA,GAA0C;EAE5C,IAAI;IAEF,MAAMC,IAAA,GAAOC,OAAA,CAAQ,8BAA8B;IACnD,MAAM;MAAEC,OAAA;MAASC,eAAA;MAAiBC;IAAW,IAAIJ,IAAA;IAEjD,IAAIE,OAAA,IAAWC,eAAA,EAAiB;MAE9Bd,iBAAA,CAAkB,EAAEgB,GAAA,CAAI;QACtBC,OAAA,EAAShB,aAAA,CAAcC,WAAA,KAAgB;QACvCW,OAAA;QACAC,eAAA;QACAC,UAAA,EAAYA,UAAA,IAAc;MAC5B,CAAC;MAGDR,CAAA,CAAEW,+BAAA,GAAkC;QAClCD,OAAA,EAAShB,aAAA,CAAcE,KAAA,KAAU;QACjCU,OAAA;QACAC,eAAA;QACAC,UAAA,EAAYA,UAAA,IAAc;MAC5B;IACF;EACF,QAAQ,CAER;AACF;AAGAV,mBAAA,CAAoB","ignoreList":[]}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { getGestureHandler } from "./gestureState.native.js";
|
|
2
|
-
|
|
2
|
+
var currentConfig = {
|
|
3
|
+
pressEvents: true,
|
|
4
|
+
sheet: true
|
|
5
|
+
};
|
|
6
|
+
function getGestureHandlerConfig() {
|
|
7
|
+
return currentConfig;
|
|
8
|
+
}
|
|
9
|
+
function setupGestureHandler(config) {
|
|
3
10
|
var g = globalThis;
|
|
4
|
-
if (
|
|
5
|
-
|
|
11
|
+
if (config) {
|
|
12
|
+
currentConfig = config;
|
|
6
13
|
}
|
|
7
|
-
|
|
14
|
+
var isFirstRun = !g.__tamagui_native_gesture_setup_complete;
|
|
15
|
+
g.__tamagui_native_gesture_setup_complete = true;
|
|
8
16
|
try {
|
|
9
17
|
var rngh = require("react-native-gesture-handler");
|
|
10
18
|
var {
|
|
@@ -14,13 +22,13 @@ function setup() {
|
|
|
14
22
|
} = rngh;
|
|
15
23
|
if (Gesture && GestureDetector) {
|
|
16
24
|
getGestureHandler().set({
|
|
17
|
-
enabled:
|
|
25
|
+
enabled: currentConfig.pressEvents !== false,
|
|
18
26
|
Gesture,
|
|
19
27
|
GestureDetector,
|
|
20
28
|
ScrollView: ScrollView || null
|
|
21
29
|
});
|
|
22
|
-
g.
|
|
23
|
-
enabled:
|
|
30
|
+
g.__tamagui_sheet_gesture_state__ = {
|
|
31
|
+
enabled: currentConfig.sheet !== false,
|
|
24
32
|
Gesture,
|
|
25
33
|
GestureDetector,
|
|
26
34
|
ScrollView: ScrollView || null
|
|
@@ -28,5 +36,6 @@ function setup() {
|
|
|
28
36
|
}
|
|
29
37
|
} catch (e) {}
|
|
30
38
|
}
|
|
31
|
-
|
|
39
|
+
setupGestureHandler();
|
|
40
|
+
export { getGestureHandlerConfig, setupGestureHandler };
|
|
32
41
|
//# sourceMappingURL=setup-gesture-handler.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getGestureHandler","
|
|
1
|
+
{"version":3,"names":["getGestureHandler","currentConfig","pressEvents","sheet","getGestureHandlerConfig","setupGestureHandler","config","g","globalThis","isFirstRun","__tamagui_native_gesture_setup_complete","rngh","require","Gesture","GestureDetector","ScrollView","set","enabled","__tamagui_sheet_gesture_state__","e"],"sources":["../../src/setup-gesture-handler.ts"],"sourcesContent":[null],"mappings":"AAmBA,SAASA,iBAAA,QAAyB;AASlC,IAAIC,aAAA,GAAsC;EACxCC,WAAA,EAAa;EACbC,KAAA,EAAO;AACT;AAEO,SAASC,wBAAA,EAAgD;EAC9D,OAAOH,aAAA;AACT;AAEO,SAASI,oBAAoBC,MAAA,EAAqC;EACvE,IAAAC,CAAA,GAAMC,UAAI;EAGV,IAAIF,MAAA,EAAQ;IACVL,aAAA,GAAgBK,MAAA;EAClB;EAGA,IAAAG,UAAM,IAAAF,CAAa,CAACG,uCAAE;EACtBH,CAAA,CAAEG,uCAAA,GAA0C;EAE5C,IAAI;IAEF,IAAAC,IAAM,GAAAC,OAAO,+BAAQ;IACrB;MAAMC,OAAE;MAAAC,eAAS;MAAAC;IAAiB,IAAWJ,IAAI;IAEjD,IAAIE,OAAA,IAAWC,eAAA,EAAiB;MAE9Bd,iBAAA,CAAkB,EAAEgB,GAAA,CAAI;QACtBC,OAAA,EAAShB,aAAA,CAAcC,WAAA,KAAgB;QACvCW,OAAA;QACAC,eAAA;QACAC,UAAA,EAAYA,UAAA,IAAc;MAC5B,CAAC;MAGDR,CAAA,CAAEW,+BAAA,GAAkC;QAClCD,OAAA,EAAShB,aAAA,CAAcE,KAAA,KAAU;QACjCU,OAAA;QACAC,eAAA;QACAC,UAAA,EAAYA,UAAA,IAAc;MAC5B;IACF;EACF,SAAQI,CAAA,GAER;AACF;AAGAd,mBAAA,CAAoB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.assign(module.exports, require('../dist/cjs/gesture-handler.cjs'))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.assign(module.exports, require('../dist/cjs/gesture-handler.cjs'))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.assign(module.exports, require('../dist/cjs/gesture-handler.native.js'))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.assign(module.exports, require('../dist/cjs/gesture-handler.native.js'))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.assign(module.exports, require('./dist/cjs/gesture-handler.cjs'))
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Native setup modules for Hanzo GUI - portals, gesture handler, worklets, and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
7
|
-
"**/setup-*"
|
|
7
|
+
"**/setup-*",
|
|
8
|
+
"**/gesture-handler*"
|
|
8
9
|
],
|
|
9
10
|
"main": "dist/cjs",
|
|
10
11
|
"module": "dist/esm",
|
|
@@ -17,6 +18,9 @@
|
|
|
17
18
|
"setup-gesture-handler": [
|
|
18
19
|
"./types/setup-gesture-handler.d.ts"
|
|
19
20
|
],
|
|
21
|
+
"gesture-handler": [
|
|
22
|
+
"./types/gesture-handler.d.ts"
|
|
23
|
+
],
|
|
20
24
|
"setup-worklets": [
|
|
21
25
|
"./types/setup-worklets.d.ts"
|
|
22
26
|
],
|
|
@@ -66,6 +70,15 @@
|
|
|
66
70
|
"require": "./dist/cjs/setup-gesture-handler.cjs",
|
|
67
71
|
"default": "./dist/esm/setup-gesture-handler.mjs"
|
|
68
72
|
},
|
|
73
|
+
"./gesture-handler": {
|
|
74
|
+
"types": "./types/gesture-handler.d.ts",
|
|
75
|
+
"react-native": "./dist/esm/gesture-handler.native.js",
|
|
76
|
+
"browser": "./dist/esm/gesture-handler.mjs",
|
|
77
|
+
"module": "./dist/esm/gesture-handler.mjs",
|
|
78
|
+
"import": "./dist/esm/gesture-handler.mjs",
|
|
79
|
+
"require": "./dist/cjs/gesture-handler.cjs",
|
|
80
|
+
"default": "./dist/esm/gesture-handler.mjs"
|
|
81
|
+
},
|
|
69
82
|
"./setup-worklets": {
|
|
70
83
|
"types": "./types/setup-worklets.d.ts",
|
|
71
84
|
"react-native": "./dist/esm/setup-worklets.native.js",
|
|
@@ -131,7 +144,7 @@
|
|
|
131
144
|
"clean:build": "hanzo-gui-build clean:build"
|
|
132
145
|
},
|
|
133
146
|
"devDependencies": {
|
|
134
|
-
"@hanzogui/build": "
|
|
147
|
+
"@hanzogui/build": "^7.0.0",
|
|
135
148
|
"burnt": "^0.12.2",
|
|
136
149
|
"react": ">=19",
|
|
137
150
|
"react-native": "0.83.2",
|
|
@@ -192,4 +205,4 @@
|
|
|
192
205
|
"optional": true
|
|
193
206
|
}
|
|
194
207
|
}
|
|
195
|
-
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View, type ViewProps } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
claimExternalPressOwnership,
|
|
5
|
+
releaseExternalPressOwnership,
|
|
6
|
+
type ExternalPressOwnershipToken,
|
|
7
|
+
} from './gestureState'
|
|
8
|
+
|
|
9
|
+
export interface PressBoundaryProps extends ViewProps {
|
|
10
|
+
enabled?: boolean
|
|
11
|
+
/**
|
|
12
|
+
* Alias for enabling the boundary. The behavior is limited to Tamagui's
|
|
13
|
+
* shared press ownership and does not patch arbitrary RN bubbling.
|
|
14
|
+
*/
|
|
15
|
+
stopPropagation?: boolean
|
|
16
|
+
debugName?: string | null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function composeFirst<T extends (...args: any[]) => void>(ours: T, theirs?: T) {
|
|
20
|
+
return (...args: Parameters<T>) => {
|
|
21
|
+
ours(...args)
|
|
22
|
+
theirs?.(...args)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function composeLast<T extends (...args: any[]) => void>(theirs: T | undefined, ours: T) {
|
|
27
|
+
return (...args: Parameters<T>) => {
|
|
28
|
+
theirs?.(...args)
|
|
29
|
+
ours(...args)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const PressBoundary: React.ForwardRefExoticComponent<
|
|
34
|
+
PressBoundaryProps & React.RefAttributes<View>
|
|
35
|
+
> = React.forwardRef<View, PressBoundaryProps>(function PressBoundary(
|
|
36
|
+
{
|
|
37
|
+
enabled,
|
|
38
|
+
stopPropagation,
|
|
39
|
+
debugName,
|
|
40
|
+
onTouchStart,
|
|
41
|
+
onTouchEnd,
|
|
42
|
+
onTouchCancel,
|
|
43
|
+
onResponderGrant,
|
|
44
|
+
onResponderRelease,
|
|
45
|
+
onResponderTerminate,
|
|
46
|
+
...props
|
|
47
|
+
},
|
|
48
|
+
forwardedRef
|
|
49
|
+
) {
|
|
50
|
+
const tokenRef = React.useRef<ExternalPressOwnershipToken | null>(null)
|
|
51
|
+
const isEnabled = enabled ?? stopPropagation ?? true
|
|
52
|
+
|
|
53
|
+
const claim = React.useCallback((): void => {
|
|
54
|
+
if (!isEnabled) return
|
|
55
|
+
if (tokenRef.current) {
|
|
56
|
+
releaseExternalPressOwnership(tokenRef.current, debugName)
|
|
57
|
+
}
|
|
58
|
+
tokenRef.current = claimExternalPressOwnership(debugName)
|
|
59
|
+
}, [debugName, isEnabled])
|
|
60
|
+
|
|
61
|
+
const release = React.useCallback((): void => {
|
|
62
|
+
if (!tokenRef.current) return
|
|
63
|
+
releaseExternalPressOwnership(tokenRef.current, debugName)
|
|
64
|
+
tokenRef.current = null
|
|
65
|
+
}, [debugName])
|
|
66
|
+
|
|
67
|
+
React.useEffect(() => release, [release])
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<View
|
|
71
|
+
ref={forwardedRef}
|
|
72
|
+
{...props}
|
|
73
|
+
onTouchStart={composeFirst(claim, onTouchStart)}
|
|
74
|
+
onTouchEnd={composeLast(onTouchEnd, release)}
|
|
75
|
+
onTouchCancel={composeLast(onTouchCancel, release)}
|
|
76
|
+
onResponderGrant={composeFirst(claim, onResponderGrant)}
|
|
77
|
+
onResponderRelease={composeLast(onResponderRelease, release)}
|
|
78
|
+
onResponderTerminate={composeLast(onResponderTerminate, release)}
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { getGestureHandler } from './gestureState'
|
|
2
|
+
export type {
|
|
3
|
+
ExternalPressOwnershipToken,
|
|
4
|
+
GestureHandlerAccessor,
|
|
5
|
+
PressGestureConfig,
|
|
6
|
+
} from './gestureState'
|
|
7
|
+
export {
|
|
8
|
+
claimExternalPressOwnership as unstable_claimExternalPressOwnership,
|
|
9
|
+
releaseExternalPressOwnership as unstable_releaseExternalPressOwnership,
|
|
10
|
+
} from './gestureState'
|
|
11
|
+
export { PressBoundary } from './PressBoundary'
|
|
12
|
+
export type { PressBoundaryProps } from './PressBoundary'
|
|
13
|
+
export {
|
|
14
|
+
getGestureHandlerConfig,
|
|
15
|
+
setupGestureHandler,
|
|
16
|
+
type GestureHandlerConfig,
|
|
17
|
+
} from './setup-gesture-handler'
|
package/src/gestureState.ts
CHANGED
|
@@ -8,6 +8,24 @@ const state = createGlobalState<GestureState>(`gesture`, {
|
|
|
8
8
|
ScrollView: null,
|
|
9
9
|
})
|
|
10
10
|
|
|
11
|
+
let pressGestureDebugId = 0
|
|
12
|
+
let externalPressDebugId = 0
|
|
13
|
+
|
|
14
|
+
type PressOwnerSource = 'internal' | 'external' | null
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Global press coordination - ensures only innermost pressable fires press events,
|
|
18
|
+
* matching RN Pressable/responder system semantics where deepest component wins.
|
|
19
|
+
* Uses a grace period to allow child gestures to steal ownership from parent,
|
|
20
|
+
* since RNGH fires parent gestures before child gestures.
|
|
21
|
+
*/
|
|
22
|
+
const pressState = {
|
|
23
|
+
owner: null as object | null,
|
|
24
|
+
ownerId: null as number | null,
|
|
25
|
+
ownerSource: null as PressOwnerSource,
|
|
26
|
+
timestamp: 0,
|
|
27
|
+
}
|
|
28
|
+
|
|
11
29
|
export interface Insets {
|
|
12
30
|
top?: number
|
|
13
31
|
left?: number
|
|
@@ -16,6 +34,7 @@ export interface Insets {
|
|
|
16
34
|
}
|
|
17
35
|
|
|
18
36
|
export type PressGestureConfig = {
|
|
37
|
+
debugName?: string | null
|
|
19
38
|
onPressIn?: (e: any) => void
|
|
20
39
|
onPressOut?: (e: any) => void
|
|
21
40
|
onPress?: (e: any) => void
|
|
@@ -32,6 +51,51 @@ export interface GestureHandlerAccessor {
|
|
|
32
51
|
createPressGesture(config: PressGestureConfig): any
|
|
33
52
|
}
|
|
34
53
|
|
|
54
|
+
export type ExternalPressOwnershipToken = object
|
|
55
|
+
|
|
56
|
+
function resetPressOwner() {
|
|
57
|
+
pressState.owner = null
|
|
58
|
+
pressState.ownerId = null
|
|
59
|
+
pressState.ownerSource = null
|
|
60
|
+
pressState.timestamp = 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resetStaleOwner(now: number, debugName?: string | null) {
|
|
64
|
+
if (now - pressState.timestamp > 2000) {
|
|
65
|
+
resetPressOwner()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function claimExternalPressOwnership(
|
|
70
|
+
debugName?: string | null
|
|
71
|
+
): ExternalPressOwnershipToken {
|
|
72
|
+
const now = Date.now()
|
|
73
|
+
resetStaleOwner(now, debugName)
|
|
74
|
+
|
|
75
|
+
const token = {}
|
|
76
|
+
const ownerId = ++externalPressDebugId
|
|
77
|
+
const previousOwnerId = pressState.ownerId
|
|
78
|
+
const previousOwnerSource = pressState.ownerSource
|
|
79
|
+
|
|
80
|
+
pressState.owner = token
|
|
81
|
+
pressState.ownerId = ownerId
|
|
82
|
+
pressState.ownerSource = 'external'
|
|
83
|
+
pressState.timestamp = now
|
|
84
|
+
|
|
85
|
+
return token
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function releaseExternalPressOwnership(
|
|
89
|
+
token: ExternalPressOwnershipToken | null | undefined,
|
|
90
|
+
debugName?: string | null
|
|
91
|
+
): void {
|
|
92
|
+
if (!token || pressState.owner !== token) {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
resetPressOwner()
|
|
97
|
+
}
|
|
98
|
+
|
|
35
99
|
export function getGestureHandler(): GestureHandlerAccessor {
|
|
36
100
|
return {
|
|
37
101
|
get isEnabled(): boolean {
|
|
@@ -54,19 +118,70 @@ export function getGestureHandler(): GestureHandlerAccessor {
|
|
|
54
118
|
|
|
55
119
|
const longPressDuration = config.delayLongPress ?? 500
|
|
56
120
|
|
|
121
|
+
// unique token for this gesture instance - used to track ownership
|
|
122
|
+
const myToken = {}
|
|
123
|
+
const myDebugId = ++pressGestureDebugId
|
|
124
|
+
|
|
125
|
+
// Grace period for child gestures to steal ownership from parent.
|
|
126
|
+
// RNGH fires parent before child, but we want innermost to win.
|
|
127
|
+
// Claims typically span a few ms, 24ms gives enough room to observe
|
|
128
|
+
// ordering while debugging slower frames.
|
|
129
|
+
const GRACE_PERIOD_MS = process.env.TAMAGUI_RNGH_PRESS_DELAY
|
|
130
|
+
? +process.env.TAMAGUI_RNGH_PRESS_DELAY
|
|
131
|
+
: 24
|
|
132
|
+
|
|
133
|
+
const tryClaimOwnership = () => {
|
|
134
|
+
const now = Date.now()
|
|
135
|
+
resetStaleOwner(now, config.debugName)
|
|
136
|
+
|
|
137
|
+
// within grace period, last claimer wins (child fires after parent)
|
|
138
|
+
const withinGrace = now - pressState.timestamp < GRACE_PERIOD_MS
|
|
139
|
+
const previousOwnerId = pressState.ownerId
|
|
140
|
+
const previousOwnerSource = pressState.ownerSource
|
|
141
|
+
if (
|
|
142
|
+
pressState.owner === null ||
|
|
143
|
+
(withinGrace && pressState.ownerSource !== 'external')
|
|
144
|
+
) {
|
|
145
|
+
pressState.owner = myToken
|
|
146
|
+
pressState.ownerId = myDebugId
|
|
147
|
+
pressState.ownerSource = 'internal'
|
|
148
|
+
pressState.timestamp = now
|
|
149
|
+
}
|
|
150
|
+
return pressState.owner === myToken
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isOwner = () => pressState.owner === myToken
|
|
154
|
+
|
|
155
|
+
const releaseOwnership = () => {
|
|
156
|
+
if (pressState.owner === myToken) {
|
|
157
|
+
resetPressOwner()
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
57
161
|
// Tap gesture for regular presses
|
|
58
162
|
// Use long maxDuration to not cancel during long presses
|
|
59
163
|
const tap = Gesture.Tap()
|
|
60
164
|
.runOnJS(true)
|
|
61
165
|
.maxDuration(10000) // allow very long presses
|
|
62
166
|
.onBegin((e: any) => {
|
|
63
|
-
|
|
167
|
+
tryClaimOwnership()
|
|
168
|
+
// defer onPressIn until after grace period to ensure we're the final owner
|
|
169
|
+
setTimeout(() => {
|
|
170
|
+
if (isOwner()) {
|
|
171
|
+
config.onPressIn?.(e)
|
|
172
|
+
}
|
|
173
|
+
}, GRACE_PERIOD_MS + 1)
|
|
64
174
|
})
|
|
65
175
|
.onEnd((e: any) => {
|
|
66
|
-
|
|
176
|
+
if (isOwner()) {
|
|
177
|
+
config.onPress?.(e)
|
|
178
|
+
}
|
|
67
179
|
})
|
|
68
180
|
.onFinalize((e: any) => {
|
|
69
|
-
|
|
181
|
+
if (isOwner()) {
|
|
182
|
+
config.onPressOut?.(e)
|
|
183
|
+
releaseOwnership()
|
|
184
|
+
}
|
|
70
185
|
})
|
|
71
186
|
|
|
72
187
|
if (config.hitSlop) tap.hitSlop(config.hitSlop)
|
|
@@ -78,9 +193,25 @@ export function getGestureHandler(): GestureHandlerAccessor {
|
|
|
78
193
|
const longPress = Gesture.LongPress()
|
|
79
194
|
.runOnJS(true)
|
|
80
195
|
.minDuration(longPressDuration)
|
|
81
|
-
.onBegin((e: any) =>
|
|
82
|
-
|
|
83
|
-
|
|
196
|
+
.onBegin((e: any) => {
|
|
197
|
+
tryClaimOwnership()
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
if (isOwner()) {
|
|
200
|
+
config.onPressIn?.(e)
|
|
201
|
+
}
|
|
202
|
+
}, GRACE_PERIOD_MS + 1)
|
|
203
|
+
})
|
|
204
|
+
.onStart((e: any) => {
|
|
205
|
+
if (isOwner()) {
|
|
206
|
+
config.onLongPress?.(e)
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
.onFinalize((e: any) => {
|
|
210
|
+
if (isOwner()) {
|
|
211
|
+
config.onPressOut?.(e)
|
|
212
|
+
releaseOwnership()
|
|
213
|
+
}
|
|
214
|
+
})
|
|
84
215
|
|
|
85
216
|
if (config.hitSlop) longPress.hitSlop(config.hitSlop)
|
|
86
217
|
|
package/src/index.ts
CHANGED
|
@@ -42,7 +42,18 @@ export type { PortalAccessor } from './portalState'
|
|
|
42
42
|
|
|
43
43
|
// gesture handler
|
|
44
44
|
export { getGestureHandler } from './gestureState'
|
|
45
|
-
export
|
|
45
|
+
export {
|
|
46
|
+
claimExternalPressOwnership as unstable_claimExternalPressOwnership,
|
|
47
|
+
releaseExternalPressOwnership as unstable_releaseExternalPressOwnership,
|
|
48
|
+
} from './gestureState'
|
|
49
|
+
export type {
|
|
50
|
+
ExternalPressOwnershipToken,
|
|
51
|
+
GestureHandlerAccessor,
|
|
52
|
+
PressGestureConfig,
|
|
53
|
+
} from './gestureState'
|
|
54
|
+
// NOTE: setupGestureHandler is exported from setup-gesture-handler.ts entry point,
|
|
55
|
+
// not here, to avoid bundler pulling in RNGH require during tree-shaking
|
|
56
|
+
export type { GestureHandlerConfig } from './setup-gesture-handler'
|
|
46
57
|
|
|
47
58
|
// worklets
|
|
48
59
|
export { getWorklets } from './workletsState'
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Setup gesture handler for
|
|
2
|
+
* Setup gesture handler for Tamagui native components.
|
|
3
3
|
*
|
|
4
4
|
* Simply import this module at the top of your app entry point:
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
|
+
* // auto-setup with all features enabled
|
|
8
9
|
* import '@hanzogui/native/setup-gesture-handler'
|
|
10
|
+
*
|
|
11
|
+
* // or configure selectively
|
|
12
|
+
* import { setupGestureHandler } from '@hanzogui/native/setup-gesture-handler'
|
|
13
|
+
* setupGestureHandler({ pressEvents: true, sheet: false })
|
|
9
14
|
* ```
|
|
10
15
|
*
|
|
11
16
|
* This automatically detects and configures react-native-gesture-handler
|
|
@@ -14,12 +19,33 @@
|
|
|
14
19
|
|
|
15
20
|
import { getGestureHandler } from './gestureState'
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
export interface GestureHandlerConfig {
|
|
23
|
+
/** use RNGH for press events on Tamagui components (default: true) */
|
|
24
|
+
pressEvents?: boolean
|
|
25
|
+
/** use RNGH for Sheet drag gestures (default: true) */
|
|
26
|
+
sheet?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let currentConfig: GestureHandlerConfig = {
|
|
30
|
+
pressEvents: true,
|
|
31
|
+
sheet: true,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getGestureHandlerConfig(): GestureHandlerConfig {
|
|
35
|
+
return currentConfig
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function setupGestureHandler(config?: GestureHandlerConfig): void {
|
|
18
39
|
const g = globalThis as any
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
|
|
41
|
+
// override config if provided
|
|
42
|
+
if (config) {
|
|
43
|
+
currentConfig = config
|
|
21
44
|
}
|
|
22
|
-
|
|
45
|
+
|
|
46
|
+
// allow re-running setup to change config
|
|
47
|
+
const isFirstRun = !g.__tamagui_native_gesture_setup_complete
|
|
48
|
+
g.__tamagui_native_gesture_setup_complete = true
|
|
23
49
|
|
|
24
50
|
try {
|
|
25
51
|
// dynamically require RNGH - it should already be imported by the app
|
|
@@ -27,16 +53,17 @@ function setup() {
|
|
|
27
53
|
const { Gesture, GestureDetector, ScrollView } = rngh
|
|
28
54
|
|
|
29
55
|
if (Gesture && GestureDetector) {
|
|
56
|
+
// only enable if pressEvents is true
|
|
30
57
|
getGestureHandler().set({
|
|
31
|
-
enabled:
|
|
58
|
+
enabled: currentConfig.pressEvents !== false,
|
|
32
59
|
Gesture,
|
|
33
60
|
GestureDetector,
|
|
34
61
|
ScrollView: ScrollView || null,
|
|
35
62
|
})
|
|
36
63
|
|
|
37
|
-
//
|
|
38
|
-
g.
|
|
39
|
-
enabled:
|
|
64
|
+
// sheet state - only enable if sheet is true
|
|
65
|
+
g.__tamagui_sheet_gesture_state__ = {
|
|
66
|
+
enabled: currentConfig.sheet !== false,
|
|
40
67
|
Gesture,
|
|
41
68
|
GestureDetector,
|
|
42
69
|
ScrollView: ScrollView || null,
|
|
@@ -47,5 +74,5 @@ function setup() {
|
|
|
47
74
|
}
|
|
48
75
|
}
|
|
49
76
|
|
|
50
|
-
// run setup immediately on import
|
|
51
|
-
|
|
77
|
+
// run setup immediately on import (can be overridden by calling setupGestureHandler)
|
|
78
|
+
setupGestureHandler()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type ViewProps } from "react-native";
|
|
3
|
+
export interface PressBoundaryProps extends ViewProps {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Alias for enabling the boundary. The behavior is limited to Tamagui's
|
|
7
|
+
* shared press ownership and does not patch arbitrary RN bubbling.
|
|
8
|
+
*/
|
|
9
|
+
stopPropagation?: boolean;
|
|
10
|
+
debugName?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare const PressBoundary: React.ForwardRefExoticComponent<PressBoundaryProps & React.RefAttributes<View>>;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=PressBoundary.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,WAAW,iBAAiB;AAOrC,iBAAiB,2BAA2B,UAAU;CACpD;;;;;CAKA;CACA;;AAiBF,OAAO,cAAM,eAAe,MAAM,0BAChC,qBAAqB,MAAM,cAAc",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/PressBoundary.tsx"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"import React from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport {\n claimExternalPressOwnership,\n releaseExternalPressOwnership,\n type ExternalPressOwnershipToken,\n} from './gestureState'\n\nexport interface PressBoundaryProps extends ViewProps {\n enabled?: boolean\n /**\n * Alias for enabling the boundary. The behavior is limited to Tamagui's\n * shared press ownership and does not patch arbitrary RN bubbling.\n */\n stopPropagation?: boolean\n debugName?: string | null\n}\n\nfunction composeFirst<T extends (...args: any[]) => void>(ours: T, theirs?: T) {\n return (...args: Parameters<T>) => {\n ours(...args)\n theirs?.(...args)\n }\n}\n\nfunction composeLast<T extends (...args: any[]) => void>(theirs: T | undefined, ours: T) {\n return (...args: Parameters<T>) => {\n theirs?.(...args)\n ours(...args)\n }\n}\n\nexport const PressBoundary: React.ForwardRefExoticComponent<\n PressBoundaryProps & React.RefAttributes<View>\n> = React.forwardRef<View, PressBoundaryProps>(function PressBoundary(\n {\n enabled,\n stopPropagation,\n debugName,\n onTouchStart,\n onTouchEnd,\n onTouchCancel,\n onResponderGrant,\n onResponderRelease,\n onResponderTerminate,\n ...props\n },\n forwardedRef\n) {\n const tokenRef = React.useRef<ExternalPressOwnershipToken | null>(null)\n const isEnabled = enabled ?? stopPropagation ?? true\n\n const claim = React.useCallback((): void => {\n if (!isEnabled) return\n if (tokenRef.current) {\n releaseExternalPressOwnership(tokenRef.current, debugName)\n }\n tokenRef.current = claimExternalPressOwnership(debugName)\n }, [debugName, isEnabled])\n\n const release = React.useCallback((): void => {\n if (!tokenRef.current) return\n releaseExternalPressOwnership(tokenRef.current, debugName)\n tokenRef.current = null\n }, [debugName])\n\n React.useEffect(() => release, [release])\n\n return (\n <View\n ref={forwardedRef}\n {...props}\n onTouchStart={composeFirst(claim, onTouchStart)}\n onTouchEnd={composeLast(onTouchEnd, release)}\n onTouchCancel={composeLast(onTouchCancel, release)}\n onResponderGrant={composeFirst(claim, onResponderGrant)}\n onResponderRelease={composeLast(onResponderRelease, release)}\n onResponderTerminate={composeLast(onResponderTerminate, release)}\n />\n )\n})\n"
|
|
10
|
+
]
|
|
11
|
+
}
|