forked from austinzheng/iOS-2048
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (76 loc) · 1.95 KB
/
index.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
import React from 'react';
import moment from 'moment';
import {FlatList, AppRegistry, StyleSheet, Text, View, Button, NativeModules} from 'react-native';
class RNHighScores extends React.Component {
constructor(props) {
super(props);
this.state = {
scores: props.scores
};
this._exitButtonPressed = this._exitButtonPressed.bind(this);
this._clearButtonPressed = this._clearButtonPressed.bind(this);
}
_exitButtonPressed() {
NativeModules.F3HBridgeModule.exitHighScoreButtonTapped(this.state.scores)
}
_clearButtonPressed() {
this.setState({
scores: []
})
}
render() {
var scores = this.state.scores;
var scores = scores.map((score) => {
score['key'] = score['createdAt'];
return score;
})
var contents = (scores.length > 0) ?
<FlatList
data={scores}
renderItem={(({item}) => {
return <Text style={styles.item}>{moment(item.createdAt).format('MM/DD/YY hh:mm:ss A')} - {item.value}</Text>
})}
/>
:
<Text>No scores yet!</Text>
;
return (
<View style={styles.container}>
<Text style={styles.highScoresTitle}>2048 High Scores!</Text>
{contents}
<Button title={'Clear'} onPress={this._clearButtonPressed}>
<Text>Clear</Text>
</Button>
<Button title={'Exit'} onPress={this._exitButtonPressed}>
<Text>Exit</Text>
</Button>
</View>
);
}
}
const styles = StyleSheet.create({
item: {
textAlign: 'left',
backgroundColor: '#DDD',
fontSize: 20,
marginBottom: 5
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'stretch',
backgroundColor: '#FFFFFF',
},
highScoresTitle: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
scores: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
// Module name
AppRegistry.registerComponent('RNHighScores', () => RNHighScores);