Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion game.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
TouchableHighlight,
AsyncStorage,
} from 'react-native';

import AwesomeAlert from 'react-native-awesome-alerts';

const STORAGE_KEY = '@Game:data';
var timeLimit=10;
var timer = null;
Expand All @@ -36,6 +39,7 @@ export default class Game extends Component {
currentScore: 0,
timeout: 0,
playing: false,
showAlert: false,
holes: [false, false, false,
false, false, false,
false, false, false]
Expand Down Expand Up @@ -97,7 +101,8 @@ export default class Game extends Component {
playing: false,
})
if(this.state.currentScore>this.state.highScore){
alert('YEAH! you got a new high score');
// alert('YEAH! you got a new high score');
this._showAlert();
this.setState({
highScore: ""+this.state.currentScore,
})
Expand All @@ -113,6 +118,18 @@ export default class Game extends Component {
.done();
}

_showAlert = () => {
this.setState({
showAlert: true
});
};

_hideAlert = () => {
this.setState({
showAlert: false
});
};

componentDidMount(){
AsyncStorage.getItem(STORAGE_KEY)
.then((value)=>{
Expand All @@ -124,6 +141,8 @@ export default class Game extends Component {
}

render() {
const { showAlert } = this.state;

return (
<View style={styles.container}>
<View style={styles.topBar}>
Expand Down Expand Up @@ -181,6 +200,21 @@ export default class Game extends Component {
onPress={this._startGame.bind(this)}
disabled={this.state.playing}/>
</View>
<AwesomeAlert
show={showAlert}
showProgress={false}
title="Alert"
message="YEAH! you got a new high score"
closeOnTouchOutside={true}
closeOnHardwareBackPress={false}
showCancelButton={false}
showConfirmButton={true}
confirmText="Yes"
confirmButtonColor="#b7eb8f"
onConfirmPressed={() => {
this._hideAlert();
}}
/>
</View>
);
}
Expand Down
40 changes: 2 additions & 38 deletions index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,6 @@ import {
View
} from 'react-native';

export default class testapp extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
import Game from './game.js';

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('testapp', () => testapp);
AppRegistry.registerComponent('Game', () => Game);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.46.4"
"react-native": "0.46.4",
"react-native-awesome-alerts": "^1.0.7"
},
"devDependencies": {
"babel-jest": "20.0.3",
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4464,6 +4464,12 @@ [email protected]:
shell-quote "^1.6.1"
ws "^2.0.3"

react-native-awesome-alerts@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/react-native-awesome-alerts/-/react-native-awesome-alerts-1.0.7.tgz#60344ab2044b994b77a9fc95f612b8347e31d1d6"
dependencies:
prop-types "^15.5.10"

react-native-scripts@^1.11.1:
version "1.11.1"
resolved "https://registry.yarnpkg.com/react-native-scripts/-/react-native-scripts-1.11.1.tgz#a9f0a5c91a85d34acee9ec9012cf614665670b80"
Expand Down