@granite-js/react-native 0.1.23 → 0.1.25

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,33 @@
1
1
  # @granite-js/react-native
2
2
 
3
+ ## 0.1.25
4
+
5
+ ### Patch Changes
6
+
7
+ - 6717901: add getInitialUrl option
8
+ - @granite-js/cli@0.1.25
9
+ - @granite-js/image@0.1.25
10
+ - @granite-js/jest@0.1.25
11
+ - @granite-js/lottie@0.1.25
12
+ - @granite-js/mpack@0.1.25
13
+ - @granite-js/native@0.1.25
14
+ - @granite-js/plugin-core@0.1.25
15
+ - @granite-js/style-utils@0.1.25
16
+
17
+ ## 0.1.24
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [6e42c3d]
22
+ - @granite-js/plugin-core@0.1.24
23
+ - @granite-js/mpack@0.1.24
24
+ - @granite-js/cli@0.1.24
25
+ - @granite-js/image@0.1.24
26
+ - @granite-js/jest@0.1.24
27
+ - @granite-js/lottie@0.1.24
28
+ - @granite-js/native@0.1.24
29
+ - @granite-js/style-utils@0.1.24
30
+
3
31
  ## 0.1.23
4
32
 
5
33
  ### 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) => 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",
3
+ "version": "0.1.25",
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",
89
+ "@granite-js/native": "0.1.25",
90
90
  "@testing-library/dom": "^10.4.0",
91
91
  "@testing-library/react": "^16.1.0",
92
92
  "@types/babel__core": "^7",
@@ -112,13 +112,13 @@
112
112
  "react-native": "*"
113
113
  },
114
114
  "dependencies": {
115
- "@granite-js/cli": "0.1.23",
116
- "@granite-js/image": "0.1.23",
117
- "@granite-js/jest": "0.1.23",
118
- "@granite-js/lottie": "0.1.23",
119
- "@granite-js/mpack": "0.1.23",
120
- "@granite-js/plugin-core": "0.1.23",
121
- "@granite-js/style-utils": "0.1.23",
115
+ "@granite-js/cli": "0.1.25",
116
+ "@granite-js/image": "0.1.25",
117
+ "@granite-js/jest": "0.1.25",
118
+ "@granite-js/lottie": "0.1.25",
119
+ "@granite-js/mpack": "0.1.25",
120
+ "@granite-js/plugin-core": "0.1.25",
121
+ "@granite-js/style-utils": "0.1.25",
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}
@@ -15,7 +15,7 @@ import { CanGoBackGuard } from './components/CanGoBackGuard';
15
15
  import { StackNavigator } from './components/StackNavigator';
16
16
  import { useInternalRouterBackHandler } from './components/useRouterBackHandler';
17
17
  import { useInitialRouteName } from './hooks/useInitialRouteName';
18
- import { useRouterControls } from './hooks/useRouterControls';
18
+ import { useRouterControls, type RouterControlsConfig } from './hooks/useRouterControls';
19
19
  import { RequireContext } from './types';
20
20
  import { BASE_STACK_NAVIGATOR_STYLE } from './types/screen-option';
21
21
 
@@ -57,6 +57,7 @@ export interface InternalRouterProps {
57
57
  initialProps: InitialProps;
58
58
  initialScheme: string;
59
59
  setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => Promise<void> | void;
60
+ getInitialUrl?: RouterControlsConfig['getInitialUrl'];
60
61
  }
61
62
 
62
63
  export type RouterProps = StackNavigatorProps & NavigationContainerProps;
@@ -131,6 +132,7 @@ export function Router({
131
132
  screenContainer,
132
133
  // Public props (StackNavigator)
133
134
  setIosSwipeGestureEnabled,
135
+ getInitialUrl,
134
136
  ...navigationContainerProps
135
137
  }: InternalRouterProps & RouterProps): ReactElement {
136
138
  const initialRouteName = useInitialRouteName({ prefix, initialScheme });
@@ -139,6 +141,7 @@ export function Router({
139
141
  context,
140
142
  screenContainer,
141
143
  initialScheme,
144
+ getInitialUrl,
142
145
  });
143
146
 
144
147
  const ref = useMemo(() => navigationContainerRef ?? createNavigationContainerRef<any>(), [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
+ }