-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
130 lines (110 loc) · 3.5 KB
/
App.js
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
import React from "react";
import { StyleSheet, Text, View, AsyncStorage, Image, } from "react-native";
import QuestionsScreen from "./screens/question";
//import AnswersScreen from './screens/answer'
import ProfileScreen from "./screens/profile";
import Nav from './navigator';
import {
createStackNavigator,
createAppContainer,
createDrawerNavigator
} from "react-navigation";
import Onboarding from "react-native-onboarding-swiper";
/*redux components*/
import {createStore} from 'redux';
import allReducers from './reducers/index';
import {Provider, useSelector, useDispatch} from 'react-redux';
import {firstLaunchCheck} from './actions/index';
const store=createStore(allReducers);
// const MainNavigator = createDrawerNavigator({
// Questions: { screen: QuestionsScreen },
// Profile: { screen: ProfileScreen },
// },
// {
// drawerBackgroundColor:"#b0f4e6",
// }
// );
// const App = createAppContainer(MainNavigator);
// export default App;
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
firstLaunch: null,
};
}
componentDidMount(){
AsyncStorage.getItem("alreadyLaunched").then(value => {
console.log(value)
if (value == null) {
console.log("A tru");
AsyncStorage.setItem("alreadyLaunched", JSON.stringify(true)); // No need to wait for `setItem` to finish, although you might want to handle errors
this.setState({ firstLaunch: true });
} else {
console.log("B fal");
this.setState({ firstLaunch: false });
}
}
)
}
render() {
if(this.state.firstLaunch === null){
return null; // This is the 'tricky' part: The query to AsyncStorage is not finished, but we have to present something to the user. Null will just render nothing, so you can also put a placeholder of some sort, but effectively the interval between the first mount and AsyncStorage retrieving your data won't be noticeable to the user.
}else if(this.state.firstLaunch == true){
return (
<Onboarding
pages={[
{
backgroundColor: "yellow",
image: (
<Image
source={require("./assets/icon.png")}
style={{ height: 200, width: 200 }}
/>
),
title: "Welcome to Ask App",
subtitle: "Find answer to your queries."
},
{
backgroundColor: "#fe6e58",
image: (
<Image
source={require("./images/screen1.png")}
style={{ height: 400, width: 200 }}
/>
),
title: "Ask Questions",
subtitle: "Whatever doubts you have clear them."
},
{
backgroundColor: "blue",
image: (
<Image
source={require("./images/screen2.png")}
style={{ height: 400, width: 200 }}
/>
),
title: "Get Answers",
subtitle: "Learn something new."
}
]}
onDone={() => {
this.setState({
firstLaunch: false
});
}}
onSkip={() => {
this.setState({
firstLaunch: false
});
}}
/>
);
}
return (
<Provider store={store}>
<Nav />
</Provider>
);
}
}