-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAppNavigator.tsx
110 lines (99 loc) · 2.57 KB
/
AppNavigator.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from 'react';
import { getBlogPostBySlug } from './AppBlogPostList';
import AppBlogPostListScreen from './AppBlogPostListScreen';
import AppBlogPostScreen from './AppBlogPostScreen';
import AppHomeScreen from './AppHomeScreen';
import {
NavigationContainer,
useRoute,
DefaultTheme,
DarkTheme,
} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { useColorMode } from 'theme/useColorMode';
import { View, Platform } from 'react-native';
import { useBodyWidth } from './AppHooks';
const LightTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: '#FFFFFF',
},
};
const Stack = createStackNavigator();
const getBlogPostFromParams = (params: any) => {
const { slug } = params as { slug: string };
return getBlogPostBySlug(slug);
};
const BlogPostScreen = () => (
<AppBlogPostScreen blogPost={getBlogPostFromParams(useRoute().params)} />
);
const SimpleMDXScreen = () => {
// extension is required for web!
const width = useBodyWidth();
const MDXComponent = require('./content/test/simpleMDX.mdx.jsx').default;
return (
<View style={{ padding: 40 }}>
<View style={{ width, alignSelf: 'center' }}>
<MDXComponent />
</View>
</View>
);
};
const AppStackNavigator = () => {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={AppHomeScreen}
options={{
title: 'Home',
}}
/>
<Stack.Screen
name="SimpleMDX"
component={SimpleMDXScreen}
options={{
title: 'Simple MDX',
}}
/>
<Stack.Screen
name="BlogPostList"
component={AppBlogPostListScreen}
options={{
title: 'All my posts',
}}
/>
<Stack.Screen
name="BlogPost"
component={BlogPostScreen}
options={({ route }) => ({
title: getBlogPostFromParams(route.params).frontmatter.title,
})}
/>
</Stack.Navigator>
);
};
const Linking = {
prefixes: ['https://sebastienlorber.com', 'slorber://'],
config: {
Home: '',
BlogPostList: 'posts',
BlogPost: {
path: 'posts/:slug',
},
},
};
const AppNavigator = () => {
const [colorMode] = useColorMode();
return (
<NavigationContainer
theme={colorMode === 'dark' ? DarkTheme : LightTheme}
// TODO why does it mess up to pass linking props in native platforms?
linking={Platform.OS === 'web' ? Linking : undefined}
>
<AppStackNavigator />
</NavigationContainer>
);
};
export default AppNavigator;