-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
54 lines (54 loc) · 1.45 KB
/
App.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
import React, { Component } from "react";
import { Text, View, Image, SafeAreaView } from "react-native";
import Button from "./src/components/Button";
export default class HelloWorldApp extends Component {
constructor() {
super();
this.state = {
uri: require(`./src/Images/dice1.png`)
};
}
//Method to get random value from 1 to 6
getRandomValue = () => {
return Math.floor(Math.random() * 6) + 1;
};
//Method will call on button press
playButtonPressed = () => {
let ranNumber = this.getRandomValue();
switch (ranNumber) {
case 1:
this.setState({ uri: require(`./src/Images/dice1.png`) });
break;
case 2:
this.setState({ uri: require(`./src/Images/dice2.png`) });
break;
case 3:
this.setState({ uri: require(`./src/Images/dice3.png`) });
break;
case 4:
this.setState({ uri: require(`./src/Images/dice4.png`) });
break;
case 5:
this.setState({ uri: require(`./src/Images/dice5.png`) });
break;
case 6:
this.setState({ uri: require(`./src/Images/dice6.png`) });
break;
}
};
render() {
return (
<View
style={{
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#E74292"
}}
>
<Image source={this.state.uri} />
<Button text="Roll It!" onPress={this.playButtonPressed} />
</View>
);
}
}