-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
199 lines (172 loc) · 5.48 KB
/
App.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import React from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {DefaultTheme, NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import Home from './src/Pages/Home';
import OnboardingScreen from './src/Pages/OnboardingScreen';
// @ts-ignore
import {APP_ENV, ONBOARDING_KEY, ONBOARDING_SHOW_DEV} from '@env';
import {CreateAndEdit} from './src/Pages/Record/CreateAndEdit';
import {Colors, Style} from './src/Styles/Style';
import {ShowRecord} from './src/Pages/Record/ShowRecord';
import {TransparentButton} from './src/Components/Buttons/TransparentButton';
import {AllEmotions} from './src/Pages/AllEmotions';
import {getSettingsValueById} from './src/Actions/Settings';
import {FACE_ID_KEY} from './src/Components/Settings/FaceID';
import {Auth} from './src/Pages/Auth';
import {LogBox} from 'react-native';
import {getDataForWidget} from './src/Functions/getDataForWidget';
import {onDisplayNotification} from './src/Functions/onDisplayNotification';
interface MyComponentState {
showOnboarding: boolean;
onboardingLoaded: boolean;
isAuthenticated: boolean;
isAuthRequired: boolean;
}
interface Props {}
LogBox.ignoreLogs([
'Non-serializable values were found in the navigation state',
]);
export const HOUR = 20;
class App extends React.Component<Props, MyComponentState> {
constructor(props: Props) {
super(props);
this.state = {
showOnboarding: false,
onboardingLoaded: false,
isAuthenticated: false,
isAuthRequired: false,
};
}
async componentDidMount() {
if (APP_ENV === 'dev' && ONBOARDING_SHOW_DEV === 'true') {
await AsyncStorage.removeItem(ONBOARDING_KEY);
}
const isFirstTime = await AsyncStorage.getItem(ONBOARDING_KEY);
if (!isFirstTime) {
await AsyncStorage.setItem(ONBOARDING_KEY, 'true');
this.setState({showOnboarding: true});
}
await this.checkIfAuthIsRequired();
this.setState({
onboardingLoaded: true,
});
await getDataForWidget();
await onDisplayNotification();
}
private async checkIfAuthIsRequired() {
const isAuthRequired = await getSettingsValueById(FACE_ID_KEY);
if (isAuthRequired?.value === '1') {
this.setState({
isAuthRequired: true,
});
}
}
render() {
const Stack = createNativeStackNavigator();
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: Colors.background,
},
};
const headerSettings = {
headerShadowVisible: false,
headerBackTitleVisible: false,
headerTintColor: Colors.dark,
headerStyle: {
backgroundColor: Colors.background,
},
headerTitleStyle: {
...Style.text,
fontWeight: '500',
},
};
if (!this.state.onboardingLoaded) {
return null;
}
const isAuthRequired =
this.state.isAuthRequired && !this.state.isAuthenticated;
return (
<NavigationContainer theme={MyTheme}>
{isAuthRequired ? (
<Stack.Navigator>
<Stack.Screen
name="Auth"
component={Auth}
initialParams={{
onSuccessfulAuth: () => this.authSuccess(),
}}
options={{headerShown: false, animation: 'none'}}
/>
</Stack.Navigator>
) : (
<Stack.Navigator>
{this.state.showOnboarding && (
<Stack.Screen
name="Onboarding"
component={OnboardingScreen}
options={{headerShown: false}}
/>
)}
<Stack.Screen
name="Home"
component={Home}
options={{headerShown: false}}
/>
<Stack.Group screenOptions={{presentation: 'modal'}}>
<Stack.Screen
name={'AllEmotions'}
component={AllEmotions}
options={{
...headerSettings,
title: 'Все эмоции',
}}
/>
<Stack.Screen
name={'CreateAndEdit'}
component={CreateAndEdit}
options={({route}) => ({
...headerSettings,
title: App.getTitle(route),
})}
/>
</Stack.Group>
<Stack.Screen
name={'ShowRecord'}
component={ShowRecord}
options={({navigation, route}) => ({
title: 'Запись',
...headerSettings,
headerRight: () => (
<TransparentButton
stylesContainer={{}}
stylesImage={{
width: 24,
height: 24,
}}
source={require('./assets/images/icon-more-dark.png')}
onClick={() => {
ShowRecord.onClick(route.params?.recordID, navigation);
}}
/>
),
})}
/>
</Stack.Navigator>
)}
</NavigationContainer>
);
}
private static getTitle(route: any): string {
if (!route.params || !route.params?.recordID) {
return 'Создать запись';
}
return 'Редактировать запись';
}
private authSuccess() {
this.setState({isAuthenticated: true});
}
}
export default App;