-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ios.js
124 lines (112 loc) · 3.1 KB
/
index.ios.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
'use strict';
let React = require('react-native');
let SocketIO = require('react-native-swift-socketio');
let {
AppRegistry,
SliderIOS,
StyleSheet,
SwitchIOS,
Text,
TouchableOpacity,
View,
} = React;
let ReactJ5 = React.createClass({
getInitialState() {
return {
socket: new SocketIO('192.168.0.3:3000', {}),
state: {status: 'not-connected'},
ledSwtich: false,
value: 0
}
},
componentDidMount() {
this.state.socket.connect();
},
_emitEvent(action, data = {}) {
this.state.socket.emit(action, data);
},
_handleLEDSwitch(value) {
this.setState({ledSwtich: value});
let action = !this.state.ledSwtich ? 'led:on' : 'led:off';
this._emitEvent(action);
},
_handleSlider(value) {
this.setState({value: value});
this._emitEvent('fade', value);
},
_handleColorChange(color) {
switch (color) {
case 'red':
this._emitEvent('colorChange', '#FF0000');
break;
case 'green':
this._emitEvent('colorChange', '#00FF00');
break;
case 'blue':
this._emitEvent('colorChange', '#0000FF');
break;
}
},
render() {
return (
<View style={styles.container}>
<View style={[styles.controlContainer, {marginBottom: 50}]}>
<Text style={styles.welcome}>OFF/ON</Text>
<SwitchIOS
onValueChange={(value) => this._handleLEDSwitch(value)}
style={{marginBottom: 10}}
value={this.state.ledSwtich}/>
</View>
<View style={styles.controlContainer}>
<Text style={styles.welcome}>RGB LED</Text>
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
<TouchableOpacity onPress={() => this._handleColorChange('red')}>
<View style={{width: 75, height: 75, backgroundColor: 'red', margin: 10}}></View>
</TouchableOpacity>
<TouchableOpacity onPress={() => this._handleColorChange('green')}>
<View style={{width: 75, height: 75, backgroundColor: 'green', margin: 10}}></View>
</TouchableOpacity>
<TouchableOpacity onPress={() => this._handleColorChange('blue')}>
<View style={{width: 75, height: 75, backgroundColor: 'blue', margin: 10}}></View>
</TouchableOpacity>
</View>
</View>
<View style={styles.container}>
<Text style={styles.welcome}>FADER</Text>
<SliderIOS
style={styles.slider}
maximumValue={100}
value={100}
onValueChange={(value) => this._handleSlider(value)} />
</View>
</View>
);
}
});
let styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 64,
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
controlContainer: {
alignItems: 'center'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
slider: {
height: 55,
margin: 20,
width: 300
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('ReactJ5', () => ReactJ5);