-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
122 lines (108 loc) · 3.79 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react"
import { View, AppRegistry, StyleSheet, Text, Navigator } from "react-native";
import WelcomeScreen from "./app/screens/WelcomeScreen"
import CreateNewAccScreen from "./app/screens/CreateNewAccScreen"
import LoginScreen from "./app/screens/LoginScreen"
import HeaderBarWithLeftTouchableIcon from "./app/components/HeaderBarWithLeftTouchableIcon"
import MapNaviScreen from "./app/screens/MapNaviScreen"
import AccountSetupVehicleScreen from "./app/screens/AccountSetupVehicleScreen"
import AccountSetupPaymentScreen from "./app/screens/AccountSetupPaymentScreen"
import VehicleConfigScreen from "./app/screens/VehicleConfigScreen"
import ParkingHistoryScreen from "./app/screens/ParkingHistoryScreen"
import Geolocation from "Geolocation"
class StreetSmart extends Component {
constructor(props){
super(props)
this.state = {
userData: null,
vehicleData: null,
userLocation: null,
lastPosition: null,
}
this._updateUserData = this._updateUserData.bind(this)
this._updateVehicleData = this._updateVehicleData.bind(this)
this._clearData = this._clearData.bind(this)
}
componentWillMount(){
Geolocation.getCurrentPosition(
(position) => {
let latLon = { latitude:position.coords.latitude,
longitude:position.coords.longitude}
this.setState({ userLocation: latLon })
},
(error) => {
alert(error.message)
this.setState({
userLocation: {
latitude:1.3594206,
longitude:103.8066663
}})
},
// {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
)
this.watchID = Geolocation.watchPosition((position) => {
var lastPosition = JSON.stringify(position);
this.setState({lastPosition});
})
}
_updateUserData(userData){
this.setState({ userData })
}
_updateVehicleData(vehicleData){
this.setState({ vehicleData })
}
_clearData(){
this._updateUserData(null)
this._updateVehicleData(null)
}
_renderScene(route, navigator){
var globalNavigatorProps = { navigator }
switch(route.identifier){
case "WelcomeScreen":
return <WelcomeScreen {...globalNavigatorProps}/>
case "CreateNewAccScreen":
return <CreateNewAccScreen {...globalNavigatorProps}/>
case "LoginScreen":
return <LoginScreen {...globalNavigatorProps}/>
case "MapNaviScreen":
return <MapNaviScreen {...globalNavigatorProps}/>
case "AccountSetupVehicleScreen":
return <AccountSetupVehicleScreen {...globalNavigatorProps}/>
case "AccountSetupPaymentScreen":
return <AccountSetupPaymentScreen {...globalNavigatorProps}/>
case "VehicleConfigScreen":
return <VehicleConfigScreen {...globalNavigatorProps}/>
case "ParkingHistoryScreen":
return <ParkingHistoryScreen parkingHistoryData={route.parkingHistoryData} {...globalNavigatorProps}/>
default:
return <View style={{flex:1, color:"red"}}/>
}
}
render() {
return (
<Navigator
initialRoute = {{identifier: "WelcomeScreen"}}
ref="appNavigator"
userData = {this.state.userData}
vehicleData = {this.state.vehicleData}
userLocation = {this.state.userLocation}
updateUserData={this._updateUserData}
updateVehicleData={this._updateVehicleData}
clearData={this._clearData}
style={styles.navigatorStyles}
renderScene={this._renderScene}
configureScene={(route)=> ({
...route.sceneConfig || Navigator.SceneConfigs.PushFromRight})} />
)
}
}
const styles = StyleSheet.create({
navigatorStyles:{
}
})
AppRegistry.registerComponent("StreetSmart", () => StreetSmart);