-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.js
42 lines (40 loc) · 1.15 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
import React, { Component } from "react";
import { AppRegistry, Text, View, StatusBar, Button } from "react-native";
export default class BlinkApp extends Component {
constructor(props) {
super(props);
this.state = {
buttonText: "blink",
ifBlink: false,
showText: true,
text: "I love blinking"
};
this.toggleBlinkState = this.toggleBlinkState.bind(this);
var handle;
}
toggleBlinkState() {
if (this.state.buttonText == "blink") {
handle = setInterval(() => {
this.setState(previousState => {
return { showText: !previousState.showText };
});
}, 1000);
this.setState({
buttonText: "Stop blinking"
});
} else {
clearInterval(handle);
this.setState({ buttonText: "blink", showText: true });
}
}
render() {
let display = this.state.showText ? this.state.text : " ";
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<StatusBar hidden={true} />
<Text>{display} </Text>
<Button onPress={this.toggleBlinkState} title={this.state.buttonText} />
</View>
);
}
}