-
Notifications
You must be signed in to change notification settings - Fork 46
/
App.js
144 lines (124 loc) · 4.19 KB
/
App.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
import React, { Component } from 'react';
import {
AppRegistry,
ActivityIndicator,
Text,
View,
StyleSheet,
TouchableHighlight,
Image,
Alert,
} from 'react-native';
import {
ViroARSceneNavigator
} from 'react-viro';
import renderIf from './js/helpers/renderIf';
var InitialARScene = require('./js/ARHitTestSample');
// Array of 3d models that we use in this sample. This app switches between this these models.
var objArray = [
require('./js/res/coffee_mug/object_coffee_mug.vrx'),
require('./js/res/object_flowers/object_flowers.vrx'),
require('./js/res/emoji_smile/emoji_smile.vrx')];
export default class ViroSample extends Component {
constructor() {
super();
this._onShowObject = this._onShowObject.bind(this);
this._renderTrackingText = this._renderTrackingText.bind(this);
this._onTrackingInit = this._onTrackingInit.bind(this);
this._onDisplayDialog = this._onDisplayDialog.bind(this);
this._onLoadStart = this._onLoadStart.bind(this);
this._onLoadEnd = this._onLoadEnd.bind(this);
this.state = {
viroAppProps: {displayObject:false, objectSource:objArray[0], yOffset:0, _onLoadEnd: this._onLoadEnd, _onLoadStart: this._onLoadStart, _onTrackingInit:this._onTrackingInit},
trackingInitialized: false,
isLoading: false,
}
}
render() {
return (
<View style={localStyles.outer} >
<ViroARSceneNavigator style={localStyles.arView} apiKey="YOUR API KEY"
initialScene={{scene:InitialARScene, passProps:{displayObject:this.state.displayObject}}} viroAppProps={this.state.viroAppProps}
/>
{this._renderTrackingText()}
{renderIf(this.state.isLoading,
<View style={{position:'absolute', left:0, right:0, top:0, bottom:0, alignItems: 'center', justifyContent:'center'}}>
<ActivityIndicator size='large' animating={this.state.isLoading} color='#ffffff'/>
</View>)
}
<View style={{position: 'absolute', left: 0, right: 0, bottom: 77, alignItems: 'center'}}>
<TouchableHighlight style={localStyles.buttons}
onPress={this._onDisplayDialog}
underlayColor={'#00000000'} >
<Image source={require("./js/res/btn_mode_objects.png")} />
</TouchableHighlight>
</View>
</View>
);
}
// Invoked when a model has started to load, we show a loading indictator.
_onLoadStart() {
this.setState({
isLoading: true,
});
}
// Invoked when a model has loaded, we hide the loading indictator.
_onLoadEnd() {
this.setState({
isLoading: false,
});
}
_renderTrackingText() {
if(this.state.trackingInitialized) {
return (<View style={{position: 'absolute', backgroundColor:"#ffffff22", left: 30, right: 30, top: 30, alignItems: 'center'}}>
<Text style={{fontSize:12, color:"#ffffff"}}>Tracking initialized.</Text>
</View>);
} else {
return (<View style={{position: 'absolute', backgroundColor:"#ffffff22", left: 30, right: 30, top:30, alignItems: 'center'}}>
<Text style={{fontSize:12, color:"#ffffff"}}>Waiting for tracking to initialize.</Text>
</View>);
}
}
_onTrackingInit() {
this.setState({
trackingInitialized: true,
});
}
_onDisplayDialog() {
Alert.alert(
'Choose an object',
'Select an object to place in the world!',
[
{text: 'Coffee Mug', onPress: () => this._onShowObject(0, "coffee_mug", 0)},
{text: 'Flowers', onPress: () => this._onShowObject(1, "flowers", .290760)},
{text: 'Smile Emoji', onPress: () => this._onShowObject(2, "smile_emoji", .497823)},
],
);
}
_onShowObject(objIndex, objUniqueName, yOffset) {
this.setState({
viroAppProps:{...this.state.viroAppProps, displayObject: true, yOffset: yOffset, displayObjectName: objUniqueName, objectSource:objArray[objIndex]},
});
}
}
var localStyles = StyleSheet.create({
outer : {
flex : 1,
},
arView: {
flex:1,
},
buttons : {
height: 80,
width: 80,
paddingTop:20,
paddingBottom:20,
marginTop: 10,
marginBottom: 10,
backgroundColor:'#00000000',
borderRadius: 10,
borderWidth: 1,
borderColor: '#ffffff00',
}
});
module.exports = ViroSample