3
3
* https://HelperNet.github.io
4
4
*/
5
5
6
- var React = require ( 'react-native' ) ;
7
- var _ = require ( 'lodash' ) ;
8
- var RCTDeviceEventEmitter = require ( 'RCTDeviceEventEmitter' ) ;
9
- var Subscribable = require ( 'Subscribable' ) ;
6
+ var React = require ( 'react-native' )
7
+ var _ = require ( 'lodash' )
8
+ var RCTDeviceEventEmitter = require ( 'RCTDeviceEventEmitter' )
9
+ var Subscribable = require ( 'Subscribable' )
10
+ var styles = require ( './stylesheet' )
10
11
11
12
var {
12
13
AppRegistry,
13
- StyleSheet,
14
14
Text,
15
15
TextInput,
16
16
View,
@@ -51,16 +51,16 @@ var HelperNet = React.createClass({
51
51
52
52
componentWillMount ( ) {
53
53
if ( this . state . enabled ) {
54
- NativeModules . P2PKit . enable ( ) ;
54
+ NativeModules . P2PKit . enable ( )
55
55
}
56
56
57
57
this . addListenerOn ( RCTDeviceEventEmitter ,
58
58
'aroundCountChanged' ,
59
- this . handleAroundChange ) ;
59
+ this . handleAroundChange )
60
60
61
61
this . addListenerOn ( RCTDeviceEventEmitter ,
62
62
'emergencyReceived' ,
63
- this . handleEmergencyReceived ) ;
63
+ this . handleEmergencyReceived )
64
64
65
65
this . addListenerOn ( RCTDeviceEventEmitter ,
66
66
'location' ,
@@ -76,10 +76,10 @@ var HelperNet = React.createClass({
76
76
} ,
77
77
78
78
componentDidMount ( ) {
79
- _ . forEach ( _ . keys ( this . state ) , ( key ) => {
80
- AsyncStorage . getItem ( key )
81
- . then ( ( value ) => { console . log ( "load key, value: " , key , value ) ; this . setState ( { key : value } ) } )
82
- } ) ;
79
+ // _.forEach(_.keys(this.state), (key) => {
80
+ // AsyncStorage.getItem(key)
81
+ // .then((value) => {console.log("load key, value: ", key, value); this.setState({key: value})})
82
+ // });
83
83
} ,
84
84
85
85
componentDidUpdate ( prevProps , prevState ) {
@@ -92,22 +92,23 @@ var HelperNet = React.createClass({
92
92
} ,
93
93
94
94
getLocation ( ) {
95
+ // TODO: where does navigator come from?
95
96
navigator . geolocation . getCurrentPosition (
96
97
( initialPosition ) => this . setState ( { location : initialPosition } ) ,
97
98
( error ) => alert ( error . message ) ,
98
99
{ enableHighAccuracy : true , timeout : 20000 , maximumAge : 1000 }
99
- ) ;
100
+ )
100
101
} ,
101
102
102
103
handleAroundChange ( event ) {
103
- this . setState ( { aroundCount : event . newCount } ) ;
104
+ this . setState ( { aroundCount : event . newCount } )
104
105
} ,
105
106
106
107
handleEmergencyReceived ( event ) {
107
108
this . setState ( {
108
109
receivedEmergency : true ,
109
110
receivedEmergencyText : event . message
110
- } ) ;
111
+ } )
111
112
} ,
112
113
113
114
handleLocationReceived ( event ) {
@@ -116,7 +117,7 @@ var HelperNet = React.createClass({
116
117
lat : event . lat ,
117
118
lng : event . lng
118
119
}
119
- } ) ;
120
+ } )
120
121
} ,
121
122
122
123
sendMessage ( ) {
@@ -128,49 +129,49 @@ var HelperNet = React.createClass({
128
129
} ,
129
130
130
131
resetMessage ( ) {
131
- NativeModules . P2PKit . resetMessage ( ) ;
132
+ NativeModules . P2PKit . resetMessage ( )
132
133
} ,
133
134
134
135
directTo ( ) {
135
- const { lat, lng } = this . state . location ;
136
- NativeModules . P2PKit . directTo ( 47.3897774 , 8.5164106 , lat , lng ) ;
136
+ const { lat, lng } = this . state . location
137
+ NativeModules . P2PKit . directTo ( 47.3897774 , 8.5164106 , lat , lng )
137
138
} ,
138
139
//
139
140
// handleEnabledChanged(isEnabled) {
140
- // this.setState({isEnabled: isEnabled});
141
+ // this.setState({isEnabled: isEnabled})
141
142
// if (isEnabled) {
142
- // NativeModules.P2PKit.enable();
143
+ // NativeModules.P2PKit.enable()
143
144
// } else {
144
- // NativeModules.P2PKit.disable();
145
+ // NativeModules.P2PKit.disable()
145
146
// }
146
147
// },
147
148
148
149
handleEmergencyClick ( ) {
149
150
if ( this . state . emergency ) {
150
- this . resetMessage ( ) ;
151
- this . setState ( { emergency : false } ) ;
151
+ this . resetMessage ( )
152
+ this . setState ( { emergency : false } )
152
153
} else {
153
154
if ( this . state . callEmergencyAutomatically ) {
154
- NativeModules . P2PKit . phoneCall ( this . state . number ) ;
155
+ NativeModules . P2PKit . phoneCall ( this . state . number )
155
156
}
156
- this . sendMessage ( ) ;
157
- this . setState ( { emergency : true } ) ;
157
+ this . sendMessage ( )
158
+ this . setState ( { emergency : true } )
158
159
}
159
160
} ,
160
161
161
162
showSettings ( ) {
162
- this . setState ( { showSettings : true } ) ;
163
+ this . setState ( { showSettings : true } )
163
164
} ,
164
165
165
166
hideSettings ( ) {
166
- this . setState ( { showSettings : false } ) ;
167
+ this . setState ( { showSettings : false } )
167
168
} ,
168
169
169
170
dismissModal ( ) {
170
- this . setState ( { receivedEmergency : false } ) ;
171
+ this . setState ( { receivedEmergency : false } )
171
172
} ,
172
173
173
- accept ( ) {
174
+ acceptEmergencyCall ( ) {
174
175
this . directTo ( ) ;
175
176
NativeModules . P2PKit . setMessage ( `OT` ) ;
176
177
} ,
@@ -179,19 +180,28 @@ var HelperNet = React.createClass({
179
180
180
181
const settingsView =
181
182
< SettingsView
182
- />
183
+ hideSettings = { this . hideSettings }
184
+ onChangeNumber = { number => this . setState ( { number} ) }
185
+ phoneNumber = { this . state . number }
186
+ shouldCallEmergencyAutomatically = { this . state . callEmergencyAutomatically }
187
+ onChangeShouldCallEmergencyAutomatically = { callEmergencyAutomatically => this . setState ( { callEmergencyAutomatically} ) }
188
+ emergencyText = { this . state . emergencyText }
189
+ onChangeEmergencyText = { emergencyText => this . setState ( { emergencyText} ) } />
183
190
184
191
const emergencyView =
185
192
< EmergencyView
186
- />
187
-
188
- return this . state . showSettings ? settingsView : emergencyView ;
193
+ showSettings = { this . showSettings }
194
+ isEmergency = { this . state . emergency }
195
+ receivedEmergency = { this . state . receivedEmergency }
196
+ aroundCount = { this . state . aroundCount }
197
+ handleEmergencyClick = { this . handleEmergencyClick }
198
+ receivedEmergencyText = { this . state . receivedEmergencyText }
199
+ onAcceptEmergencyCall = { this . acceptEmergencyCall }
200
+ onDismissEmergencyCall = { this . dismissModal } />
201
+
202
+ return this . state . showSettings ? settingsView : emergencyView ;
189
203
}
190
- } ) ;
191
-
192
-
193
-
194
-
204
+ } )
195
205
196
206
// <View style={styles.switchContainer}>
197
207
// <Text style={styles.label}>
@@ -206,182 +216,4 @@ var HelperNet = React.createClass({
206
216
// tintColor='ff0000' />
207
217
// </View>
208
218
209
-
210
- var styles = StyleSheet . create ( {
211
- rootContainer : {
212
- flex : 1
213
- } ,
214
- toolbar : {
215
- backgroundColor : '#303F9F' ,
216
- paddingTop : 10 ,
217
- paddingBottom : 10 ,
218
- // height: 50,
219
- flexDirection : 'row' ,
220
- justifyContent : 'space-between'
221
- } ,
222
- backButton : {
223
- height : 30 ,
224
- width : 30
225
- } ,
226
- backButtonTouch : {
227
- flex : 1
228
- } ,
229
- toolbarTitle : {
230
- width : 100 ,
231
- flex : 1 ,
232
- color : '#fff' ,
233
- textAlign : 'center' ,
234
- fontWeight : 'bold' ,
235
- fontSize : 20
236
- } ,
237
- spaceView : {
238
- flex : 1
239
- } ,
240
- scrollContainer : {
241
- padding : 20 ,
242
- backgroundColor : '#F5FCFF' ,
243
- } ,
244
- // emergencyReceivedContainer: {
245
- // marginBottom: 15,
246
- // borderColor: '#e70000',
247
- // borderWidth: 3,
248
- // borderRadius: 8,
249
- // padding: 10
250
- // },
251
- numberContainer : {
252
- // padding: 10
253
- } ,
254
- numberText : {
255
- fontSize : 20 ,
256
- marginTop : 10
257
- } ,
258
- switchContainer : {
259
- marginTop : 10 ,
260
- flexDirection : 'row' ,
261
- justifyContent : 'space-between'
262
- } ,
263
- label : {
264
-
265
- } ,
266
- switch : {
267
- marginBottom : 10
268
- } ,
269
- button : {
270
- height : 65 ,
271
- // flex: 1,
272
- flexDirection : 'row' ,
273
- backgroundColor : '#e70000' ,
274
- borderColor : '#e70000' ,
275
- borderWidth : 1 ,
276
- borderRadius : 8 ,
277
- marginTop : 10 ,
278
- alignSelf : 'stretch' ,
279
- justifyContent : 'center'
280
- } ,
281
- buttonText : {
282
- color : '#fff' ,
283
- fontWeight : 'bold' ,
284
- fontSize : 20 ,
285
- marginTop : 17
286
- } ,
287
- aroundCountContainer : {
288
- padding : 20 ,
289
- justifyContent : 'center' ,
290
- flex : 1 ,
291
- alignItems : 'center' ,
292
- flexDirection : 'column' ,
293
- } ,
294
- aroundCountText : {
295
- flex : 1 ,
296
- textAlign : 'center' ,
297
- fontSize : 17 ,
298
- marginBottom : 110 ,
299
- color : '#fff' ,
300
- fontWeight : 'bold' ,
301
- } ,
302
- copyrightText : {
303
- flex : 1 ,
304
- marginBottom : 10
305
- } ,
306
- backgroundContainer : {
307
- backgroundColor : '#303F9F' ,
308
- flex : 1 ,
309
- } ,
310
- touchableSettingsIcon : {
311
- // position: 'absolute',
312
- // right: 10,
313
- // top: 10
314
- flex : 1
315
- } ,
316
- settingsIcon : {
317
- width : 40 ,
318
- height : 40 ,
319
- // position: 'relative',
320
- // right: 0
321
- alignSelf : 'flex-end' ,
322
- marginRight : 10
323
-
324
- } ,
325
- emergencyReceivedContainer : {
326
- right : 0 ,
327
- left : 0 ,
328
- margin : 15 ,
329
- padding : 10 ,
330
- height : 170 ,
331
- position : 'absolute' ,
332
- marginTop : 150 ,
333
- borderRadius : 5 ,
334
- backgroundColor : '#f10000'
335
- } ,
336
- emergencyReceivedText : {
337
- fontSize : 20 ,
338
- color : '#fff'
339
- } ,
340
- emergencyReceivedButton : {
341
- padding : 5 ,
342
- backgroundColor : '#a90b1d' ,
343
- borderRadius : 3
344
- } ,
345
- emergencyReceivedButtonText : {
346
- fontSize : 20 ,
347
- color : '#fff'
348
- } ,
349
- buttonGroup : {
350
- flex : 1 ,
351
- flexDirection : 'row' ,
352
- marginTop : 10 ,
353
- justifyContent : 'space-between'
354
- } ,
355
- buttonWrapper : {
356
- flex : 1 ,
357
- justifyContent : 'center' ,
358
- flexDirection : 'row' ,
359
- marginTop : 110
360
- } ,
361
- emergencyButton : {
362
- width : 180 ,
363
- height : 180 ,
364
- borderRadius : 200 ,
365
- backgroundColor : '#F50057' ,
366
- justifyContent : 'center' ,
367
- flexDirection : 'column' ,
368
- } ,
369
- emergencyButtonText : {
370
- color : '#fff' ,
371
- fontSize : 25 ,
372
- textAlign : 'center' ,
373
- fontWeight : 'bold'
374
- } ,
375
- circlesWrapper : {
376
- justifyContent : 'center' ,
377
- } ,
378
- circles : {
379
- height : 550 ,
380
- width : 550 ,
381
- position : 'absolute' ,
382
- bottom : - 160 ,
383
- right : - 90
384
- }
385
- } ) ;
386
-
387
- AppRegistry . registerComponent ( 'HelperNet' , ( ) => HelperNet ) ;
219
+ AppRegistry . registerComponent ( 'HelperNet' , ( ) => HelperNet )
0 commit comments