forked from thomaspark/flexboxfroggy
-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.js
86 lines (73 loc) · 1.83 KB
/
main.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
import React, {
AppRegistry,
StyleSheet,
View,
Component,
Navigator
} from "react-native";
import Play from "./js/play"
import Home from "./js/home"
import levels from "./js/levels"
import docs from "./js/docs"
import messages from "./js/messages"
import colors from "./js/colors"
var KeyboardSpacer = require('react-native-keyboard-spacer');
let routes = {
home: {component: Home},
play: {component: Play}
}
function renderScene(Comp, language, level, onLanguageChange, onGoToGame, onGoToLevel, onGoToHome) {
return (
<Comp
language={language}
level={level}
onLanguageChange={onLanguageChange}
onGoToHome={onGoToHome}
onGoToGame={onGoToGame}
onGoToLevel={onGoToLevel}
/>
);
}
class FlexboxFroggy extends Component {
constructor(props) {
super(props)
this.state = {
language: 'en'
}
}
render() {
let onLanguageChange = (language) => this.setState({language});
let onGoToGame = () => this.refs.navigator.push(routes.play)
let onGoToHome = () => {
this.refs.navigator.immediatelyResetRouteStack([]);
this.refs.navigator.push(routes.home);
}
let onGoToLevel = (level) => this.refs.navigator.push(
{
...routes.play,
level
}
)
return (
<View style={styles.container}>
<Navigator
ref="navigator"
style={styles.spacer}
initialRoute={routes.home}
renderScene={route => renderScene(route.component, this.state.language, route.level, onLanguageChange, onGoToGame, onGoToLevel, onGoToHome)}
/>
<KeyboardSpacer />
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: colors.green
},
spacer: {
marginTop: 32
}
});
AppRegistry.registerComponent('main', () => FlexboxFroggy);