-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
224 lines (196 loc) · 5.94 KB
/
App.js
File metadata and controls
224 lines (196 loc) · 5.94 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import React, { Component } from 'react'
import {
View,
TouchableOpacity,
Button,
StatusBar,
Image
} from 'react-native'
import styles from './Public/appStyle'
import {
ViroVRSceneNavigator,
ViroARSceneNavigator,
ViroUtils
} from 'react-viro'
import QRScanner from './components/qrScanner'
import InitialARScene from './components/cardWithAR'
import InitialVRScene from './components/cardWithVR'
const isARSupportedOnDevice = ViroUtils.isARSupportedOnDevice
// Insert your API key below!
var sharedProps = {
apiKey: '53F859C6-0996-417C-8CC3-CDDF2775C41C'
}
// Sets the default scene you want for AR and VR
// const InitialARScene = require('./components/cardWithAR')
// const InitialVRScene = require('./components/cardWithVR')
const GET_WELCOME_SCREEN = 'GET_WELCOME_SCREEN'
const GET_SCAN_A_CARD = 'GET_SCAN_A_CARD'
const NO_AR_SUPPORT = 'NO_AR_SUPPORT'
const QR_SCANNER = 'QR_SCANNER'
const SELECT_AR_OR_VR = 'SELECT_AR_OR_VR'
const VR_NAVIGATOR_TYPE = 'VR'
const AR_NAVIGATOR_TYPE = 'AR'
const defaultNavigatorType = GET_WELCOME_SCREEN
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
navigatorType: defaultNavigatorType,
sharedProps: sharedProps
}
this._getWelcomeScreen = this._getWelcomeScreen.bind(this)
this._getScanACardScreen = this._getScanACardScreen.bind(this)
this._getNonARSCanQRScreen = this._getNonARSCanQRScreen.bind(this)
this._getQRScanner = this._getQRScanner.bind(this)
this._getExperienceSelector.bind(this)
this._getARNavigator = this._getARNavigator.bind(this)
this._getVRNavigator = this._getVRNavigator.bind(this)
this._getExperienceButtonOnPress = this._getExperienceButtonOnPress.bind(this)
this._exitViro = this._exitViro.bind(this)
}
componentDidMount() {
setTimeout(() => {
this.setState({
navigatorType: GET_SCAN_A_CARD
})
}, 3000)
}
render() {
if (this.state.navigatorType === GET_WELCOME_SCREEN) {
return this._getWelcomeScreen()
} else if (this.state.navigatorType === GET_SCAN_A_CARD) {
return this._getScanACardScreen()
} else if (this.state.navigatorType === NO_AR_SUPPORT) {
return this._getNonARSCanQRScreen()
} else if (this.state.navigatorType === QR_SCANNER) {
return this._getQRScanner()
} else if (this.state.navigatorType === SELECT_AR_OR_VR) {
return this._getExperienceSelector()
} else if (this.state.navigatorType === AR_NAVIGATOR_TYPE) {
return this._getARNavigator()
} else if (this.state.navigatorType === VR_NAVIGATOR_TYPE) {
return this._getVRNavigator()
}
}
_getWelcomeScreen() {
return (
<View style={styles.container}>
<StatusBar hidden = {true} />
<Image
style={styles.welcome}
source={require('./assets/forScreens/welcome.jpg')}
/>
<Image
style={styles.centerLogo}
source={require('./assets/forScreens/cARd-logo.jpg')}
/>
</View>
)
}
_getScanACardScreen() {
return (
<View style={styles.container}>
<StatusBar
barStyle="dark-content"
hidden={false}
backgroundColor="#fff"
translucent={false}
networkActivityIndicatorVisible={true}
/>
<TouchableOpacity
onPress={ () => isARSupportedOnDevice(
() => this.setState({ navigatorType: NO_AR_SUPPORT}),
() => this.setState({ navigatorType: QR_SCANNER})
)}>
<Image
style={styles.scanButton}
source={require('./assets/forScreens/scanQR.jpg')}
/>
</TouchableOpacity>
</View>
)
}
_getNonARSCanQRScreen() {
return (
<React.Fragment>
<QRScanner />
<Button
style={styles.enterBarcodeManualButton}
title="Go to VR View"
onPress={this._getExperienceButtonOnPress(VR_NAVIGATOR_TYPE)}
/>
</React.Fragment>
)
}
_getQRScanner() {
return (
<React.Fragment>
<QRScanner />
<Button
style={styles.enterBarcodeManualButton}
title="Go Select AR/VR"
onPress={this._getExperienceButtonOnPress(SELECT_AR_OR_VR)}
/>
</React.Fragment>
)
}
_getExperienceSelector() {
return (
<View style={styles.container}>
<Image
style={styles.selectMessage}
source={require('./assets/forScreens/selectAROrVR.jpg')}
/>
<View style={styles.inner}>
<TouchableOpacity onPress={this._getExperienceButtonOnPress(AR_NAVIGATOR_TYPE)}>
<Image
style={styles.ARVRButton}
source={require('./assets/forScreens/AR.jpg')}
/>
</TouchableOpacity>
<TouchableOpacity onPress={this._getExperienceButtonOnPress(VR_NAVIGATOR_TYPE)}>
<Image
style={styles.ARVRButton}
source={require('./assets/forScreens/VR.jpg')}
/>
</TouchableOpacity>
</View>
</View>
)
}
// Returns the ViroARSceneNavigator which will start the AR experience
_getARNavigator() {
return (
<ViroARSceneNavigator
{...this.state.sharedProps}
initialScene={{ scene: InitialARScene }}
onExitViro={this._exitViro}
/>
)
}
// Returns the ViroSceneNavigator which will start the VR experience
_getVRNavigator() {
return (
<ViroVRSceneNavigator
{...this.state.sharedProps}
initialScene={{ scene: InitialVRScene }}
onExitViro={this._exitViro}
/>
)
}
// This function returns an anonymous/lambda function to be used
// by the experience selector buttons
_getExperienceButtonOnPress(navigatorType) {
return () => {
this.setState({
navigatorType: navigatorType
})
}
}
// This function "exits" Viro by setting the navigatorType to UNSET.
_exitViro() {
this.setState({
navigatorType: SELECT_AR_OR_VR
})
}
}