Skip to content

Commit 228c0c6

Browse files
committed
Merge branch 'develop'
2 parents 8145fcf + bc57946 commit 228c0c6

5 files changed

Lines changed: 93 additions & 10 deletions

File tree

bluebase/expo/apps/plugin-settings-app/Screens/Home.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export const HomeScreen = (props: any) => {
3838
onPress={navigate('WrappedSettings')}
3939
/>
4040
<Divider />
41+
<List.Item title="Native Stack" onPress={navigate('NativeStack')} />
42+
<Divider />
4143
<List.Item title="Modal" onPress={navigate('Modal')} />
4244
<Divider />
4345
<List.Item

bluebase/expo/apps/plugin-settings-app/index.tsx

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable react/jsx-no-bind */
12
// https://github.com/kmagiera/react-native-gesture-handler/issues/320#issuecomment-443815828
23
import 'react-native-gesture-handler';
34

@@ -71,8 +72,8 @@ const plugin = createPlugin({
7172
},
7273

7374
{
74-
name: 'Modal',
75-
path: '/modal',
75+
name: 'NativeStack',
76+
path: '/native-stack',
7677

7778
options: {
7879
headerShown: false,
@@ -85,6 +86,61 @@ const plugin = createPlugin({
8586
type: 'native-stack',
8687
// mode: 'modal',
8788

89+
routes: [
90+
{
91+
name: 'Native 1',
92+
path: 'native1',
93+
exact: true,
94+
95+
// eslint-disable-next-line react/display-name
96+
screen: (props: any) => (
97+
<ComponentState
98+
title="Title 1"
99+
description="This screen is in a native stack"
100+
actionOnPress={() => props.navigation.navigate('Native2')}
101+
actionTitle="Show Modal"
102+
/>
103+
),
104+
105+
navigationOptions: {
106+
// stackPresentation: 'modal',
107+
title: 'Native Stack 1 Screen',
108+
},
109+
},
110+
{
111+
name: 'Native2',
112+
path: 'native2',
113+
exact: true,
114+
115+
// eslint-disable-next-line react/display-name
116+
screen: () => (
117+
<ComponentState title="Title 2" description="This screen is in a modal" />
118+
),
119+
120+
navigationOptions: {
121+
stackPresentation: 'modal',
122+
title: 'Native Stack 2 Screen',
123+
} as any,
124+
},
125+
],
126+
},
127+
},
128+
129+
{
130+
name: 'Modal',
131+
path: '/modal',
132+
133+
options: {
134+
headerShown: false,
135+
contentStyle: {
136+
backgroundColor: 'black',
137+
},
138+
},
139+
140+
navigator: {
141+
type: 'stack',
142+
mode: 'modal',
143+
88144
routes: [
89145
{
90146
name: 'Modal1',
@@ -96,8 +152,8 @@ const plugin = createPlugin({
96152
<ComponentState
97153
title="Title 1"
98154
description="This screen is in a modal"
99-
actionOnPress={() => props.navigation.navigate('Modal2')}
100155
actionTitle="Modal 2"
156+
actionOnPress={() => props.navigation.navigate('Modal2')}
101157
/>
102158
),
103159

src/components/Navigator/Navigator.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import {
88
} from '../../helpers';
99
import { resolveThunk, useBlueBase, useIntl, useTheme } from '@bluebase/core';
1010

11-
import { NavigatorProps as CoreNavigatorProps } from '@bluebase/components';
11+
import { NavigatorProps } from '@bluebase/components';
1212
import React from 'react';
1313

14-
export interface NavigatorProps extends CoreNavigatorProps {}
15-
1614
/**
1715
* Navigator (V5)
1816
* Renders a single navigator
@@ -40,7 +38,10 @@ export const Navigator = (props: NavigatorProps) => {
4038

4139
const renderRoute = (route: RouteConfigWithResolveSubRoutes) => {
4240
// We're not able to resovle navigation object here. Open to better ideas.
43-
const options = resolveRouteOptions(route, { navigation: stubNavigationObject, screenProps });
41+
const options = resolveRouteOptions(route, {
42+
navigation: stubNavigationObject,
43+
screenProps,
44+
});
4445

4546
return (
4647
<NavigatorComponent.Screen

src/helpers/__tests__/resolveNavigatorScreenOptions.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isIosModalScreen } from '../resolveNavigatorScreenOptions';
12
import { resolveNavigatorScreenOptions } from '..';
23

34
describe('resolveNavigatorScreenOptions', () => {
@@ -21,7 +22,12 @@ describe('resolveNavigatorScreenOptions', () => {
2122

2223
it('should return empty object if nothing suitable is provided', async () => {
2324
const opts = resolveNavigatorScreenOptions({} as any);
24-
2525
expect(opts).toMatchObject({});
2626
});
27+
28+
describe('isIosModalScreen', () => {
29+
it('should return true', async () => {
30+
expect(isIosModalScreen({ type: 'stack', mode: 'modal' } as any)).toBe(true);
31+
});
32+
});
2733
});
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
import { NavigatorProps as CoreNavigatorProps } from '@bluebase/components';
1+
import { NavigatorProps as CoreNavigatorProps, NavigatorProps } from '@bluebase/components';
2+
3+
import { Platform } from 'react-native';
4+
import { TransitionPresets } from '@react-navigation/stack';
5+
6+
export const isIosModalScreen = ({ type, mode }: NavigatorProps) => {
7+
if (Platform.OS === 'ios' && type === 'stack' && mode === 'modal') {
8+
return true;
9+
}
10+
11+
return false;
12+
};
213

314
/**
415
* Given a navigator object, resolves its screen options
@@ -7,5 +18,12 @@ import { NavigatorProps as CoreNavigatorProps } from '@bluebase/components';
718
*/
819
export const resolveNavigatorScreenOptions = (navigator: CoreNavigatorProps) => {
920
const resolvedScreenOptions = navigator.screenOptions || navigator.defaultNavigationOptions || {};
10-
return resolvedScreenOptions;
21+
return {
22+
...(isIosModalScreen(navigator) && {
23+
gestureEnabled: true,
24+
cardOverlayEnabled: true,
25+
...TransitionPresets.ModalPresentationIOS,
26+
}),
27+
...resolvedScreenOptions,
28+
};
1129
};

0 commit comments

Comments
 (0)