-
Notifications
You must be signed in to change notification settings - Fork 14
/
LogicScreen.js
180 lines (175 loc) · 4.16 KB
/
LogicScreen.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
Switch,
Button,
TouchableOpacity,
Animated,
Image,
Easing,
ScrollView,
Dimensions,
TextInput
} from "react-native";
import BlocklyScreen from "./BlocklyScreen";
export default class LogicScreen extends Component<{}> {
state = {
showBlocklyScreen: false,
xml: "",
logicKey: "",
states: this.props.states
};
_renderBlocklyScreen() {
if (!this.state.showBlocklyScreen) return null;
return (
<View style={styles.overlay}>
<BlocklyScreen
logicKey={this.state.logicKey}
xml={this.state.xml}
onBack={() => this.setState({ showBlocklyScreen: false })}
onSave={(logicKey, code, xml) => {
this.setState({
showBlocklyScreen: false
});
this.props.onSaveLogic(logicKey, code, xml);
}}
states={this.state.states}
/>
</View>
);
}
render() {
const eventKeys = Object.keys(this.props.logics);
const events = eventKeys.map(key => {
return this.props.logics[key];
});
return (
<View style={styles.container}>
<ScrollView style={{ flex: 1 }}>
<View style={styles.divider}>
<Text style={styles.dividerText}>Events</Text>
<TouchableOpacity style={styles.buttonAdd}>
<Image
style={styles.buttonAddIcon}
source={require("AppSense/assets/add.png")}
/>
</TouchableOpacity>
</View>
{events.map((event, i) => {
return (
<TouchableOpacity
key={i}
style={styles.item}
onPress={() =>
this.setState({
showBlocklyScreen: true,
xml: event.xml,
logicKey: event.name
})}
>
<View style={styles.itemWrapper}>
<View style={styles.itemIconWrapper}>
<View style={styles.itemIcon} />
</View>
<View style={styles.item}>
<Text style={styles.itemTitleText}>{event.name}</Text>
<Text style={styles.itemDescText}>{event.description}</Text>
</View>
</View>
</TouchableOpacity>
);
})}
{/* <TouchableOpacity style={styles.item}>
<View style={styles.itemWrapper}>
<View style={styles.itemIconWrapper}>
<View style={styles.itemIcon} />
</View>
<View style={styles.item}>
<Text style={styles.itemTitleText}>Button 1: onPress</Text>
<Text style={styles.itemDescText}>Button 1 onPress event.</Text>
</View>
</View>
</TouchableOpacity> */}
</ScrollView>
{this._renderBlocklyScreen()}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
scroll: {
flex: 1
},
divider: {
backgroundColor: "#fff",
flexDirection: "row",
alignItems: "center",
paddingHorizontal: 15
},
dividerText: {
flex: 1,
color: "#555",
fontWeight: "500"
},
buttonAdd: {
width: 40,
height: 40,
alignItems: "center",
justifyContent: "center"
},
buttonAddIcon: {
width: 23,
height: 23,
tintColor: "#555"
},
item: {
height: 80
},
itemWrapper: {
height: 80,
flexDirection: "row",
alignItems: "center"
},
itemIconWrapper: {
width: 60,
height: 60,
alignItems: "center",
justifyContent: "center"
},
itemIcon: {
width: 30,
height: 30,
backgroundColor: "#999",
borderRadius: 20,
marginHorizontal: 10
},
item: {
flex: 1
},
itemTitleText: {
color: "#000",
fontSize: 15,
fontWeight: "500"
},
overlay: {
zIndex: 10,
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0,
elevation: 5,
backgroundColor: "#fff"
}
});