-
Notifications
You must be signed in to change notification settings - Fork 11
/
App.js
59 lines (55 loc) · 1.28 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
55
56
57
58
59
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {StyleSheet, Text, View, NativeModules, Button} from 'react-native';
export default class App extends Component{
constructor(props) {
super(props);
this.state = { isOn: false };
this.updateStatus();
}
turnOn = () => {
NativeModules.Bulb.turnOn();
this.updateStatus()
}
turnOff = () => {
NativeModules.Bulb.turnOff();
this.updateStatus()
}
updateStatus = () => {
NativeModules.Bulb.getStatus( (error, isOn)=>{
this.setState({ isOn: isOn});
})
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome to Light App!!</Text>
<Text> Bulb is {this.state.isOn ? "ON": "OFF"}</Text>
{!this.state.isOn ? <Button
onPress={this.turnOn}
title="Turn ON "
color="#FF6347"
/> :
<Button
onPress={this.turnOff}
title="Turn OFF "
color="#FF6347"
/> }
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});