@granite-js/react-native 0.1.19 → 0.1.21
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/async-bridges.d.ts +1 -0
- package/constant-bridges.d.ts +1 -0
- package/dist/app/AppRoot.d.ts +1 -1
- package/dist/app/Granite.d.ts +8 -1
- package/dist/async-bridges.d.mts +60 -0
- package/dist/async-bridges.js +46 -0
- package/dist/async-bridges.mjs +18 -0
- package/dist/chunk-A3JGM5OI.mjs +7 -0
- package/dist/constant-bridges.d.mts +25 -0
- package/dist/constant-bridges.js +38 -0
- package/dist/constant-bridges.mjs +11 -0
- package/dist/router/Router.d.ts +1 -1
- package/dist/router/components/CanGoBackGuard.d.ts +4 -1
- package/package.json +25 -13
- package/src/app/AppRoot.tsx +11 -1
- package/src/app/Granite.tsx +8 -1
- package/src/router/Router.tsx +3 -1
- package/src/router/components/CanGoBackGuard.tsx +17 -0
- package/types.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @granite-js/react-native
|
|
2
2
|
|
|
3
|
+
## 0.1.21
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1a15a19: Add setIosSwipeGestureEnabled
|
|
8
|
+
- @granite-js/cli@0.1.21
|
|
9
|
+
- @granite-js/image@0.1.21
|
|
10
|
+
- @granite-js/jest@0.1.21
|
|
11
|
+
- @granite-js/lottie@0.1.21
|
|
12
|
+
- @granite-js/mpack@0.1.21
|
|
13
|
+
- @granite-js/native@0.1.21
|
|
14
|
+
- @granite-js/plugin-core@0.1.21
|
|
15
|
+
- @granite-js/style-utils@0.1.21
|
|
16
|
+
|
|
17
|
+
## 0.1.20
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 1df5883: update package.json meta to supports any moduleResolutions
|
|
22
|
+
- Updated dependencies [1df5883]
|
|
23
|
+
- Updated dependencies [a93bf1e]
|
|
24
|
+
- @granite-js/native@0.1.20
|
|
25
|
+
- @granite-js/image@0.1.20
|
|
26
|
+
- @granite-js/mpack@0.1.20
|
|
27
|
+
- @granite-js/jest@0.1.20
|
|
28
|
+
- @granite-js/lottie@0.1.20
|
|
29
|
+
- @granite-js/style-utils@0.1.20
|
|
30
|
+
- @granite-js/cli@0.1.20
|
|
31
|
+
- @granite-js/plugin-core@0.1.20
|
|
32
|
+
|
|
3
33
|
## 0.1.19
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/async-bridges';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/constant-bridges';
|
package/dist/app/AppRoot.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function AppRoot({ appName, context, container: Container, initialProps, initialScheme, router }: AppRootProps): import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
export declare function AppRoot({ appName, context, container: Container, initialProps, initialScheme, router, setIosSwipeGestureEnabled, }: AppRootProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/app/Granite.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ export interface GraniteProps {
|
|
|
24
24
|
* The initial scheme of the app.
|
|
25
25
|
*/
|
|
26
26
|
initialScheme?: string;
|
|
27
|
+
/**
|
|
28
|
+
* @description
|
|
29
|
+
* The function to set the iOS swipe gesture enabled.
|
|
30
|
+
*/
|
|
31
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: {
|
|
32
|
+
isEnabled: boolean;
|
|
33
|
+
}) => void;
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* @public
|
|
@@ -60,7 +67,7 @@ export interface GraniteProps {
|
|
|
60
67
|
* ```
|
|
61
68
|
*/
|
|
62
69
|
export declare const Granite: {
|
|
63
|
-
registerApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName, context, router, initialScheme }: GraniteProps): (initialProps: InitialProps) => JSX.Element;
|
|
70
|
+
registerApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName, context, router, initialScheme, setIosSwipeGestureEnabled }: GraniteProps): (initialProps: InitialProps) => JSX.Element;
|
|
64
71
|
registerHostApp(AppContainer: ComponentType<PropsWithChildren<InitialProps>>, { appName }: Pick<GraniteProps, "appName">): (initialProps: InitialProps) => JSX.Element;
|
|
65
72
|
readonly appName: string;
|
|
66
73
|
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* @category Screen Control
|
|
4
|
+
* @kind function
|
|
5
|
+
* @name closeView
|
|
6
|
+
* @description Function that closes the current screen. It can be used when you want to exit a service by pressing a "Close" button.
|
|
7
|
+
* @returns {Promise<void>}
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ### Close screen with close button
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { Button } from 'react-native';
|
|
14
|
+
* import { closeView } from '@granite-js/react-native';
|
|
15
|
+
*
|
|
16
|
+
* function CloseButton() {
|
|
17
|
+
* return <Button title="Close" onPress={closeView} />;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare function closeView(): Promise<void>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @public
|
|
25
|
+
* @kind function
|
|
26
|
+
* @category Screen Navigation
|
|
27
|
+
*
|
|
28
|
+
* @name openURL
|
|
29
|
+
* @signature
|
|
30
|
+
* ```typescript
|
|
31
|
+
* function openURL(url: string): Promise<any>;
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @description
|
|
35
|
+
* Opens the specified URL in the device's default browser or related app.
|
|
36
|
+
* This function uses the [`Linking.openURL`](https://reactnative.dev/docs/0.72/linking#openurl) method from `react-native` to open the URL.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} url URL address to open
|
|
39
|
+
* @returns {Promise<any>} Promise that resolves when the URL is successfully opened
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
*
|
|
43
|
+
* ### Open external URL
|
|
44
|
+
*
|
|
45
|
+
* ```tsx
|
|
46
|
+
* import { openURL } from '@granite-js/react-native';
|
|
47
|
+
* import { Button } from 'react-native';
|
|
48
|
+
*
|
|
49
|
+
* function Page() {
|
|
50
|
+
* const handlePress = () => {
|
|
51
|
+
* openURL('https://google.com');
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* return <Button title="Open Google Website" onPress={handlePress} />;
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function openURL(url: string): Promise<any>;
|
|
59
|
+
|
|
60
|
+
export { closeView, openURL };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/async-bridges.ts
|
|
21
|
+
var async_bridges_exports = {};
|
|
22
|
+
__export(async_bridges_exports, {
|
|
23
|
+
closeView: () => closeView,
|
|
24
|
+
openURL: () => openURL
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(async_bridges_exports);
|
|
27
|
+
|
|
28
|
+
// src/native-modules/natives/GraniteModule.ts
|
|
29
|
+
var import_react_native = require("react-native");
|
|
30
|
+
var GraniteModule = import_react_native.TurboModuleRegistry.getEnforcing("GraniteModule");
|
|
31
|
+
|
|
32
|
+
// src/native-modules/natives/closeView.ts
|
|
33
|
+
async function closeView() {
|
|
34
|
+
return GraniteModule.closeView();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/native-modules/natives/openURL.ts
|
|
38
|
+
var import_react_native2 = require("react-native");
|
|
39
|
+
function openURL(url) {
|
|
40
|
+
return import_react_native2.Linking.openURL(url);
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
closeView,
|
|
45
|
+
openURL
|
|
46
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GraniteModule
|
|
3
|
+
} from "./chunk-A3JGM5OI.mjs";
|
|
4
|
+
|
|
5
|
+
// src/native-modules/natives/closeView.ts
|
|
6
|
+
async function closeView() {
|
|
7
|
+
return GraniteModule.closeView();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/native-modules/natives/openURL.ts
|
|
11
|
+
import { Linking } from "react-native";
|
|
12
|
+
function openURL(url) {
|
|
13
|
+
return Linking.openURL(url);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
closeView,
|
|
17
|
+
openURL
|
|
18
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* @name getSchemeUri
|
|
4
|
+
* @category Environment Check
|
|
5
|
+
* @kind function
|
|
6
|
+
* @description Returns the scheme value when first entering the screen. URI changes due to page navigation are not reflected.
|
|
7
|
+
* @returns {string} Returns the scheme value when first entering the screen.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ### Get initial scheme value
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { getSchemeUri } from '@granite-js/react-native';
|
|
14
|
+
* import { Text } from 'react-native';
|
|
15
|
+
*
|
|
16
|
+
* function MyPage() {
|
|
17
|
+
* const schemeUri = getSchemeUri();
|
|
18
|
+
*
|
|
19
|
+
* return <Text>Initial scheme value: {schemeUri}</Text>
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function getSchemeUri(): string;
|
|
24
|
+
|
|
25
|
+
export { getSchemeUri };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/constant-bridges.ts
|
|
21
|
+
var constant_bridges_exports = {};
|
|
22
|
+
__export(constant_bridges_exports, {
|
|
23
|
+
getSchemeUri: () => getSchemeUri
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constant_bridges_exports);
|
|
26
|
+
|
|
27
|
+
// src/native-modules/natives/GraniteModule.ts
|
|
28
|
+
var import_react_native = require("react-native");
|
|
29
|
+
var GraniteModule = import_react_native.TurboModuleRegistry.getEnforcing("GraniteModule");
|
|
30
|
+
|
|
31
|
+
// src/native-modules/natives/getSchemeUri.ts
|
|
32
|
+
function getSchemeUri() {
|
|
33
|
+
return GraniteModule.schemeUri;
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
getSchemeUri
|
|
38
|
+
});
|
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, ...navigationContainerProps }: InternalRouterProps & RouterProps): ReactElement;
|
|
58
|
+
export declare function Router({ prefix, context, container: Container, initialProps, initialScheme, navigationContainerRef, defaultScreenOption, screenContainer, setIosSwipeGestureEnabled, ...navigationContainerProps }: InternalRouterProps & RouterProps): ReactElement;
|
|
59
59
|
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
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
4
|
children: ReactNode;
|
|
5
5
|
onBack?: () => void;
|
|
6
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: {
|
|
7
|
+
isEnabled: boolean;
|
|
8
|
+
}) => void;
|
|
6
9
|
}): import("react/jsx-runtime").JSX.Element;
|
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.21",
|
|
4
4
|
"description": "The Granite Framework",
|
|
5
5
|
"bin": {
|
|
6
6
|
"granite": "./bin/cli.js"
|
|
@@ -20,12 +20,24 @@
|
|
|
20
20
|
"default": "./src/index.ts"
|
|
21
21
|
},
|
|
22
22
|
"./async-bridges": {
|
|
23
|
-
"
|
|
24
|
-
|
|
23
|
+
"import": {
|
|
24
|
+
"types": "./dist/async-bridges.d.mts",
|
|
25
|
+
"default": "./dist/async-bridges.mjs"
|
|
26
|
+
},
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/async-bridges.d.ts",
|
|
29
|
+
"default": "./dist/async-bridges.js"
|
|
30
|
+
}
|
|
25
31
|
},
|
|
26
32
|
"./constant-bridges": {
|
|
27
|
-
"
|
|
28
|
-
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/constant-bridges.d.mts",
|
|
35
|
+
"default": "./dist/constant-bridges.mjs"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/constant-bridges.d.ts",
|
|
39
|
+
"default": "./dist/constant-bridges.js"
|
|
40
|
+
}
|
|
29
41
|
},
|
|
30
42
|
"./config": {
|
|
31
43
|
"import": {
|
|
@@ -74,7 +86,7 @@
|
|
|
74
86
|
"@babel/core": "^7.24.9",
|
|
75
87
|
"@babel/preset-env": "^7.24.8",
|
|
76
88
|
"@babel/preset-typescript": "^7.24.7",
|
|
77
|
-
"@granite-js/native": "0.1.
|
|
89
|
+
"@granite-js/native": "0.1.21",
|
|
78
90
|
"@testing-library/dom": "^10.4.0",
|
|
79
91
|
"@testing-library/react": "^16.1.0",
|
|
80
92
|
"@types/babel__core": "^7",
|
|
@@ -100,13 +112,13 @@
|
|
|
100
112
|
"react-native": "*"
|
|
101
113
|
},
|
|
102
114
|
"dependencies": {
|
|
103
|
-
"@granite-js/cli": "0.1.
|
|
104
|
-
"@granite-js/image": "0.1.
|
|
105
|
-
"@granite-js/jest": "0.1.
|
|
106
|
-
"@granite-js/lottie": "0.1.
|
|
107
|
-
"@granite-js/mpack": "0.1.
|
|
108
|
-
"@granite-js/plugin-core": "0.1.
|
|
109
|
-
"@granite-js/style-utils": "0.1.
|
|
115
|
+
"@granite-js/cli": "0.1.21",
|
|
116
|
+
"@granite-js/image": "0.1.21",
|
|
117
|
+
"@granite-js/jest": "0.1.21",
|
|
118
|
+
"@granite-js/lottie": "0.1.21",
|
|
119
|
+
"@granite-js/mpack": "0.1.21",
|
|
120
|
+
"@granite-js/plugin-core": "0.1.21",
|
|
121
|
+
"@granite-js/style-utils": "0.1.21",
|
|
110
122
|
"es-toolkit": "^1.39.8",
|
|
111
123
|
"react-native-url-polyfill": "1.3.0"
|
|
112
124
|
}
|
package/src/app/AppRoot.tsx
CHANGED
|
@@ -15,9 +15,18 @@ interface AppRootProps extends GraniteProps {
|
|
|
15
15
|
container: ComponentType<PropsWithChildren<InitialProps>>;
|
|
16
16
|
initialProps: InitialProps;
|
|
17
17
|
initialScheme: string;
|
|
18
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function AppRoot({
|
|
21
|
+
export function AppRoot({
|
|
22
|
+
appName,
|
|
23
|
+
context,
|
|
24
|
+
container: Container,
|
|
25
|
+
initialProps,
|
|
26
|
+
initialScheme,
|
|
27
|
+
router,
|
|
28
|
+
setIosSwipeGestureEnabled,
|
|
29
|
+
}: AppRootProps) {
|
|
21
30
|
const prefix = getSchemePrefix({
|
|
22
31
|
appName,
|
|
23
32
|
scheme: global.__granite.app.scheme,
|
|
@@ -35,6 +44,7 @@ export function AppRoot({ appName, context, container: Container, initialProps,
|
|
|
35
44
|
initialScheme={initialScheme}
|
|
36
45
|
container={Container}
|
|
37
46
|
prefix={prefix}
|
|
47
|
+
setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
|
|
38
48
|
{...router}
|
|
39
49
|
/>
|
|
40
50
|
</BackEventProvider>
|
package/src/app/Granite.tsx
CHANGED
|
@@ -31,6 +31,12 @@ export interface GraniteProps {
|
|
|
31
31
|
* The initial scheme of the app.
|
|
32
32
|
*/
|
|
33
33
|
initialScheme?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @description
|
|
37
|
+
* The function to set the iOS swipe gesture enabled.
|
|
38
|
+
*/
|
|
39
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
const createApp = () => {
|
|
@@ -47,7 +53,7 @@ const createApp = () => {
|
|
|
47
53
|
return {
|
|
48
54
|
registerApp(
|
|
49
55
|
AppContainer: ComponentType<PropsWithChildren<InitialProps>>,
|
|
50
|
-
{ appName, context, router, initialScheme }: GraniteProps
|
|
56
|
+
{ appName, context, router, initialScheme, setIosSwipeGestureEnabled }: GraniteProps
|
|
51
57
|
): (initialProps: InitialProps) => JSX.Element {
|
|
52
58
|
if (appName === ENTRY_BUNDLE_NAME) {
|
|
53
59
|
throw new Error(`Reserved app name 'shared' cannot be used`);
|
|
@@ -59,6 +65,7 @@ const createApp = () => {
|
|
|
59
65
|
container={AppContainer}
|
|
60
66
|
initialProps={initialProps}
|
|
61
67
|
initialScheme={initialScheme ?? getSchemeUri()}
|
|
68
|
+
setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}
|
|
62
69
|
appName={appName}
|
|
63
70
|
context={context}
|
|
64
71
|
router={router}
|
package/src/router/Router.tsx
CHANGED
|
@@ -56,6 +56,7 @@ export interface InternalRouterProps {
|
|
|
56
56
|
container: ComponentType<PropsWithChildren<InitialProps>>;
|
|
57
57
|
initialProps: InitialProps;
|
|
58
58
|
initialScheme: string;
|
|
59
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => Promise<void> | void;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export type RouterProps = StackNavigatorProps & NavigationContainerProps;
|
|
@@ -129,6 +130,7 @@ export function Router({
|
|
|
129
130
|
defaultScreenOption,
|
|
130
131
|
screenContainer,
|
|
131
132
|
// Public props (StackNavigator)
|
|
133
|
+
setIosSwipeGestureEnabled,
|
|
132
134
|
...navigationContainerProps
|
|
133
135
|
}: InternalRouterProps & RouterProps): ReactElement {
|
|
134
136
|
const initialRouteName = useInitialRouteName({ prefix, initialScheme });
|
|
@@ -163,7 +165,7 @@ export function Router({
|
|
|
163
165
|
|
|
164
166
|
return (
|
|
165
167
|
<NavigationContainer ref={ref} {...navigationContainerProps} linking={linkingOptions}>
|
|
166
|
-
<CanGoBackGuard canGoBack={canGoBack} onBack={onBack}>
|
|
168
|
+
<CanGoBackGuard canGoBack={canGoBack} onBack={onBack} setIosSwipeGestureEnabled={setIosSwipeGestureEnabled}>
|
|
167
169
|
<Container {...initialProps}>
|
|
168
170
|
<StackNavigator.Navigator initialRouteName={initialRouteName} screenOptions={screenOptions}>
|
|
169
171
|
{Screens}
|
|
@@ -1,17 +1,34 @@
|
|
|
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,
|
|
9
|
+
setIosSwipeGestureEnabled,
|
|
8
10
|
}: {
|
|
9
11
|
canGoBack: boolean;
|
|
10
12
|
children: ReactNode;
|
|
11
13
|
onBack?: () => void;
|
|
14
|
+
setIosSwipeGestureEnabled?: ({ isEnabled }: { isEnabled: boolean }) => void;
|
|
12
15
|
}) {
|
|
16
|
+
const isInitialScreen = useIsInitialScreen();
|
|
17
|
+
|
|
13
18
|
const shouldBlockGoingBack = !canGoBack;
|
|
14
19
|
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!isInitialScreen || !canGoBack) {
|
|
22
|
+
setIosSwipeGestureEnabled?.({ isEnabled: false });
|
|
23
|
+
|
|
24
|
+
return () => {
|
|
25
|
+
setIosSwipeGestureEnabled?.({ isEnabled: true });
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return;
|
|
30
|
+
}, [canGoBack, isInitialScreen, setIosSwipeGestureEnabled]);
|
|
31
|
+
|
|
15
32
|
useEffect(() => {
|
|
16
33
|
if (shouldBlockGoingBack) {
|
|
17
34
|
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/types/global.d.ts';
|