@granite-js/react-native 0.1.23-next.10 → 0.1.23-next.11

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,20 @@
1
1
  # @granite-js/react-native
2
2
 
3
+ ## 0.1.23-next.11
4
+
5
+ ### Patch Changes
6
+
7
+ - fix
8
+ - Updated dependencies
9
+ - @granite-js/plugin-core@0.1.23-next.11
10
+ - @granite-js/style-utils@0.1.23-next.11
11
+ - @granite-js/lottie@0.1.23-next.11
12
+ - @granite-js/native@0.1.23-next.11
13
+ - @granite-js/image@0.1.23-next.11
14
+ - @granite-js/mpack@0.1.23-next.11
15
+ - @granite-js/jest@0.1.23-next.11
16
+ - @granite-js/cli@0.1.23-next.11
17
+
3
18
  ## 0.1.23-next.10
4
19
 
5
20
  ### Patch Changes
@@ -1 +1 @@
1
- export declare function AppRoot({ appName, context, container: Container, initialProps, initialScheme, router, setIosSwipeGestureEnabled, }: AppRootProps): import("react/jsx-runtime").JSX.Element;
1
+ export declare function AppRoot({ appName, context, container: Container, initialProps, initialScheme, router, setIosSwipeGestureEnabled, getInitialUrl, }: AppRootProps): import("react/jsx-runtime").JSX.Element;
@@ -31,6 +31,13 @@ export interface GraniteProps {
31
31
  setIosSwipeGestureEnabled?: ({ isEnabled }: {
32
32
  isEnabled: boolean;
33
33
  }) => void;
34
+ /**
35
+ * @description
36
+ * The function to provide the initial URL to router.
37
+ * @param initialScheme The initial scheme of the app.
38
+ * @returns
39
+ */
40
+ getInitialUrl?: (initialScheme: string) => string | undefined | Promise<string | undefined>;
34
41
  }
35
42
  /**
36
43
  * @public
@@ -67,7 +74,7 @@ export interface GraniteProps {
67
74
  * ```
68
75
  */
69
76
  export declare const Granite: {
70
- registerApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName, context, router, initialScheme, setIosSwipeGestureEnabled }: GraniteProps): (initialProps: InitialProps) => JSX.Element;
77
+ registerApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName, context, router, initialScheme, setIosSwipeGestureEnabled, getInitialUrl }: GraniteProps): (initialProps: InitialProps) => JSX.Element;
71
78
  registerHostApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName }: Pick<GraniteProps, "appName">): (initialProps: InitialProps) => React.JSX.Element;
72
79
  readonly appName: string;
73
80
  };
@@ -55,5 +55,5 @@ type NavigationContainerProps = Pick<ComponentProps<typeof NavigationContainer>,
55
55
  * }
