-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
131 lines (123 loc) · 3.58 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
import React, { Component } from 'react';
import { SafeAreaView, View, Text, StyleSheet, PermissionsAndroid, FlatList, TouchableOpacity } from 'react-native';
import { AugmentedFacesView } from '@sceneview/react-native-sceneform';
const ExampleSet = [
{title: 'Mesh', model: 'models/face.glb', texture: 'textures/face.png'},
{title: 'Fox', model: 'models/fox.glb', texture: 'textures/freckles.png'},
{title: 'Mario hat', model: 'models/mario-hat.glb'}
];
class MyAugmentedFacesView extends Component {
constructor(props){
super(props);
this.state = {
cameraPermissionGranted: false,
augmentedFaceIndex: -1,
augmentedFaces: []
}
this.checkPermissions = this.checkPermissions.bind(this);
this.loadAssets = this.loadAssets.bind(this);
this.augmentedFacesView = null;
}
componentDidMount(){
this.checkPermissions();
}
checkPermissions = async () => {
const actual = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA);
if(actual){
this.setState({cameraPermissionGranted: true}, this.loadAssets);
}
else{
const permission = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
if(permission == 'granted'){
this.setState({cameraPermissionGranted: true}, this.loadAssets);
}
}
}
loadAssets = () => {
ExampleSet.forEach((item) => {
this.augmentedFacesView.addAugmentedFace(item)
.then((index) => {
const faces = [...this.state.augmentedFaces, {...item, index}];
this.setState({augmentedFaces: faces});
})
})
}
render(){
return(
<SafeAreaView style={styles.container}>
{this.state.cameraPermissionGranted &&
<View style={styles.container}>
<AugmentedFacesView
style={styles.camera}
setAugmentedFace={this.state.augmentedFaceIndex}
ref={(c) => this.augmentedFacesView = c}
/>
<View style={styles.overlay}>
<FlatList
horizontal={true}
data={this.state.augmentedFaces}
renderItem={({item}) => {
return(
<TouchableOpacity style={styles.touchable} onPress={() => { this.setState({augmentedFaceIndex: item.index})}}>
<View style={styles.touchable_body}>
<Text style={styles.text}>{item.title}</Text>
</View>
</TouchableOpacity>
);
}}
style={styles.flatlist}
contentContainerStyle={styles.flatlist_container}
/>
</View>
</View>
}
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
backgroundColor: 'white'
},
camera: {
flex: 1
},
overlay: {
zIndex: 2,
width: '100%',
height: '100%',
position: 'absolute',
top: 0,
},
flatlist: {
width: '100%',
height: 60,
position: 'absolute',
bottom: 0,
backgroundColor: 'rgba(0,0,0,0.25)',
},
flatlist_container:{
alignItems: 'center'
},
touchable: {
width: 100,
height: 50,
padding: 5
},
touchable_body: {
width: '100%',
height: '100%',
backgroundColor: 'white',
borderRadius: 5,
elevation: 1,
alignItems: 'center',
justifyContent: 'center'
},
text: {
textAlign: 'center',
textAlignVertical: 'center'
}
});
export default MyAugmentedFacesView;