forked from shootismoke/mobile-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screens.tsx
148 lines (134 loc) · 3.47 KB
/
Screens.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Sh**t! I Smoke
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny
// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.
import React, { useContext } from 'react';
import { StatusBar, View } from 'react-native';
import {
createAppContainer,
CreateNavigatorConfig,
NavigationRoute,
NavigationStackRouterConfig
} from 'react-navigation';
import {
createStackNavigator,
NavigationStackConfig,
NavigationStackOptions,
NavigationStackProp
} from 'react-navigation-stack';
import { fadeIn } from 'react-navigation-transitions';
import { Api, ApiContext, ErrorContext } from '../stores';
import * as theme from '../util/theme';
import { About } from './About';
import { Details } from './Details';
import { ErrorScreen } from './ErrorScreen';
import { Home } from './Home';
import { Loading } from './Loading';
import { Search } from './Search';
import { ShareScreen } from './ShareScreen';
function stackNavigatorOptions(
initialRouteName: string
): CreateNavigatorConfig<
NavigationStackConfig,
NavigationStackRouterConfig,
NavigationStackOptions,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
NavigationStackProp<NavigationRoute, any>
> {
return {
cardStyle: {
backgroundColor: theme.backgroundColor
},
headerMode: 'none',
initialRouteName,
defaultNavigationOptions: {
// FIXME the `headerVisible` field has been moved away from this config
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
headerVisible: false
}
};
}
/**
* The main stack navigator, for the app.
*/
const MainStack = createAppContainer(
createStackNavigator(
{
About: {
screen: About
},
Details: {
screen: Details
},
Home: {
screen: Home
},
Search: {
screen: Search
}
},
stackNavigatorOptions('Home')
)
);
const RootStack = createAppContainer(
createStackNavigator(
{
Main: {
screen: MainStack
},
ShareModal: {
screen: ShareScreen
}
},
{
mode: 'modal',
headerMode: 'none',
transitionConfig: () => fadeIn()
}
)
);
/**
* A stack navigator for the error case.
*/
const ErrorStack = createAppContainer(
createStackNavigator(
{
Error: {
screen: ErrorScreen
},
Search: {
screen: Search
}
},
stackNavigatorOptions('Error')
)
);
function renderScreen(api?: Api, error?: Error): React.ReactElement {
if (error) {
return <ErrorStack />;
}
if (!api) {
return <Loading />;
}
return <RootStack />;
}
export function Screens(): React.ReactElement {
const { api } = useContext(ApiContext);
const { error } = useContext(ErrorContext);
const stack = renderScreen(api, error);
return (
<View style={theme.fullScreen}>
<StatusBar barStyle="dark-content" />
{stack}
</View>
);
}