@granite-js/react-native 0.1.24 → 0.1.26
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 +29 -0
- package/dist/app/AppRoot.d.ts +1 -1
- package/dist/app/Granite.d.ts +8 -1
- package/dist/rn-polyfills/index.d.ts +1 -1
- package/dist/router/Router.d.ts +1 -1
- package/dist/router/hooks/useRouterControls.d.ts +2 -1
- package/package.json +14 -10
- package/src/app/AppRoot.tsx +4 -1
- package/src/app/Granite.tsx +13 -1
- package/src/dev-entrypoint/index.tsx +0 -3
- package/src/rn-polyfills/index.ts +1 -1
- package/src/router/Router.tsx +4 -1
- package/src/router/hooks/useRouterControls.tsx +13 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 0.1.26
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 41f9ab3: ensure polyfill setup during initialization and update package.json config for improve tree shaking
|
|
8
|
+
- Updated dependencies [41f9ab3]
|
|
9
|
+
- @granite-js/style-utils@0.1.26
|
|
10
|
+
- @granite-js/lottie@0.1.26
|
|
11
|
+
- @granite-js/image@0.1.26
|
|
12
|
+
- @granite-js/jest@0.1.26
|
|
13
|
+
- @granite-js/cli@0.1.26
|
|
14
|
+
- @granite-js/mpack@0.1.26
|
|
15
|
+
- @granite-js/native@0.1.26
|
|
16
|
+
- @granite-js/plugin-core@0.1.26
|
|
17
|
+
|
|
18
|
+
## 0.1.25
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 6717901: add getInitialUrl option
|
|
23
|
+
- @granite-js/cli@0.1.25
|
|
24
|
+
- @granite-js/image@0.1.25
|
|
25
|
+
- @granite-js/jest@0.1.25
|
|
26
|
+
- @granite-js/lottie@0.1.25
|
|
27
|
+
- @granite-js/mpack@0.1.25
|
|
28
|
+
- @granite-js/native@0.1.25
|
|
29
|
+
- @granite-js/plugin-core@0.1.25
|
|
30
|
+
- @granite-js/style-utils@0.1.25
|
|
31
|
+
|
|
3
32
|
## 0.1.24
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/app/AppRoot.d.ts
CHANGED
|
@@ -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;
|
package/dist/app/Granite.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function setupPolyfills(): void;
|
package/dist/router/Router.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.1.26",
|
|
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.
|
|
89
|
+
"@granite-js/native": "0.1.26",
|
|
90
90
|
"@testing-library/dom": "^10.4.0",
|
|
91
91
|
"@testing-library/react": "^16.1.0",
|
|
92
92
|
"@types/babel__core": "^7",
|
|
@@ -112,14 +112,18 @@
|
|
|
112
112
|
"react-native": "*"
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
-
"@granite-js/cli": "0.1.
|
|
116
|
-
"@granite-js/image": "0.1.
|
|
117
|
-
"@granite-js/jest": "0.1.
|
|
118
|
-
"@granite-js/lottie": "0.1.
|
|
119
|
-
"@granite-js/mpack": "0.1.
|
|
120
|
-
"@granite-js/plugin-core": "0.1.
|
|
121
|
-
"@granite-js/style-utils": "0.1.
|
|
115
|
+
"@granite-js/cli": "0.1.26",
|
|
116
|
+
"@granite-js/image": "0.1.26",
|
|
117
|
+
"@granite-js/jest": "0.1.26",
|
|
118
|
+
"@granite-js/lottie": "0.1.26",
|
|
119
|
+
"@granite-js/mpack": "0.1.26",
|
|
120
|
+
"@granite-js/plugin-core": "0.1.26",
|
|
121
|
+
"@granite-js/style-utils": "0.1.26",
|
|
122
122
|
"es-toolkit": "^1.39.8",
|
|
123
123
|
"react-native-url-polyfill": "1.3.0"
|
|
124
|
-
}
|
|
124
|
+
},
|
|
125
|
+
"sideEffects": [
|
|
126
|
+
"dist/async-bridges.*",
|
|
127
|
+
"dist/constant-bridges.*"
|
|
128
|
+
]
|
|
125
129
|
}
|
package/src/app/AppRoot.tsx
CHANGED
|
@@ -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>
|
package/src/app/Granite.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import type { RouterProps, RequireContext } from '../router';
|
|
|
6
6
|
import { AppRoot } from './AppRoot';
|
|
7
7
|
import { HostAppRoot } from './HostAppRoot';
|
|
8
8
|
import { getSchemeUri } from '../constant-bridges';
|
|
9
|
+
import { setupPolyfills } from '../rn-polyfills';
|
|
9
10
|
|
|
10
11
|
export interface GraniteProps {
|
|
11
12
|
/**
|
|
@@ -37,11 +38,21 @@ export interface GraniteProps {
|
|
|
37
38
|
* The function to set the iOS swipe gesture enabled.
|
|
38
39
|
*/
|
|
39
40
|
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description
|
|
44
|
+
* The function to provide the initial URL to router.
|
|
45
|
+
* @param initialScheme The initial scheme of the app.
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getInitialUrl?: (initialScheme: string) => string | undefined | Promise<string | undefined>;
|
|
40
49
|
}
|
|
41
50
|
|
|
42
51
|
const createApp = () => {
|
|
43
52
|
let _appName: string | null = null;
|
|
44
53
|
|
|
54
|
+
setupPolyfills();
|
|
55
|
+
|
|
45
56
|
function registerComponent(appKey: string, component: React.ComponentType<any>): string {
|
|
46
57
|
if (AppRegistry.getAppKeys().includes(appKey)) {
|
|
47
58
|
// `AppRegistry.registerComponent` returns the app key.
|
|
@@ -54,7 +65,7 @@ const createApp = () => {
|
|
|
54
65
|
return {
|
|
55
66
|
registerApp(
|
|
56
67
|
AppContainer: ComponentType<PropsWithChildren<InitialProps>>,
|
|
57
|
-
{ appName, context, router, initialScheme, setIosSwipeGestureEnabled }: GraniteProps
|
|
68
|
+
{ appName, context, router, initialScheme, setIosSwipeGestureEnabled, getInitialUrl }: GraniteProps
|
|
58
69
|
): (initialProps: InitialProps) => JSX.Element {
|
|
59
70
|
if (appName === ENTRY_BUNDLE_NAME) {
|
|
60
71
|
throw new Error(`Reserved app name 'shared' cannot be used`);
|
|
@@ -67,6 +78,7 @@ const createApp = () => {
|
|
|
67
78
|
initialProps={initialProps}
|
|
68
79
|
initialScheme={initialScheme ?? getSchemeUri()}
|
|
69
80
|
setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
|
|
81
|
+
getInitialUrl={getInitialUrl}
|
|
70
82
|
appName={appName}
|
|
71
83
|
context={context}
|
|
72
84
|
router={router}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
2
|
import { AppRegistry } from 'react-native';
|
|
3
3
|
import { ENTRY_BUNDLE_NAME } from '../constants';
|
|
4
|
-
import { setup } from '../rn-polyfills';
|
|
5
|
-
|
|
6
|
-
setup();
|
|
7
4
|
|
|
8
5
|
export function register(Component: ComponentType<any>) {
|
|
9
6
|
if (AppRegistry.getAppKeys().includes(ENTRY_BUNDLE_NAME)) {
|
package/src/router/Router.tsx
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|