-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.android.js
88 lines (78 loc) · 1.77 KB
/
index.android.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
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Navigator,
} from 'react-native'
import StartScreen from './StartScreen'
import QuoteScreen from './QuoteScreen'
const { quotes } = require('./quotes.json')
class RelaxationStation extends Component {
constructor(props) {
super(props)
this.state = {
quoteIndex: 3,
}
this._incrementQuoteIndex = this._incrementQuoteIndex.bind(this)
}
_incrementQuoteIndex() {
let newIndex
if (this.state.quoteIndex + 1 === quotes.length) {
newIndex = 0
} else {
newIndex = this.state.quoteIndex + 1
}
this.setState({
quoteIndex: newIndex,
})
}
render() {
const quote = quotes[this.state.quoteIndex]
return (
<Navigator
initialRoute={{ name: 'StartScreen' }}
renderScene={(route, navigator) => {
switch (route.name) {
case 'StartScreen':
return <StartScreen onStartHandler={() => navigator.push({ name: 'QuoteScreen' })} />
case 'QuoteScreen':
return (
<QuoteScreen
qId={this.state.quoteIndex}
text={quote.text}
source={quote.source}
onNextQuotePress={this._incrementQuoteIndex}
/>)
}
}}
/>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#efefef',
},
readyText: {
fontSize: 20,
fontStyle: 'italic',
color: '#ffffff',
},
button: {
backgroundColor: '#859a9b',
borderRadius: 20,
padding: 10,
marginBottom: 20,
// On Android we can't use the ShadowPropTypesIOS styles used in the course,
// so instead we rely on the very similar elevation property.
elevation: 2,
},
buttonImage: {
width: 200,
height: 200,
},
})
AppRegistry.registerComponent('RelaxationStation', () => RelaxationStation)