@granite-js/react-native 0.1.12 → 0.1.14
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/CHANGELOG.md +30 -0
- package/dist/index.d.ts +0 -1
- package/dist/use-back-event/useBackEvent.d.ts +2 -6
- package/package.json +9 -9
- package/src/app/AppRoot.tsx +2 -4
- package/src/index.ts +0 -1
- package/src/router/components/useRouterBackHandler.tsx +2 -2
- package/src/router/utils/screen.tsx +6 -0
- package/src/use-back-event/useBackEvent.tsx +5 -12
- package/dist/react/index.d.ts +0 -1
- package/dist/react/useWaitForReturnNavigator.d.ts +0 -39
- package/src/react/index.ts +0 -1
- package/src/react/useWaitForReturnNavigator.ts +0 -75
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 0.1.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0520d19: Fix type error
|
|
8
|
+
- a06bb7d: Remove useWaitForReturnNavigator
|
|
9
|
+
- 6d38bc5: Clarify error message for missing \_404 Page
|
|
10
|
+
- @granite-js/cli@0.1.14
|
|
11
|
+
- @granite-js/image@0.1.14
|
|
12
|
+
- @granite-js/jest@0.1.14
|
|
13
|
+
- @granite-js/lottie@0.1.14
|
|
14
|
+
- @granite-js/mpack@0.1.14
|
|
15
|
+
- @granite-js/native@0.1.14
|
|
16
|
+
- @granite-js/plugin-core@0.1.14
|
|
17
|
+
- @granite-js/style-utils@0.1.14
|
|
18
|
+
|
|
19
|
+
## 0.1.13
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 6838797: Make backEventState a singleton
|
|
24
|
+
- @granite-js/cli@0.1.13
|
|
25
|
+
- @granite-js/image@0.1.13
|
|
26
|
+
- @granite-js/jest@0.1.13
|
|
27
|
+
- @granite-js/lottie@0.1.13
|
|
28
|
+
- @granite-js/mpack@0.1.13
|
|
29
|
+
- @granite-js/native@0.1.13
|
|
30
|
+
- @granite-js/plugin-core@0.1.13
|
|
31
|
+
- @granite-js/style-utils@0.1.13
|
|
32
|
+
|
|
3
33
|
## 0.1.12
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from './keyboard';
|
|
|
11
11
|
export * from './intersection-observer';
|
|
12
12
|
export * from './impression-area';
|
|
13
13
|
export * from './scroll-view-inertial-background';
|
|
14
|
-
export * from './react';
|
|
15
14
|
export * from './router/createRoute';
|
|
16
15
|
export * from './event';
|
|
17
16
|
export * from './video';
|
|
@@ -32,9 +32,8 @@ interface PrivateBackEventControls extends BackEventControls {
|
|
|
32
32
|
* </BackEventProvider>
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
export declare function BackEventProvider({ children
|
|
35
|
+
export declare function BackEventProvider({ children }: {
|
|
36
36
|
children: ReactNode;
|
|
37
|
-
backEvent: PrivateBackEventControls;
|
|
38
37
|
}): import("react/jsx-runtime").JSX.Element;
|
|
39
38
|
/**
|
|
40
39
|
* @name useBackEventState
|
|
@@ -128,8 +127,5 @@ export declare function useBackEventState(): PrivateBackEventControls;
|
|
|
128
127
|
* ```
|
|
129
128
|
*/
|
|
130
129
|
export declare function useBackEvent(): BackEventControls;
|
|
131
|
-
export declare function useBackEventContext():
|
|
132
|
-
onGoBack: () => void;
|
|
133
|
-
hasBackEvent: boolean;
|
|
134
|
-
};
|
|
130
|
+
export declare function useBackEventContext(): PrivateBackEventControls;
|
|
135
131
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "The Granite Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"granite": "./bin/cli.js"
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@babel/core": "^7.24.9",
|
|
75
75
|
"@babel/preset-env": "^7.24.8",
|
|
76
76
|
"@babel/preset-typescript": "^7.24.7",
|
|
77
|
-
"@granite-js/native": "0.1.
|
|
77
|
+
"@granite-js/native": "0.1.14",
|
|
78
78
|
"@testing-library/dom": "^10.4.0",
|
|
79
79
|
"@testing-library/react": "^16.1.0",
|
|
80
80
|
"@types/babel__core": "^7",
|
|
@@ -100,13 +100,13 @@
|
|
|
100
100
|
"react-native": "*"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@granite-js/cli": "0.1.
|
|
104
|
-
"@granite-js/image": "0.1.
|
|
105
|
-
"@granite-js/jest": "0.1.
|
|
106
|
-
"@granite-js/lottie": "0.1.
|
|
107
|
-
"@granite-js/mpack": "0.1.
|
|
108
|
-
"@granite-js/plugin-core": "0.1.
|
|
109
|
-
"@granite-js/style-utils": "0.1.
|
|
103
|
+
"@granite-js/cli": "0.1.14",
|
|
104
|
+
"@granite-js/image": "0.1.14",
|
|
105
|
+
"@granite-js/jest": "0.1.14",
|
|
106
|
+
"@granite-js/lottie": "0.1.14",
|
|
107
|
+
"@granite-js/mpack": "0.1.14",
|
|
108
|
+
"@granite-js/plugin-core": "0.1.14",
|
|
109
|
+
"@granite-js/style-utils": "0.1.14",
|
|
110
110
|
"es-toolkit": "^1.39.8",
|
|
111
111
|
"react-native-url-polyfill": "1.3.0"
|
|
112
112
|
}
|
package/src/app/AppRoot.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { SafeAreaProvider } from '@granite-js/native/react-native-safe-area-cont
|
|
|
2
2
|
import type { ComponentType, PropsWithChildren } from 'react';
|
|
3
3
|
import type { InitialProps } from '../initial-props';
|
|
4
4
|
import { Router } from '../router';
|
|
5
|
-
import { BackEventProvider
|
|
5
|
+
import { BackEventProvider } from '../use-back-event';
|
|
6
6
|
import { App } from './App';
|
|
7
7
|
import type { GraniteProps } from './Granite';
|
|
8
8
|
import { getSchemePrefix } from '../utils/getSchemePrefix';
|
|
@@ -17,8 +17,6 @@ interface AppRootProps extends GraniteProps {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function AppRoot({ appName, context, container: Container, initialProps, initialScheme, router }: AppRootProps) {
|
|
20
|
-
const backEventState = useBackEventState();
|
|
21
|
-
|
|
22
20
|
const prefix = getSchemePrefix({
|
|
23
21
|
appName,
|
|
24
22
|
scheme: global.__granite.app.scheme,
|
|
@@ -28,7 +26,7 @@ export function AppRoot({ appName, context, container: Container, initialProps,
|
|
|
28
26
|
return (
|
|
29
27
|
<App {...initialProps}>
|
|
30
28
|
<SafeAreaProvider>
|
|
31
|
-
<BackEventProvider
|
|
29
|
+
<BackEventProvider>
|
|
32
30
|
<Router
|
|
33
31
|
context={context}
|
|
34
32
|
initialProps={initialProps}
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ export * from './keyboard';
|
|
|
13
13
|
export * from './intersection-observer';
|
|
14
14
|
export * from './impression-area';
|
|
15
15
|
export * from './scroll-view-inertial-background';
|
|
16
|
-
export * from './react';
|
|
17
16
|
export * from './router/createRoute';
|
|
18
17
|
export * from './event';
|
|
19
18
|
export * from './video';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NavigationContainerRefWithCurrent } from '@granite-js/native/@react-navigation/native';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useBackEventContext } from '../../use-back-event';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @public
|
|
@@ -63,7 +63,7 @@ export function useInternalRouterBackHandler({
|
|
|
63
63
|
navigationContainerRef: NavigationContainerRefWithCurrent<any>;
|
|
64
64
|
onClose?: () => void;
|
|
65
65
|
}) {
|
|
66
|
-
const {
|
|
66
|
+
const { hasBackEvent, onBack } = useBackEventContext();
|
|
67
67
|
const canGoBack = !hasBackEvent;
|
|
68
68
|
|
|
69
69
|
const handler = useCallback(() => {
|
|
@@ -72,6 +72,12 @@ export function getScreenPathMapConfig(routeScreens: RouteScreen[]) {
|
|
|
72
72
|
path: '',
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
const notFoundPage = routeScreens.find((screen) => screen.path === '/_404');
|
|
76
|
+
|
|
77
|
+
if (notFoundPage == null) {
|
|
78
|
+
throw new Error('404 page not found. Please create a `_404.ts` or `_404.tsx` file in the `pages/*` folder.');
|
|
79
|
+
}
|
|
80
|
+
|
|
75
81
|
// https://reactnavigation.org/docs/configuring-links/#handling-unmatched-routes-or-404
|
|
76
82
|
screensConfig['/_404'] = {
|
|
77
83
|
path: '*',
|
|
@@ -38,14 +38,10 @@ const BackEventContext = createContext<PrivateBackEventControls | null>(null);
|
|
|
38
38
|
* </BackEventProvider>
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export function BackEventProvider({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
children: ReactNode;
|
|
46
|
-
backEvent: PrivateBackEventControls;
|
|
47
|
-
}) {
|
|
48
|
-
return <BackEventContext.Provider value={backEvent}>{children}</BackEventContext.Provider>;
|
|
41
|
+
export function BackEventProvider({ children }: { children: ReactNode }) {
|
|
42
|
+
const backEventState = useBackEventState();
|
|
43
|
+
|
|
44
|
+
return <BackEventContext.Provider value={backEventState}>{children}</BackEventContext.Provider>;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
/**
|
|
@@ -253,8 +249,5 @@ export function useBackEventContext() {
|
|
|
253
249
|
throw new Error('useBackEvent must be used within a BackEventProvider');
|
|
254
250
|
}
|
|
255
251
|
|
|
256
|
-
return
|
|
257
|
-
onGoBack: context.onBack,
|
|
258
|
-
hasBackEvent: context.hasBackEvent,
|
|
259
|
-
};
|
|
252
|
+
return context;
|
|
260
253
|
}
|
package/dist/react/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useWaitForReturnNavigator } from './useWaitForReturnNavigator';
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @public
|
|
3
|
-
* @category Screen Control
|
|
4
|
-
* @name useWaitForReturnNavigator
|
|
5
|
-
* @description
|
|
6
|
-
* A Hook that helps execute the next code synchronously when returning from a screen transition.
|
|
7
|
-
* Screen navigation uses [@react-navigation/native `useNavigation`'s `navigate`](https://reactnavigation.org/docs/6.x/navigation-prop#navigate).
|
|
8
|
-
*
|
|
9
|
-
* For example, it can be used when you want to log that a user has navigated to another screen and returned.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ### Example of code execution when returning from screen navigation
|
|
13
|
-
*
|
|
14
|
-
* When the **"Navigate"** button is pressed, it navigates to another screen, and logs are created when returning.
|
|
15
|
-
*
|
|
16
|
-
* ```tsx
|
|
17
|
-
* import { Button } from 'react-native';
|
|
18
|
-
* import { useWaitForReturnNavigator } from '@granite-js/react-native';
|
|
19
|
-
*
|
|
20
|
-
* export function UseWaitForReturnNavigator() {
|
|
21
|
-
* const navigate = useWaitForReturnNavigator();
|
|
22
|
-
*
|
|
23
|
-
* return (
|
|
24
|
-
* <>
|
|
25
|
-
* <Button
|
|
26
|
-
* title="Navigate"
|
|
27
|
-
* onPress={async () => {
|
|
28
|
-
* console.log(1);
|
|
29
|
-
* await navigate('/examples/use-visibility');
|
|
30
|
-
* // This code executes when returning to the screen
|
|
31
|
-
* console.log(2);
|
|
32
|
-
* }}
|
|
33
|
-
* />
|
|
34
|
-
* </>
|
|
35
|
-
* );
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare function useWaitForReturnNavigator<T extends Record<string, object | undefined>>(): <RouteName extends keyof T>(route: RouteName, params?: T[RouteName]) => Promise<void>;
|
package/src/react/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useWaitForReturnNavigator } from './useWaitForReturnNavigator';
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { useNavigation } from '@granite-js/native/@react-navigation/native';
|
|
2
|
-
import { NativeStackNavigationProp } from '@granite-js/native/@react-navigation/native-stack';
|
|
3
|
-
import { useCallback, useRef } from 'react';
|
|
4
|
-
import { useVisibilityChange, type VisibilityState } from '../visibility';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
* @category Screen Control
|
|
9
|
-
* @name useWaitForReturnNavigator
|
|
10
|
-
* @description
|
|
11
|
-
* A Hook that helps execute the next code synchronously when returning from a screen transition.
|
|
12
|
-
* Screen navigation uses [@react-navigation/native `useNavigation`'s `navigate`](https://reactnavigation.org/docs/6.x/navigation-prop#navigate).
|
|
13
|
-
*
|
|
14
|
-
* For example, it can be used when you want to log that a user has navigated to another screen and returned.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ### Example of code execution when returning from screen navigation
|
|
18
|
-
*
|
|
19
|
-
* When the **"Navigate"** button is pressed, it navigates to another screen, and logs are created when returning.
|
|
20
|
-
*
|
|
21
|
-
* ```tsx
|
|
22
|
-
* import { Button } from 'react-native';
|
|
23
|
-
* import { useWaitForReturnNavigator } from '@granite-js/react-native';
|
|
24
|
-
*
|
|
25
|
-
* export function UseWaitForReturnNavigator() {
|
|
26
|
-
* const navigate = useWaitForReturnNavigator();
|
|
27
|
-
*
|
|
28
|
-
* return (
|
|
29
|
-
* <>
|
|
30
|
-
* <Button
|
|
31
|
-
* title="Navigate"
|
|
32
|
-
* onPress={async () => {
|
|
33
|
-
* console.log(1);
|
|
34
|
-
* await navigate('/examples/use-visibility');
|
|
35
|
-
* // This code executes when returning to the screen
|
|
36
|
-
* console.log(2);
|
|
37
|
-
* }}
|
|
38
|
-
* />
|
|
39
|
-
* </>
|
|
40
|
-
* );
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
export function useWaitForReturnNavigator<T extends Record<string, object | undefined>>() {
|
|
46
|
-
const callbacks = useRef<Array<() => void>>([]).current;
|
|
47
|
-
const navigation = useNavigation<NativeStackNavigationProp<T>>();
|
|
48
|
-
|
|
49
|
-
const startNavigating = useCallback(
|
|
50
|
-
<RouteName extends keyof T>(route: RouteName, params?: T[RouteName]): Promise<void> => {
|
|
51
|
-
return new Promise<void>((resolve) => {
|
|
52
|
-
callbacks.push(resolve);
|
|
53
|
-
navigation.navigate(route as any, params as any);
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
[callbacks, navigation]
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const handleVisibilityChange = useCallback(
|
|
60
|
-
(state: VisibilityState) => {
|
|
61
|
-
if (state === 'visible' && callbacks.length > 0) {
|
|
62
|
-
for (const callback of callbacks) {
|
|
63
|
-
callback();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
callbacks.splice(0, callbacks.length);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
[callbacks]
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
useVisibilityChange(handleVisibilityChange);
|
|
73
|
-
|
|
74
|
-
return startNavigating;
|
|
75
|
-
}
|