-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathindex.ios.js
145 lines (132 loc) · 3.91 KB
/
index.ios.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Navigator,
NetInfo
} from 'react-native';
import MainScene from './app/components/mainScene'
import WordFeed from './app/components/words'
import Search from './app/components/search'
import NoConnection from './app/components/noInternet'
export default class UrbanDictionary extends Component {
state = {
isNetworkConnected: false
}
componentDidMount(){
NetInfo.isConnected.addEventListener('change', this.handleConnectionChange);
NetInfo.isConnected.fetch().then(isConnected =>{
{this.setState({ status: isConnected });}
});
console.log('component did mount')
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('change', this.handleConnectionChange);
}
handleConnectionChange = (isConnected) => {
this.setState({ isNetworkConnected: isConnected });
console.log(`is connected: ${isConnected}`);
}
render() {
if (this.state.isNetworkConnected === false){
return(<NoConnection />);
}else{
return (
<Navigator
initialRoute={{ title: 'Main', index: 0 }}
configureScene={(route, routeStack) => {
if(route.title === 'Search'){
return Navigator.SceneConfigs.FloatFromBottom
}else{
return Navigator.SceneConfigs.FloatFromRight
}
}}
renderScene={(route, navigator) => {
if(route.title === 'Main'){
return (
<MainScene navigator={navigator}
onPresentSearch={() => {
navigator.push({
title:'Search'
});
}}
/>);
}
if(route.title === 'WoTD'){
return(
<WordFeed
title={route.search}
feedURL={'https://api.urbandictionary.com/v0/define?term='+route.search}
onBack={() => {
navigator.pop()
}}
/>
);
}
if(route.title === 'WoTD_2'){
return(
<WordFeed
title={'Word of the Day'}
feedURL={'https://api.urbandictionary.com/v0/words_of_the_day'}
onBack={() => {
navigator.pop()
}}
/>
);
}
if(route.title === 'Random'){
return(
<WordFeed
title={'Random'}
feedURL={'https://api.urbandictionary.com/v0/random'}
onBack={() => {
navigator.pop()
}}
/>
);
}
if(route.title === 'Search'){
return(
<Search
navigator={navigator}
title={'Search'}
title={'Random'}
onBack={() => {
navigator.pop()
}}
/>
);
}
}
}
/>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('UrbanDictionary', () => UrbanDictionary);