This repository was archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
162 lines (148 loc) · 4.42 KB
/
App.js
File metadata and controls
162 lines (148 loc) · 4.42 KB
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
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import React, { useState } from 'react';
import { Platform, StatusBar, StyleSheet, View, ScrollView } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { AsyncStorage } from 'react-native';
import AppNavigator from './navigation/AppNavigator';
import AppIntroSlider from 'react-native-app-intro-slider';
import ProfileCreateScreen from './screens/ProfileCreateScreen';
export default function App(props) {
const [isLoadingComplete, setLoadingComplete] = useState(false);
const [isOnboardingDone, setOnboardingDone] = useState(false);
const [isProfileCreated, setProfileCreated] = useState(false);
const slides = [
{
key: 'why',
title: 'Зачем приложение',
text:
'Commodo officia laboris sit aute est labore.\nPariatur veniam et ipsum incididunt commodo.',
image: require('./assets/images/robot-dev.png'),
backgroundColor: '#8fb2ab',
titleStyle: styles.tutorialTitle,
},
{
key: 'ad',
title: 'Реклама чемпионата',
text: 'Два пенсионера пойдут бегать.\nПриложение вызовет скорую.',
image: require('./assets/images/robot-dev.png'),
backgroundColor: '#deae29',
titleStyle: styles.tutorialTitle,
},
{
key: 'geo',
title: 'Важность геолокации',
text: 'Мы будем отслеживать тебя.\nТвой дом и твою собаку.',
image: require('./assets/images/robot-dev.png'),
backgroundColor: '#12bcb5',
titleStyle: styles.tutorialTitle,
},
];
if (!isLoadingComplete && !props.skipLoadingScreen) {
return (
<AppLoading
startAsync={loadResourcesAsync}
onError={handleLoadingError}
onFinish={handleFinishLoading}
/>
);
} else {
// enter the app only if intro steps are completed
if (isOnboardingDone && isProfileCreated) {
return (
<View style={styles.container}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
<AppNavigator />
</View>
);
}
if (!isOnboardingDone) {
return (
<AppIntroSlider
slides={slides}
onDone={handleFinishOnboarding}
renderDoneButton={renderDoneButton}
renderNextButton={renderNextButton}
/>
);
}
if (!isProfileCreated) {
return <ProfileCreateScreen setCreated={setProfileCreated} />;
}
}
function handleFinishOnboarding() {
AsyncStorage.setItem('isOnboardingDone', 'true').then(() => {
setOnboardingDone(true);
});
}
function handleFinishLoading() {
AsyncStorage.getItem('isOnboardingDone').then(value => {
const isCompleted = value === 'true';
console.log(isCompleted, '- check if user closed tutorial');
setOnboardingDone(isCompleted);
});
AsyncStorage.getItem('isProfileCreated').then(value => {
const isCreated = value === 'true';
console.log(isCreated, '- check if user created profile');
setProfileCreated(isCreated);
});
setLoadingComplete(true);
}
}
function renderNextButton() {
return (
<View style={styles.buttonCircle}>
<Ionicons
name="md-arrow-round-forward"
color="rgba(255, 255, 255, .9)"
size={24}
style={{ backgroundColor: 'transparent' }}
/>
</View>
);
}
function renderDoneButton() {
return (
<View style={styles.buttonCircle}>
<Ionicons
name="md-checkmark"
color="rgba(255, 255, 255, .9)"
size={24}
style={{ backgroundColor: 'transparent' }}
/>
</View>
);
}
async function loadResourcesAsync() {
await Promise.all([
Font.loadAsync({
// This is the font that we are using for our tab bar
...Ionicons.font,
}),
]);
}
function handleLoadingError(error) {
// In this case, you might want to report the error to your error reporting
// service, for example Sentry
console.warn(error);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
buttonCircle: {
width: 40,
height: 40,
backgroundColor: 'rgba(0, 0, 0, .2)',
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center',
},
tutorialTitle: {
textAlign: 'center',
fontWeight: '400',
marginTop: 16,
color: 'rgba(255, 255, 255, .9)',
},
});