@granite-js/react-native 0.1.23-next.6 → 0.1.23-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @granite-js/react-native
2
2
 
3
+ ## 0.1.23-next.8
4
+
5
+ ### Patch Changes
6
+
7
+ - router
8
+ - Updated dependencies
9
+ - @granite-js/plugin-core@0.1.23-next.8
10
+ - @granite-js/style-utils@0.1.23-next.8
11
+ - @granite-js/lottie@0.1.23-next.8
12
+ - @granite-js/native@0.1.23-next.8
13
+ - @granite-js/image@0.1.23-next.8
14
+ - @granite-js/mpack@0.1.23-next.8
15
+ - @granite-js/jest@0.1.23-next.8
16
+ - @granite-js/cli@0.1.23-next.8
17
+
18
+ ## 0.1.23-next.7
19
+
20
+ ### Patch Changes
21
+
22
+ - fix
23
+ - Updated dependencies
24
+ - @granite-js/plugin-core@0.1.23-next.7
25
+ - @granite-js/style-utils@0.1.23-next.7
26
+ - @granite-js/lottie@0.1.23-next.7
27
+ - @granite-js/native@0.1.23-next.7
28
+ - @granite-js/image@0.1.23-next.7
29
+ - @granite-js/mpack@0.1.23-next.7
30
+ - @granite-js/jest@0.1.23-next.7
31
+ - @granite-js/cli@0.1.23-next.7
32
+
3
33
  ## 0.1.23-next.6
4
34
 
5
35
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  import { BrickModuleSpec } from 'brick-module';
2
2
  interface GraniteModuleSpec extends BrickModuleSpec {
3
3
  readonly moduleName: 'GraniteModule';
4
- closeView(): void;
4
+ closeView(): Promise<void>;
5
5
  schemeUri: string;
6
6
  }
