-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
110 lines (95 loc) · 2.98 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
import React from 'react';
import TabNavigator from 'react-native-tab-navigator';
import { AsyncStorage, ActivityIndicator, Dimensions, StyleSheet, Text, View } from 'react-native';
import { Ionicons } from '@expo/vector-icons';
import { Provider } from 'react-redux'
import storeFactory from './src/store'
import { getJoke } from './src/actions'
import Joke from './src/Jokes.js'
import Fav from './src/Fav.js'
import defaultInitialState from './initialState.json'
let store = storeFactory(defaultInitialState)
const deviceW = Dimensions.get('window').width
const basePx = 375
function px2dp(px) {
return px * deviceW / basePx
}
export default class App extends React.Component {
constructor(props) {
super(props)
this.state = {
selectedTab: 'jokes',
initializeApp: true
}
}
componentWillMount() {
var self = this;
AsyncStorage.getItem('joke-store').then((value) => {
const initialState = (value !== null) ?
JSON.parse(value) : defaultInitialState
store = storeFactory(initialState)
self.setState({
initializeApp: false
})
})
}
render() {
if (this.state.initializeApp) {
return (
<View style={styles.container}>
<Text fontSize={36}>Hold your horses, while things get stable</Text><ActivityIndicator size="large" color="#00ff00" />
</View>
)
}
else {
return (
<Provider store={store}>
<TabNavigator tabBarStyle={styles.tabBar}>
<TabNavigator.Item
titleStyle={styles.title}
selectedTitleStyle={styles.selectedTitle}
selected={this.state.selectedTab === 'jokes'}
title="Jokes"
renderIcon={() => <Ionicons name="ios-home-outline" size={px2dp(22)} color="#fffacd" />}
renderSelectedIcon={() => <Ionicons name="ios-home" size={px2dp(22)} color="#1f3a93" />}
onPress={() => this.setState({ selectedTab: 'jokes' })}>
<Joke />
</TabNavigator.Item>
<TabNavigator.Item
titleStyle={styles.title}
selectedTitleStyle={styles.selectedTitle}
selected={this.state.selectedTab === 'fav'}
title="Favorites"
renderIcon={() => <Ionicons name="ios-heart-outline" size={px2dp(22)} color="#fffacd" />}
renderSelectedIcon={() => <Ionicons name="ios-heart" size={px2dp(22)} color="#1f3a93" />}
onPress={() => {
this.setState({ selectedTab: 'fav' })
}}>
<Fav />
</TabNavigator.Item>
</TabNavigator>
</Provider>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFF',
alignItems: 'center',
justifyContent: 'center'
},
tabBar: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1E90FF'
},
title: {
color: '#fffacd'
},
selectedTitle: {
color: '#1f3a93'
}
});