@granite-js/react-native 0.1.23-next.7 → 0.1.23-next.9
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/router/Router.d.ts +2 -3
- package/dist/router/components/CanGoBackGuard.d.ts +1 -2
- package/dist/router/components/useRouterBackHandler.d.ts +1 -1
- package/package.json +10 -10
- package/src/router/Router.tsx +8 -22
- package/src/router/components/CanGoBackGuard.tsx +3 -2
- package/src/router/components/useRouterBackHandler.tsx +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 0.1.23-next.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- tollback
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @granite-js/plugin-core@0.1.23-next.9
|
|
10
|
+
- @granite-js/style-utils@0.1.23-next.9
|
|
11
|
+
- @granite-js/lottie@0.1.23-next.9
|
|
12
|
+
- @granite-js/native@0.1.23-next.9
|
|
13
|
+
- @granite-js/image@0.1.23-next.9
|
|
14
|
+
- @granite-js/mpack@0.1.23-next.9
|
|
15
|
+
- @granite-js/jest@0.1.23-next.9
|
|
16
|
+
- @granite-js/cli@0.1.23-next.9
|
|
17
|
+
|
|
18
|
+
## 0.1.23-next.8
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- router
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @granite-js/plugin-core@0.1.23-next.8
|
|
25
|
+
- @granite-js/style-utils@0.1.23-next.8
|
|
26
|
+
- @granite-js/lottie@0.1.23-next.8
|
|
27
|
+
- @granite-js/native@0.1.23-next.8
|
|
28
|
+
- @granite-js/image@0.1.23-next.8
|
|
29
|
+
- @granite-js/mpack@0.1.23-next.8
|
|
30
|
+
- @granite-js/jest@0.1.23-next.8
|
|
31
|
+
- @granite-js/cli@0.1.23-next.8
|
|
32
|
+
|
|
3
33
|
## 0.1.23-next.7
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/router/Router.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ interface StackNavigatorProps {
|
|
|
8
8
|
* @description
|
|
9
9
|
* You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
|
|
10
10
|
*/
|
|
11
|
-
navigationContainerRef?: NavigationContainerRefWithCurrent<
|
|
11
|
+
navigationContainerRef?: NavigationContainerRefWithCurrent<never>;
|
|
12
12
|
/**
|
|
13
13
|
* @name defaultScreenOption
|
|
14
14
|
* @description
|
|
@@ -26,7 +26,6 @@ interface StackNavigatorProps {
|
|
|
26
26
|
screenContainer?: ComponentType<PropsWithChildren<any>>;
|
|
27
27
|
}
|
|
28
28
|
type NavigationContainerProps = Pick<ComponentProps<typeof NavigationContainer>, 'ref' | 'documentTitle' | 'fallback' | 'onReady' | 'onUnhandledAction' | 'onStateChange'>;
|
|
29
|
-
export declare const navigationRef: NavigationContainerRefWithCurrent<never>;
|
|
30
29
|
/**
|
|
31
30
|
* @category Components
|
|
32
31
|
* @kind function
|
|
@@ -38,7 +37,7 @@ export declare const navigationRef: NavigationContainerRefWithCurrent<never>;
|
|
|
38
37
|
*
|
|
39
38
|
* @param {string} prefix Prefix to use when the scheme is executed. For example, to enter 'scheme://my-service/intro', you need to set 'scheme://my-service' as the prefix.
|
|
40
39
|
* @param {RequireContext} context Object containing information about screens for file-based routing.
|
|
41
|
-
* @param {NavigationContainerRefWithCurrent<
|
|
40
|
+
* @param {NavigationContainerRefWithCurrent<never>} [navigationContainerRef] You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
|
|
42
41
|
* @param {NativeStackNavigationOptions | ((props: { route: RouteProp<ParamListBase>; navigation: any }) => NativeStackNavigationOptions)} [defaultScreenOption] Default options for screens. You can set options to be applied commonly to screens, such as title or headerStyle.
|
|
43
42
|
* @param {boolean} [canGoBack=true] Whether navigation back is possible. Default is true, and when set to true, you can use the back gesture or back button from @react-navigation/native.
|
|
44
43
|
* @param {() => void} [onBack] Callback function called when the user presses the back button or uses the back gesture. For example, you can set it to log when the user presses the back button.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
export declare function CanGoBackGuard({ children, canGoBack, onBack,
|
|
2
|
+
export declare function CanGoBackGuard({ children, canGoBack, onBack, setIosSwipeGestureEnabled, }: {
|
|
3
3
|
canGoBack: boolean;
|
|
4
|
-
isInitialScreen: boolean;
|
|
5
4
|
children: ReactNode;
|
|
6
5
|
onBack?: () => void;
|
|
7
6
|
setIosSwipeGestureEnabled?: ({ isEnabled }: {
|
|
@@ -6,7 +6,7 @@ import { NavigationContainerRefWithCurrent } from '@granite-js/native/@react-nav
|
|
|
6
6
|
* @description
|
|
7
7
|
* A hook that provides a handler for handling back navigation actions. This can be used when you need to close a view directly when the back button is pressed in modals or independent screens where there's no navigation stack. This hook uses `NavigationContainerRef` from `@react-navigation/native` to navigate to the previous screen if there's a remaining navigation stack, or executes the user-defined `onClose` function if the stack is empty.
|
|
8
8
|
*
|
|
9
|
-
* @param {NavigationContainerRefWithCurrent<
|
|
9
|
+
* @param {NavigationContainerRefWithCurrent<never>} navigationContainerRef - A `NavigationContainerRef` that can reference the current navigation state. Used when executing back navigation actions.
|
|
10
10
|
* @param {() => void} [onClose] - A function to execute when the navigation stack is empty. For example, you can pass a function that closes a React Native View.
|
|
11
11
|
*
|
|
12
12
|
* @returns {{ handler: () => void }} A handler function that can be used in back buttons or similar components.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/react-native",
|
|
3
|
-
"version": "0.1.23-next.
|
|
3
|
+
"version": "0.1.23-next.9",
|
|
4
4
|
"description": "The Granite Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"granite": "./bin/cli.js"
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"@babel/core": "^7.24.9",
|
|
87
87
|
"@babel/preset-env": "^7.24.8",
|
|
88
88
|
"@babel/preset-typescript": "^7.24.7",
|
|
89
|
-
"@granite-js/native": "0.1.23-next.
|
|
89
|
+
"@granite-js/native": "0.1.23-next.9",
|
|
90
90
|
"@testing-library/dom": "^10.4.0",
|
|
91
91
|
"@testing-library/react": "^16.1.0",
|
|
92
92
|
"@types/babel__core": "^7",
|
|
@@ -105,20 +105,20 @@
|
|
|
105
105
|
"vitest": "^2.1.8"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@granite-js/native": "0.1.23-next.
|
|
108
|
+
"@granite-js/native": "0.1.23-next.9",
|
|
109
109
|
"@types/react": "*",
|
|
110
110
|
"brick-module": "*",
|
|
111
111
|
"react": "*",
|
|
112
112
|
"react-native": "*"
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@granite-js/cli": "0.1.23-next.
|
|
116
|
-
"@granite-js/image": "0.1.23-next.
|
|
117
|
-
"@granite-js/jest": "0.1.23-next.
|
|
118
|
-
"@granite-js/lottie": "0.1.23-next.
|
|
119
|
-
"@granite-js/mpack": "0.1.23-next.
|
|
120
|
-
"@granite-js/plugin-core": "0.1.23-next.
|
|
121
|
-
"@granite-js/style-utils": "0.1.23-next.
|
|
115
|
+
"@granite-js/cli": "0.1.23-next.9",
|
|
116
|
+
"@granite-js/image": "0.1.23-next.9",
|
|
117
|
+
"@granite-js/jest": "0.1.23-next.9",
|
|
118
|
+
"@granite-js/lottie": "0.1.23-next.9",
|
|
119
|
+
"@granite-js/mpack": "0.1.23-next.9",
|
|
120
|
+
"@granite-js/plugin-core": "0.1.23-next.9",
|
|
121
|
+
"@granite-js/style-utils": "0.1.23-next.9",
|
|
122
122
|
"es-toolkit": "^1.39.8",
|
|
123
123
|
"react-native-url-polyfill": "1.3.0"
|
|
124
124
|
}
|
package/src/router/Router.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
RouteProp,
|
|
8
8
|
} from '@granite-js/native/@react-navigation/native';
|
|
9
9
|
import { NativeStackNavigationOptions } from '@granite-js/native/@react-navigation/native-stack';
|
|
10
|
-
import { ComponentProps, ComponentType, Fragment, PropsWithChildren, ReactElement, useCallback,
|
|
10
|
+
import { ComponentProps, ComponentType, Fragment, PropsWithChildren, ReactElement, useCallback, useMemo } from 'react';
|
|
11
11
|
import { InitialProps } from '..';
|
|
12
12
|
import { closeView } from '../native-modules';
|
|
13
13
|
import { BackButton } from './components/BackButton';
|
|
@@ -67,7 +67,7 @@ interface StackNavigatorProps {
|
|
|
67
67
|
* @description
|
|
68
68
|
* You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
|
|
69
69
|
*/
|
|
70
|
-
navigationContainerRef?: NavigationContainerRefWithCurrent<
|
|
70
|
+
navigationContainerRef?: NavigationContainerRefWithCurrent<never>;
|
|
71
71
|
/**
|
|
72
72
|
* @name defaultScreenOption
|
|
73
73
|
* @description
|
|
@@ -89,8 +89,6 @@ type NavigationContainerProps = Pick<
|
|
|
89
89
|
'ref' | 'documentTitle' | 'fallback' | 'onReady' | 'onUnhandledAction' | 'onStateChange'
|
|
90
90
|
>;
|
|
91
91
|
|
|
92
|
-
export const navigationRef = createNavigationContainerRef<never>();
|
|
93
|
-
|
|
94
92
|
/**
|
|
95
93
|
* @category Components
|
|
96
94
|
* @kind function
|
|
@@ -102,7 +100,7 @@ export const navigationRef = createNavigationContainerRef<never>();
|
|
|
102
100
|
*
|
|
103
101
|
* @param {string} prefix Prefix to use when the scheme is executed. For example, to enter 'scheme://my-service/intro', you need to set 'scheme://my-service' as the prefix.
|
|
104
102
|
* @param {RequireContext} context Object containing information about screens for file-based routing.
|
|
105
|
-
* @param {NavigationContainerRefWithCurrent<
|
|
103
|
+
* @param {NavigationContainerRefWithCurrent<never>} [navigationContainerRef] You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
|
|
106
104
|
* @param {NativeStackNavigationOptions | ((props: { route: RouteProp<ParamListBase>; navigation: any }) => NativeStackNavigationOptions)} [defaultScreenOption] Default options for screens. You can set options to be applied commonly to screens, such as title or headerStyle.
|
|
107
105
|
* @param {boolean} [canGoBack=true] Whether navigation back is possible. Default is true, and when set to true, you can use the back gesture or back button from @react-navigation/native.
|
|
108
106
|
* @param {() => void} [onBack] Callback function called when the user presses the back button or uses the back gesture. For example, you can set it to log when the user presses the back button.
|
|
@@ -143,8 +141,10 @@ export function Router({
|
|
|
143
141
|
initialScheme,
|
|
144
142
|
});
|
|
145
143
|
|
|
144
|
+
const ref = useMemo(() => navigationContainerRef ?? createNavigationContainerRef<never>(), [navigationContainerRef]);
|
|
145
|
+
|
|
146
146
|
const { handler, canGoBack, onBack } = useInternalRouterBackHandler({
|
|
147
|
-
navigationContainerRef:
|
|
147
|
+
navigationContainerRef: ref,
|
|
148
148
|
onClose: closeView,
|
|
149
149
|
});
|
|
150
150
|
|
|
@@ -163,23 +163,9 @@ export function Router({
|
|
|
163
163
|
[canGoBack, defaultScreenOption, headerLeft]
|
|
164
164
|
);
|
|
165
165
|
|
|
166
|
-
const [isInitialScreen, setIsInitialScreen] = useState(true);
|
|
167
|
-
|
|
168
166
|
return (
|
|
169
|
-
<NavigationContainer
|
|
170
|
-
|
|
171
|
-
setIsInitialScreen(state ? state?.index === 0 : true);
|
|
172
|
-
}}
|
|
173
|
-
ref={navigationRef}
|
|
174
|
-
{...navigationContainerProps}
|
|
175
|
-
linking={linkingOptions}
|
|
176
|
-
>
|
|
177
|
-
<CanGoBackGuard
|
|
178
|
-
canGoBack={canGoBack}
|
|
179
|
-
isInitialScreen={isInitialScreen}
|
|
180
|
-
onBack={onBack}
|
|
181
|
-
setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
|
|
182
|
-
>
|
|
167
|
+
<NavigationContainer ref={ref} {...navigationContainerProps} linking={linkingOptions}>
|
|
168
|
+
<CanGoBackGuard canGoBack={canGoBack} onBack={onBack} setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}>
|
|
183
169
|
<Container {...initialProps}>
|
|
184
170
|
<StackNavigator.Navigator initialRouteName={initialRouteName} screenOptions={screenOptions}>
|
|
185
171
|
{Screens}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ReactNode, useEffect } from 'react';
|
|
2
2
|
import { BackHandler } from 'react-native';
|
|
3
|
+
import { useIsInitialScreen } from '../hooks/useIsInitialScreen';
|
|
3
4
|
|
|
4
5
|
export function CanGoBackGuard({
|
|
5
6
|
children,
|
|
6
7
|
canGoBack,
|
|
7
8
|
onBack,
|
|
8
|
-
isInitialScreen,
|
|
9
9
|
setIosSwipeGestureEnabled,
|
|
10
10
|
}: {
|
|
11
11
|
canGoBack: boolean;
|
|
12
|
-
isInitialScreen: boolean;
|
|
13
12
|
children: ReactNode;
|
|
14
13
|
onBack?: () => void;
|
|
15
14
|
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
|
|
16
15
|
}) {
|
|
16
|
+
const isInitialScreen = useIsInitialScreen();
|
|
17
|
+
|
|
17
18
|
const shouldBlockGoingBack = !canGoBack;
|
|
18
19
|
|
|
19
20
|
useEffect(() => {
|
|
@@ -9,7 +9,7 @@ import { useBackEventContext } from '../../use-back-event';
|
|
|
9
9
|
* @description
|
|
10
10
|
* A hook that provides a handler for handling back navigation actions. This can be used when you need to close a view directly when the back button is pressed in modals or independent screens where there's no navigation stack. This hook uses `NavigationContainerRef` from `@react-navigation/native` to navigate to the previous screen if there's a remaining navigation stack, or executes the user-defined `onClose` function if the stack is empty.
|
|
11
11
|
*
|
|
12
|
-
* @param {NavigationContainerRefWithCurrent<
|
|
12
|
+
* @param {NavigationContainerRefWithCurrent<never>} navigationContainerRef - A `NavigationContainerRef` that can reference the current navigation state. Used when executing back navigation actions.
|
|
13
13
|
* @param {() => void} [onClose] - A function to execute when the navigation stack is empty. For example, you can pass a function that closes a React Native View.
|
|
14
14
|
*
|
|
15
15
|
* @returns {{ handler: () => void }} A handler function that can be used in back buttons or similar components.
|