-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
135 lines (126 loc) · 3.38 KB
/
index.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
import React from 'react';
import {
AppRegistry, asset,
StyleSheet,
Text,
View,
NativeModules,
VrButton,
} from 'react-360';
const RCTDeviceEventEmitter = require("RCTDeviceEventEmitter");
const {AudioModule} = NativeModules;
export default class AudioTest360 extends React.Component {
constructor() {
super();
this.state = {
sound: true,
};
NativeModules.GlassModule.openOverlay();
RCTDeviceEventEmitter.addListener('mutetoggle', this.onMuteToggle.bind(this));
};
onMuteToggle(vol) {
console.log("Environmental EMITTER " + vol);
this.setState({sound: vol});
this.handleEnvironmentalAudio();
};
componentDidMount() {
this.handleEnvironmentalAudio();
};
handleEnvironmentalAudio() {
console.log("handleEnvironmentalAudio");
if (this.state.sound) {
AudioModule.playEnvironmental({
source: asset("mario.mp3"),
loop: true,
muted: false,
volume: 1,
});
}
else {
AudioModule.stopEnvironmental();
}
}
render() {
return (
<View style={styles.panel}>
<View style={styles.greetingBox}>
<Text style={styles.greeting}>
Welcome to React 360
</Text>
<VrButton
style={styles.postButton}
onEnter={() => this.setState({hover: true})}
onExit={() => this.setState({hover: false})}
onClick={() => {
this.onMuteToggle(this.state.sound);
}}>
<View style={[styles.postButtonInfo, this.state.hover ? styles.postButtonInfoHover : null]}>
<View style={styles.postButtonLabel}>
<Text style={styles.postButtonName}>{this.state.sound?"Stop":"Play"}</Text>
</View>
</View>
</VrButton>
</View>
</View>
);
}
};
const styles = StyleSheet.create({
panel: {
// Fill the entire surface
width: 1000,
height: 600,
backgroundColor: 'rgba(255, 255, 255, 0.4)',
justifyContent: 'center',
alignItems: 'center',
},
greetingBox: {
padding: 20,
backgroundColor: '#000000',
borderColor: '#639dda',
borderWidth: 2,
},
greeting: {
fontSize: 30,
},
wrapper: {
width: 300,
height: 600,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
borderColor: '#303050',
borderWidth: 2,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'stretch',
},
postButton: {
height: 120,
backgroundColor: '#000000',
overflow: 'hidden',
},
postButtonInfo: {
...StyleSheet.absoluteFillObject,
backgroundColor: 'rgba(0, 0, 0, 0.2)',
flexDirection: 'column',
},
postButtonPreview: {
width: '100%',
height: 225,
},
postButtonInfoHover: {
backgroundColor: 'rgba(0, 0, 0, 0)',
},
postButtonLabel: {
backgroundColor: 'rgba(0, 0, 0, 0.8)',
paddingHorizontal: 10,
paddingVertical: 2,
alignSelf: 'flex-start',
},
postButtonName: {
fontSize: 24,
},
postButtonAuthor: {
fontSize: 16,
}
});
AppRegistry.registerComponent('AudioTest360', () => AudioTest360);