7
7
  export declare const GraniteModule: GraniteModuleSpec & {
@@ -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<any>;
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<any>} [navigationContainerRef] You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
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,6 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
- export declare function CanGoBackGuard({ children, canGoBack, onBack, setIosSwipeGestureEnabled, }: {
2
+ export declare function CanGoBackGuard({ children, canGoBack, onBack, isInitialScreen, setIosSwipeGestureEnabled, }: {
3
3
  canGoBack: boolean;
4
+ isInitialScreen: boolean;
4
5
  children: ReactNode;
5
6
  onBack?: () => void;
6
7
  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<any>} navigationContainerRef - A `NavigationContainerRef` that can reference the current navigation state. Used when executing back navigation actions.
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.6",
3
+ "version": "0.1.23-next.8",
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.6",
89
+ "@granite-js/native": "0.1.23-next.8",
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.6",
108
+ "@granite-js/native": "0.1.23-next.8",
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.6",
116
- "@granite-js/image": "0.1.23-next.6",
117
- "@granite-js/jest": "0.1.23-next.6",
118
- "@granite-js/lottie": "0.1.23-next.6",
119
- "@granite-js/mpack": "0.1.23-next.6",
120
- "@granite-js/plugin-core": "0.1.23-next.6",
121
- "@granite-js/style-utils": "0.1.23-next.6",
115
+ "@granite-js/cli": "0.1.23-next.8",
116
+ "@granite-js/image": "0.1.23-next.8",
117
+ "@granite-js/jest": "0.1.23-next.8",
118
+ "@granite-js/lottie": "0.1.23-next.8",
119
+ "@granite-js/mpack": "0.1.23-next.8",
120
+ "@granite-js/plugin-core": "0.1.23-next.8",
121
+ "@granite-js/style-utils": "0.1.23-next.8",
122
122
  "es-toolkit": "^1.39.8",
123
123
  "react-native-url-polyfill": "1.3.0"
124
124
  }
@@ -3,7 +3,7 @@ import { BrickModule, BrickModuleSpec } from 'brick-module';
3
3
  interface GraniteModuleSpec extends BrickModuleSpec {
4
4
  readonly moduleName: 'GraniteModule';
5
5
 
6
- closeView(): void;
6
+ closeView(): Promise<void>;
7
7
  schemeUri: string;
8
8
  }
9
9
 
@@ -7,7 +7,16 @@ 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 } from 'react';
10
+ import {
11
+ ComponentProps,
12
+ ComponentType,
13
+ Fragment,
14
+ PropsWithChildren,
15
+ ReactElement,
16
+ useCallback,
17
+ useMemo,
18
+ useState,
19
+ } from 'react';
11
20
  import { InitialProps } from '..';
12
21
  import { closeView } from '../native-modules';
13
22
  import { BackButton } from './components/BackButton';
@@ -67,7 +76,7 @@ interface StackNavigatorProps {
67
76
  * @description
68
77
  * You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
69
78
  */
70
- navigationContainerRef?: NavigationContainerRefWithCurrent<any>;
79
+ navigationContainerRef?: NavigationContainerRefWithCurrent<never>;
71
80
  /**
72
81
  * @name defaultScreenOption
73
82
  * @description
@@ -89,8 +98,6 @@ type NavigationContainerProps = Pick<
89
98
  'ref' | 'documentTitle' | 'fallback' | 'onReady' | 'onUnhandledAction' | 'onStateChange'
90
99
  >;
91
100
 
92
- export const navigationRef = createNavigationContainerRef<never>();
93
-
94
101
  /**
95
102
  * @category Components
96
103
  * @kind function
@@ -102,7 +109,7 @@ export const navigationRef = createNavigationContainerRef<never>();
102
109
  *
103
110
  * @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
111
  * @param {RequireContext} context Object containing information about screens for file-based routing.
105
- * @param {NavigationContainerRefWithCurrent<any>} [navigationContainerRef] You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
112
+ * @param {NavigationContainerRefWithCurrent<never>} [navigationContainerRef] You can create and pass a NavigationContainerRef from @react-navigation/native externally. This allows external control of the router.
106
113
  * @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
114
  * @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
115
  * @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 +150,10 @@ export function Router({
143
150
  initialScheme,
144
151
  });
145
152
 
153
+ const ref = useMemo(() => navigationContainerRef ?? createNavigationContainerRef<never>(), [navigationContainerRef]);
154
+
146
155
  const { handler, canGoBack, onBack } = useInternalRouterBackHandler({
147
- navigationContainerRef: navigationRef,
156
+ navigationContainerRef: ref,
148
157
  onClose: closeView,
149
158
  });
150
159
 
@@ -163,9 +172,23 @@ export function Router({
163
172
  [canGoBack, defaultScreenOption, headerLeft]
164
173
  );
165
174
 
175
+ const [isInitialScreen, setIsInitialScreen] = useState(true);
176
+
166
177
  return (
167
- <NavigationContainer ref={navigationRef} {...navigationContainerProps} linking={linkingOptions}>
168
- <CanGoBackGuard canGoBack={canGoBack} onBack={onBack} setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}>
178
+ <NavigationContainer
179
+ onStateChange={(state) => {
180
+ setIsInitialScreen(state ? state?.index === 0 : true);
181
+ }}
182
+ ref={ref}
183
+ {...navigationContainerProps}
184
+ linking={linkingOptions}
185
+ >
186
+ <CanGoBackGuard
187
+ canGoBack={canGoBack}
188
+ isInitialScreen={isInitialScreen}
189
+ onBack={onBack}
190
+ setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
191
+ >
169
192
  <Container {...initialProps}>
170
193
  <StackNavigator.Navigator initialRouteName={initialRouteName} screenOptions={screenOptions}>
171
194
  {Screens}
@@ -1,20 +1,19 @@
1
1
  import { ReactNode, useEffect } from 'react';
2
2
  import { BackHandler } from 'react-native';
3
- import { useIsInitialScreen } from '../hooks/useIsInitialScreen';
4
3
 
5
4
  export function CanGoBackGuard({
6
5
  children,
7
6
  canGoBack,
8
7
  onBack,
8
+ isInitialScreen,
9
9
  setIosSwipeGestureEnabled,
10
10
  }: {
11
11
  canGoBack: boolean;
12
+ isInitialScreen: boolean;
12
13
  children: ReactNode;
13
14
  onBack?: () => void;
14
15
  setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
15
16
  }) {
16
- const isInitialScreen = useIsInitialScreen();
17
-
18
17
  const shouldBlockGoingBack = !canGoBack;
19
18
 
20
19
  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<any>} navigationContainerRef - A `NavigationContainerRef` that can reference the current navigation state. Used when executing back navigation actions.
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.