@granite-js/react-native 0.1.20 → 0.1.22

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,32 @@
1
1
  # @granite-js/react-native
2
2
 
3
+ ## 0.1.22
4
+
5
+ ### Patch Changes
6
+
7
+ - @granite-js/cli@0.1.22
8
+ - @granite-js/image@0.1.22
9
+ - @granite-js/jest@0.1.22
10
+ - @granite-js/lottie@0.1.22
11
+ - @granite-js/mpack@0.1.22
12
+ - @granite-js/native@0.1.22
13
+ - @granite-js/plugin-core@0.1.22
14
+ - @granite-js/style-utils@0.1.22
15
+
16
+ ## 0.1.21
17
+
18
+ ### Patch Changes
19
+
20
+ - 1a15a19: Add setIosSwipeGestureEnabled
21
+ - @granite-js/cli@0.1.21
22
+ - @granite-js/image@0.1.21
23
+ - @granite-js/jest@0.1.21
24
+ - @granite-js/lottie@0.1.21
25
+ - @granite-js/mpack@0.1.21
26
+ - @granite-js/native@0.1.21
27
+ - @granite-js/plugin-core@0.1.21
28
+ - @granite-js/style-utils@0.1.21
29
+
3
30
  ## 0.1.20
4
31
 
5
32
  ### Patch Changes
@@ -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;
@@ -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
  };
@@ -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.20",
3
+ "version": "0.1.22",
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.20",
89
+ "@granite-js/native": "0.1.22",
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.20",
116
- "@granite-js/image": "0.1.20",
117
- "@granite-js/jest": "0.1.20",
118
- "@granite-js/lottie": "0.1.20",
119
- "@granite-js/mpack": "0.1.20",
120
- "@granite-js/plugin-core": "0.1.20",
121
- "@granite-js/style-utils": "0.1.20",
115
+ "@granite-js/cli": "0.1.22",
116
+ "@granite-js/image": "0.1.22",
117
+ "@granite-js/jest": "0.1.22",
118
+ "@granite-js/lottie": "0.1.22",
119
+ "@granite-js/mpack": "0.1.22",
120
+ "@granite-js/plugin-core": "0.1.22",
121
+ "@granite-js/style-utils": "0.1.22",
122
122
  "es-toolkit": "^1.39.8",
123
123
  "react-native-url-polyfill": "1.3.0"
124
124
  }
@@ -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({ appName, context, container: Container, initialProps, initialScheme, router }: AppRootProps) {
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>
@@ -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}
@@ -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', () => {