56
56
  * ```
57
57
  */
58
- export declare function Router({ prefix, context, container: Container, initialProps, initialScheme, navigationContainerRef, defaultScreenOption, screenContainer, setIosSwipeGestureEnabled, ...navigationContainerProps }: InternalRouterProps & RouterProps): ReactElement;
58
+ export declare function Router({ prefix, context, container: Container, initialProps, initialScheme, navigationContainerRef, defaultScreenOption, screenContainer, setIosSwipeGestureEnabled, getInitialUrl, ...navigationContainerProps }: InternalRouterProps & RouterProps): ReactElement;
59
59
  export {};
@@ -4,9 +4,10 @@ export interface RouterControlsConfig {
4
4
  prefix: string;
5
5
  initialScheme: string;
6
6
  context: RequireContext;
7
+ getInitialUrl?: (initialScheme: string) => string | undefined | Promise<string | undefined>;
7
8
  screenContainer?: ComponentType<PropsWithChildren<any>>;
8
9
  }
9
- export declare function useRouterControls({ prefix, context, screenContainer: ScreenContainer, initialScheme, }: RouterControlsConfig): {
10
+ export declare function useRouterControls({ prefix, context, screenContainer: ScreenContainer, getInitialUrl, initialScheme, }: RouterControlsConfig): {
10
11
  Screens: import("react/jsx-runtime").JSX.Element[];
11
12
  linkingOptions: import("@react-navigation/native").LinkingOptions<{}>;
12
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granite-js/react-native",
3
- "version": "0.1.23-next.10",
3
+ "version": "0.1.23-next.11",
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.10",
89
+ "@granite-js/native": "0.1.23-next.11",
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.10",
108
+ "@granite-js/native": "0.1.23-next.11",
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.10",
116
- "@granite-js/image": "0.1.23-next.10",
117
- "@granite-js/jest": "0.1.23-next.10",
118
- "@granite-js/lottie": "0.1.23-next.10",
119
- "@granite-js/mpack": "0.1.23-next.10",
120
- "@granite-js/plugin-core": "0.1.23-next.10",
121
- "@granite-js/style-utils": "0.1.23-next.10",
115
+ "@granite-js/cli": "0.1.23-next.11",
116
+ "@granite-js/image": "0.1.23-next.11",
117
+ "@granite-js/jest": "0.1.23-next.11",
118
+ "@granite-js/lottie": "0.1.23-next.11",
119
+ "@granite-js/mpack": "0.1.23-next.11",
120
+ "@granite-js/plugin-core": "0.1.23-next.11",
121
+ "@granite-js/style-utils": "0.1.23-next.11",
122
122
  "es-toolkit": "^1.39.8",
123
123
  "react-native-url-polyfill": "1.3.0"
124
124
  }
@@ -1,7 +1,7 @@
1
1
  import { SafeAreaProvider } from '@granite-js/native/react-native-safe-area-context';
2
2
  import type { ComponentType, PropsWithChildren } from 'react';
3
3
  import type { InitialProps } from '../initial-props';
4
- import { Router } from '../router';
4
+ import { Router, type InternalRouterProps } from '../router';
5
5
  import { BackEventProvider } from '../use-back-event';
6
6
  import { App } from './App';
7
7
  import type { GraniteProps } from './Granite';
@@ -16,6 +16,7 @@ interface AppRootProps extends GraniteProps {
16
16
  initialProps: InitialProps;
17
17
  initialScheme: string;
18
18
  setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
19
+ getInitialUrl: InternalRouterProps['getInitialUrl'];
19
20
  }
20
21
 
21
22
  export function AppRoot({
@@ -26,6 +27,7 @@ export function AppRoot({
26
27
  initialScheme,
27
28
  router,
28
29
  setIosSwipeGestureEnabled,
30
+ getInitialUrl,
29
31
  }: AppRootProps) {
30
32
  const prefix = getSchemePrefix({
31
33
  appName,
@@ -45,6 +47,7 @@ export function AppRoot({
45
47
  container={Container}
46
48
  prefix={prefix}
47
49
  setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
50
+ getInitialUrl={getInitialUrl}
48
51
  {...router}
49
52
  />
50
53
  </BackEventProvider>
@@ -37,6 +37,14 @@ export interface GraniteProps {
37
37
  * The function to set the iOS swipe gesture enabled.
38
38
  */
39
39
  setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
40
+
41
+ /**
42
+ * @description
43
+ * The function to provide the initial URL to router.
44
+ * @param initialScheme The initial scheme of the app.
45
+ * @returns
46
+ */
47
+ getInitialUrl?: (initialScheme: string) => string | undefined | Promise<string | undefined>;
40
48
  }
41
49
 
42
50
  const createApp = () => {
@@ -54,7 +62,7 @@ const createApp = () => {
54
62
  return {
55
63
  registerApp(
56
64
  AppContainer: ComponentType<PropsWithChildren<InitialProps>>,
57
- { appName, context, router, initialScheme, setIosSwipeGestureEnabled }: GraniteProps
65
+ { appName, context, router, initialScheme, setIosSwipeGestureEnabled, getInitialUrl }: GraniteProps
58
66
  ): (initialProps: InitialProps) => JSX.Element {
59
67
  if (appName === ENTRY_BUNDLE_NAME) {
60
68
  throw new Error(`Reserved app name 'shared' cannot be used`);
@@ -67,6 +75,7 @@ const createApp = () => {
67
75
  initialProps={initialProps}
68
76
  initialScheme={initialScheme ?? getSchemeUri()}
69
77
  setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
78
+ getInitialUrl={getInitialUrl}
70
79
  appName={appName}
71
80
  context={context}
72
81
  router={router}
@@ -24,7 +24,7 @@ import { CanGoBackGuard } from './components/CanGoBackGuard';
24
24
  import { StackNavigator } from './components/StackNavigator';
25
25
  import { useInternalRouterBackHandler } from './components/useRouterBackHandler';
26
26
  import { useInitialRouteName } from './hooks/useInitialRouteName';
27
- import { useRouterControls } from './hooks/useRouterControls';
27
+ import { useRouterControls, type RouterControlsConfig } from './hooks/useRouterControls';
28
28
  import { RequireContext } from './types';
29
29
  import { BASE_STACK_NAVIGATOR_STYLE } from './types/screen-option';
30
30
 
@@ -66,6 +66,7 @@ export interface InternalRouterProps {
66
66
  initialProps: InitialProps;
67
67
  initialScheme: string;
68
68
  setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => Promise<void> | void;
69
+ getInitialUrl?: RouterControlsConfig['getInitialUrl'];
69
70
  }
70
71
 
71
72
  export type RouterProps = StackNavigatorProps & NavigationContainerProps;
@@ -140,6 +141,7 @@ export function Router({
140
141
  screenContainer,
141
142
  // Public props (StackNavigator)
142
143
  setIosSwipeGestureEnabled,
144
+ getInitialUrl,
143
145
  ...navigationContainerProps
144
146
  }: InternalRouterProps & RouterProps): ReactElement {
145
147
  const initialRouteName = useInitialRouteName({ prefix, initialScheme });
@@ -148,6 +150,7 @@ export function Router({
148
150
  context,
149
151
  screenContainer,
150
152
  initialScheme,
153
+ getInitialUrl,
151
154
  });
152
155
 
153
156
  const ref = useMemo(() => navigationContainerRef ?? createNavigationContainerRef<never>(), [navigationContainerRef]);
@@ -14,6 +14,7 @@ export interface RouterControlsConfig {
14
14
  prefix: string;
15
15
  initialScheme: string;
16
16
  context: RequireContext;
17
+ getInitialUrl?: (initialScheme: string) => string | undefined | Promise<string | undefined>;
17
18
  screenContainer?: ComponentType<PropsWithChildren<any>>;
18
19
  }
19
20
 
@@ -21,6 +22,7 @@ export function useRouterControls({
21
22
  prefix,
22
23
  context,
23
24
  screenContainer: ScreenContainer,
25
+ getInitialUrl = defaultGetInitialUrl,
24
26
  initialScheme,
25
27
  }: RouterControlsConfig) {
26
28
  const routeScreens = useMemo(() => getRouteScreens(context), [context]);
@@ -61,15 +63,19 @@ export function useRouterControls({
61
63
  screens: getScreenPathMapConfig(registerScreens),
62
64
  },
63
65
  async getInitialURL() {
64
- if (initialScheme == null) {
65
- return;
66
- }
67
-
68
- /** @NOTE Korean paths need to be decoded. */
69
- return decodeURI(initialScheme);
66
+ return (getInitialUrl ?? defaultGetInitialUrl)(initialScheme);
70
67
  },
71
68
  };
72
- }, [initialScheme, prefix, registerScreens]);
69
+ }, [initialScheme, prefix, registerScreens, getInitialUrl]);
73
70
 
74
71
  return { Screens, linkingOptions };
75
72
  }
73
+
74
+ function defaultGetInitialUrl(initialScheme: string) {
75
+ if (initialScheme == null) {
76
+ return;
77
+ }
78
+
79
+ /** @NOTE Korean paths need to be decoded. */
80
+ return decodeURI(initialScheme);
81
+ }