@react-navigation/core 7.0.0-rc.6 → 7.0.0-rc.8
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/lib/commonjs/useIsFocused.cjs +6 -17
- package/lib/commonjs/useIsFocused.cjs.map +1 -1
- package/lib/commonjs/useNavigationState.cjs +5 -15
- package/lib/commonjs/useNavigationState.cjs.map +1 -1
- package/lib/module/useIsFocused.mjs +5 -16
- package/lib/module/useIsFocused.mjs.map +1 -1
- package/lib/module/useNavigationState.mjs +5 -15
- package/lib/module/useNavigationState.mjs.map +1 -1
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/package.json +19 -7
- package/src/useIsFocused.tsx +20 -31
- package/src/useNavigationState.tsx +15 -17
|
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useIsFocused = useIsFocused;
|
|
7
|
-
var
|
|
8
|
-
var React = _react;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _useNavigation = require("./useNavigation.cjs");
|
|
10
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -15,25 +14,15 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
15
14
|
*/
|
|
16
15
|
function useIsFocused() {
|
|
17
16
|
const navigation = (0, _useNavigation.useNavigation)();
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// If the value has changed since the last render, we need to update it.
|
|
22
|
-
// This could happen if we missed an update from the event listeners during re-render.
|
|
23
|
-
// React will process this update immediately, so the old subscription value won't be committed.
|
|
24
|
-
// It is still nice to avoid returning a mismatched value though, so let's override the return value.
|
|
25
|
-
// This is the same logic as in https://github.com/facebook/react/tree/master/packages/use-subscription
|
|
26
|
-
setIsFocused(valueToReturn);
|
|
27
|
-
}
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
const unsubscribeFocus = navigation.addListener('focus', () => setIsFocused(true));
|
|
30
|
-
const unsubscribeBlur = navigation.addListener('blur', () => setIsFocused(false));
|
|
17
|
+
const subscribe = React.useCallback(callback => {
|
|
18
|
+
const unsubscribeFocus = navigation.addListener('focus', callback);
|
|
19
|
+
const unsubscribeBlur = navigation.addListener('blur', callback);
|
|
31
20
|
return () => {
|
|
32
21
|
unsubscribeFocus();
|
|
33
22
|
unsubscribeBlur();
|
|
34
23
|
};
|
|
35
24
|
}, [navigation]);
|
|
36
|
-
React.
|
|
37
|
-
return
|
|
25
|
+
const value = React.useSyncExternalStore(subscribe, navigation.isFocused, navigation.isFocused);
|
|
26
|
+
return value;
|
|
38
27
|
}
|
|
39
28
|
//# sourceMappingURL=useIsFocused.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_useNavigation","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useIsFocused","navigation","useNavigation","subscribe","useCallback","callback","unsubscribeFocus","addListener","unsubscribeBlur","value","useSyncExternalStore","isFocused"],"sourceRoot":"../../src","sources":["use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Y;EACtC,MAAMC,UAAU,GAAG,IAAAC,4BAAa,EAAC,CAAC;EAElC,MAAMC,SAAS,GAAG3B,KAAK,CAAC4B,WAAW,CAChCC,QAAoB,IAAK;IACxB,MAAMC,gBAAgB,GAAGL,UAAU,CAACM,WAAW,CAAC,OAAO,EAAEF,QAAQ,CAAC;IAClE,MAAMG,eAAe,GAAGP,UAAU,CAACM,WAAW,CAAC,MAAM,EAAEF,QAAQ,CAAC;IAEhE,OAAO,MAAM;MACXC,gBAAgB,CAAC,CAAC;MAClBE,eAAe,CAAC,CAAC;IACnB,CAAC;EACH,CAAC,EACD,CAACP,UAAU,CACb,CAAC;EAED,MAAMQ,KAAK,GAAGjC,KAAK,CAACkC,oBAAoB,CACtCP,SAAS,EACTF,UAAU,CAACU,SAAS,EACpBV,UAAU,CAACU,SACb,CAAC;EAED,OAAOF,KAAK;AACd","ignoreList":[]}
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useNavigationState = useNavigationState;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _withSelector = require("use-sync-external-store/with-selector");
|
|
8
9
|
var _useNavigation = require("./useNavigation.cjs");
|
|
9
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -15,22 +16,11 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
15
16
|
*/
|
|
16
17
|
function useNavigationState(selector) {
|
|
17
18
|
const navigation = (0, _useNavigation.useNavigation)();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// The state is only to make sure that there's a re-render when we have a new value
|
|
21
|
-
const [, setResult] = React.useState(() => selector(navigation.getState()));
|
|
22
|
-
|
|
23
|
-
// We store the selector in a ref to avoid re-subscribing listeners every render
|
|
24
|
-
const selectorRef = React.useRef(selector);
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
selectorRef.current = selector;
|
|
27
|
-
});
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
const unsubscribe = navigation.addListener('state', e => {
|
|
30
|
-
setResult(selectorRef.current(e.data.state));
|
|
31
|
-
});
|
|
19
|
+
const subscribe = React.useCallback(callback => {
|
|
20
|
+
const unsubscribe = navigation.addListener('state', callback);
|
|
32
21
|
return unsubscribe;
|
|
33
22
|
}, [navigation]);
|
|
34
|
-
|
|
23
|
+
const value = (0, _withSelector.useSyncExternalStoreWithSelector)(subscribe, navigation.getState, navigation.getState, selector);
|
|
24
|
+
return value;
|
|
35
25
|
}
|
|
36
26
|
//# sourceMappingURL=useNavigationState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_useNavigation","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useNavigationState","selector","navigation","useNavigation","
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_withSelector","_useNavigation","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useNavigationState","selector","navigation","useNavigation","subscribe","useCallback","callback","unsubscribe","addListener","value","useSyncExternalStoreWithSelector","getState"],"sourceR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D;AACA;AACA;AACA;AACA;AACO,SAASW,kBAAkBA,CAChCC,QAAgC,EAC7B;EACH,MAAMC,UAAU,GAAG,IAAAC,4BAAa,EAA4B,CAAC;EAE7D,MAAMC,SAAS,GAAG7B,KAAK,CAAC8B,WAAW,CAChCC,QAAoB,IAAK;IACxB,MAAMC,WAAW,GAAGL,UAAU,CAACM,WAAW,CAAC,OAAO,EAAEF,QAAQ,CAAC;IAE7D,OAAOC,WAAW;EACpB,CAAC,EACD,CAACL,UAAU,CACb,CAAC;EAED,MAAMO,KAAK,GAAG,IAAAC,8CAAgC,EAC5CN,SAAS,EACTF,UAAU,CAACS,QAAQ,EACnBT,UAAU,CAACS,QAAQ,EACnBV,QACF,CAAC;EAED,OAAOQ,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
3
2
|
import { useNavigation } from "./useNavigation.mjs";
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -8,25 +7,15 @@ import { useNavigation } from "./useNavigation.mjs";
|
|
|
8
7
|
*/
|
|
9
8
|
export function useIsFocused() {
|
|
10
9
|
const navigation = useNavigation();
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// If the value has changed since the last render, we need to update it.
|
|
15
|
-
// This could happen if we missed an update from the event listeners during re-render.
|
|
16
|
-
// React will process this update immediately, so the old subscription value won't be committed.
|
|
17
|
-
// It is still nice to avoid returning a mismatched value though, so let's override the return value.
|
|
18
|
-
// This is the same logic as in https://github.com/facebook/react/tree/master/packages/use-subscription
|
|
19
|
-
setIsFocused(valueToReturn);
|
|
20
|
-
}
|
|
21
|
-
React.useEffect(() => {
|
|
22
|
-
const unsubscribeFocus = navigation.addListener('focus', () => setIsFocused(true));
|
|
23
|
-
const unsubscribeBlur = navigation.addListener('blur', () => setIsFocused(false));
|
|
10
|
+
const subscribe = React.useCallback(callback => {
|
|
11
|
+
const unsubscribeFocus = navigation.addListener('focus', callback);
|
|
12
|
+
const unsubscribeBlur = navigation.addListener('blur', callback);
|
|
24
13
|
return () => {
|
|
25
14
|
unsubscribeFocus();
|
|
26
15
|
unsubscribeBlur();
|
|
27
16
|
};
|
|
28
17
|
}, [navigation]);
|
|
29
|
-
React.
|
|
30
|
-
return
|
|
18
|
+
const value = React.useSyncExternalStore(subscribe, navigation.isFocused, navigation.isFocused);
|
|
19
|
+
return value;
|
|
31
20
|
}
|
|
32
21
|
//# sourceMappingURL=useIsFocused.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","useNavigation","useIsFocused","navigation","subscribe","useCallback","callback","unsubscribeFocus","addListener","unsubscribeBlur","value","useSyncExternalStore","isFocused"],"sourceRoot":"../../src","sources":["useIsFocused.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,aAAa,QAAQ,qBAAiB;;AAE/C;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAAA,EAAY;EACtC,MAAMC,UAAU,GAAGF,aAAa,CAAC,CAAC;EAElC,MAAMG,SAAS,GAAGJ,KAAK,CAACK,WAAW,CAChCC,QAAoB,IAAK;IACxB,MAAMC,gBAAgB,GAAGJ,UAAU,CAACK,WAAW,CAAC,OAAO,EAAEF,QAAQ,CAAC;IAClE,MAAMG,eAAe,GAAGN,UAAU,CAACK,WAAW,CAAC,MAAM,EAAEF,QAAQ,CAAC;IAEhE,OAAO,MAAM;MACXC,gBAAgB,CAAC,CAAC;MAClBE,eAAe,CAAC,CAAC;IACnB,CAAC;EACH,CAAC,EACD,CAACN,UAAU,CACb,CAAC;EAED,MAAMO,KAAK,GAAGV,KAAK,CAACW,oBAAoB,CACtCP,SAAS,EACTD,UAAU,CAACS,SAAS,EACpBT,UAAU,CAACS,SACb,CAAC;EAED,OAAOF,KAAK;AACd","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
2
3
|
import { useNavigation } from "./useNavigation.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* Hook to get a value from the current navigation state using a selector.
|
|
@@ -7,22 +8,11 @@ import { useNavigation } from "./useNavigation.mjs";
|
|
|
7
8
|
*/
|
|
8
9
|
export function useNavigationState(selector) {
|
|
9
10
|
const navigation = useNavigation();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// The state is only to make sure that there's a re-render when we have a new value
|
|
13
|
-
const [, setResult] = React.useState(() => selector(navigation.getState()));
|
|
14
|
-
|
|
15
|
-
// We store the selector in a ref to avoid re-subscribing listeners every render
|
|
16
|
-
const selectorRef = React.useRef(selector);
|
|
17
|
-
React.useEffect(() => {
|
|
18
|
-
selectorRef.current = selector;
|
|
19
|
-
});
|
|
20
|
-
React.useEffect(() => {
|
|
21
|
-
const unsubscribe = navigation.addListener('state', e => {
|
|
22
|
-
setResult(selectorRef.current(e.data.state));
|
|
23
|
-
});
|
|
11
|
+
const subscribe = React.useCallback(callback => {
|
|
12
|
+
const unsubscribe = navigation.addListener('state', callback);
|
|
24
13
|
return unsubscribe;
|
|
25
14
|
}, [navigation]);
|
|
26
|
-
|
|
15
|
+
const value = useSyncExternalStoreWithSelector(subscribe, navigation.getState, navigation.getState, selector);
|
|
16
|
+
return value;
|
|
27
17
|
}
|
|
28
18
|
//# sourceMappingURL=useNavigationState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useNavigation","useNavigationState","selector","navigation","
|
|
1
|
+
{"version":3,"names":["React","useSyncExternalStoreWithSelector","useNavigation","useNavigationState","selector","navigation","subscribe","useCallback","callback","unsubscribe","addListener","value","getState"],"sourceRoot":"../../src","sources":["useNavigationState.tsx"],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,gCAAgC,QAAQ,uCAAuC;AAGxF,SAASC,aAAa,QAAQ,qBAAiB;AAM/C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAChCC,QAAgC,EAC7B;EACH,MAAMC,UAAU,GAAGH,aAAa,CAA4B,CAAC;EAE7D,MAAMI,SAAS,GAAGN,KAAK,CAACO,WAAW,CAChCC,QAAoB,IAAK;IACxB,MAAMC,WAAW,GAAGJ,UAAU,CAACK,WAAW,CAAC,OAAO,EAAEF,QAAQ,CAAC;IAE7D,OAAOC,WAAW;EACpB,CAAC,EACD,CAACJ,UAAU,CACb,CAAC;EAED,MAAMM,KAAK,GAAGV,gCAAgC,CAC5CK,SAAS,EACTD,UAAU,CAACO,QAAQ,EACnBP,UAAU,CAACO,QAAQ,EACnBR,QACF,CAAC;EAED,OAAOO,KAAK;AACd","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFocused.d.ts","sourceRoot":"","sources":["../../../src/useIsFocused.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIsFocused.d.ts","sourceRoot":"","sources":["../../../src/useIsFocused.tsx"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAuBtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigationState.d.ts","sourceRoot":"","sources":["../../../src/useNavigationState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"useNavigationState.d.ts","sourceRoot":"","sources":["../../../src/useNavigationState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAOhF,KAAK,QAAQ,CAAC,SAAS,SAAS,aAAa,EAAE,CAAC,IAAI,CAClD,KAAK,EAAE,eAAe,CAAC,SAAS,CAAC,KAC9B,CAAC,CAAC;AAEP;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,aAAa,EAAE,CAAC,EACnE,QAAQ,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,GAC/B,CAAC,CAoBH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/core",
|
|
3
3
|
"description": "Core utilities for building navigators",
|
|
4
|
-
"version": "7.0.0-rc.
|
|
4
|
+
"version": "7.0.0-rc.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"react-native",
|
|
@@ -41,21 +41,23 @@
|
|
|
41
41
|
"clean": "del lib"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@react-navigation/routers": "^7.0.0-rc.
|
|
44
|
+
"@react-navigation/routers": "^7.0.0-rc.5",
|
|
45
45
|
"escape-string-regexp": "^4.0.0",
|
|
46
46
|
"nanoid": "3.3.7",
|
|
47
47
|
"query-string": "^7.1.3",
|
|
48
48
|
"react-is": "^18.2.0",
|
|
49
|
-
"use-latest-callback": "^0.1
|
|
49
|
+
"use-latest-callback": "^0.2.1",
|
|
50
|
+
"use-sync-external-store": "^1.2.2"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@testing-library/react-native": "^12.4.3",
|
|
53
54
|
"@types/react": "~18.2.79",
|
|
54
55
|
"@types/react-is": "^18.2.3",
|
|
56
|
+
"@types/use-sync-external-store": "^0.0.6",
|
|
55
57
|
"del-cli": "^5.1.0",
|
|
56
58
|
"immer": "^10.0.3",
|
|
57
59
|
"react": "18.2.0",
|
|
58
|
-
"react-native-builder-bob": "^0.25.0
|
|
60
|
+
"react-native-builder-bob": "^0.25.0",
|
|
59
61
|
"react-test-renderer": "18.2.0",
|
|
60
62
|
"typescript": "^5.5.2"
|
|
61
63
|
},
|
|
@@ -66,8 +68,18 @@
|
|
|
66
68
|
"source": "src",
|
|
67
69
|
"output": "lib",
|
|
68
70
|
"targets": [
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
[
|
|
72
|
+
"commonjs",
|
|
73
|
+
{
|
|
74
|
+
"esm": true
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"module",
|
|
79
|
+
{
|
|
80
|
+
"esm": true
|
|
81
|
+
}
|
|
82
|
+
],
|
|
71
83
|
[
|
|
72
84
|
"typescript",
|
|
73
85
|
{
|
|
@@ -76,5 +88,5 @@
|
|
|
76
88
|
]
|
|
77
89
|
]
|
|
78
90
|
},
|
|
79
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "1f63ce5b62055a439f43bfcbd6dd5ca5c64af603"
|
|
80
92
|
}
|
package/src/useIsFocused.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
3
2
|
|
|
4
3
|
import { useNavigation } from './useNavigation';
|
|
5
4
|
|
|
@@ -9,35 +8,25 @@ import { useNavigation } from './useNavigation';
|
|
|
9
8
|
*/
|
|
10
9
|
export function useIsFocused(): boolean {
|
|
11
10
|
const navigation = useNavigation();
|
|
12
|
-
const [isFocused, setIsFocused] = useState(navigation.isFocused);
|
|
13
11
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return () => {
|
|
35
|
-
unsubscribeFocus();
|
|
36
|
-
unsubscribeBlur();
|
|
37
|
-
};
|
|
38
|
-
}, [navigation]);
|
|
39
|
-
|
|
40
|
-
React.useDebugValue(valueToReturn);
|
|
41
|
-
|
|
42
|
-
return valueToReturn;
|
|
12
|
+
const subscribe = React.useCallback(
|
|
13
|
+
(callback: () => void) => {
|
|
14
|
+
const unsubscribeFocus = navigation.addListener('focus', callback);
|
|
15
|
+
const unsubscribeBlur = navigation.addListener('blur', callback);
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
unsubscribeFocus();
|
|
19
|
+
unsubscribeBlur();
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
[navigation]
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const value = React.useSyncExternalStore(
|
|
26
|
+
subscribe,
|
|
27
|
+
navigation.isFocused,
|
|
28
|
+
navigation.isFocused
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return value;
|
|
43
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NavigationState, ParamListBase } from '@react-navigation/routers';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
3
4
|
|
|
4
5
|
import type { NavigationProp } from './types';
|
|
5
6
|
import { useNavigation } from './useNavigation';
|
|
@@ -18,24 +19,21 @@ export function useNavigationState<ParamList extends ParamListBase, T>(
|
|
|
18
19
|
): T {
|
|
19
20
|
const navigation = useNavigation<NavigationProp<ParamList>>();
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const subscribe = React.useCallback(
|
|
23
|
+
(callback: () => void) => {
|
|
24
|
+
const unsubscribe = navigation.addListener('state', callback);
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
return unsubscribe;
|
|
27
|
+
},
|
|
28
|
+
[navigation]
|
|
29
|
+
);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
const value = useSyncExternalStoreWithSelector(
|
|
32
|
+
subscribe,
|
|
33
|
+
navigation.getState,
|
|
34
|
+
navigation.getState,
|
|
35
|
+
selector
|
|
36
|
+
);
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
const unsubscribe = navigation.addListener('state', (e) => {
|
|
34
|
-
setResult(selectorRef.current(e.data.state));
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return unsubscribe;
|
|
38
|
-
}, [navigation]);
|
|
39
|
-
|
|
40
|
-
return selector(navigation.getState());
|
|
38
|
+
return value;
|
|
41
39
|
}
|