-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
126 lines (116 loc) · 3.16 KB
/
Copy pathindex.js
File metadata and controls
126 lines (116 loc) · 3.16 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
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
asset,
Environment,
} from 'react-360';
import EventEmitter from "EventEmitter";
import MediaAppTemplateScenePage from "MediaAppTemplateScenePage.react";
import MediaAppTemplateSubtitleText from "MediaAppTemplateSubtitleText.react";
// The mock database
const SCENE_DEF = [
{
type: 'photo',
title: 'Mudar',
source: asset('SAM_100_0021.jpg'),
audio: asset('cafe.wav'),
next: 1,
subtitle: 'This is the welcome scene, just look around!',
},
{
type: 'photo',
title: 'Welcome Scene',
source: asset('SAM_100_0023.jpg'),
audio: asset('cafe.wav'),
next: 2,
subtitle: 'This is the welcome scene, just look around!',
},
{
type: 'photo',
title: '2D Street View',
source: asset('SAM_100_0025.jpg'),
screen: {url: asset('video.mp4').uri},
next: 0,
subtitle: 'This is a 2d video of street view, you can see the traffic.',
},
];
// To share data between different root views, the best way is to
// use data frameworks such as flux or redux.
// Here we just use a simple event emitter.
const dataStore = new EventEmitter();
// The root react component of the app main surface
export default class MediaAppTemplate extends React.Component {
constructor(props) {
super(props);
this.state = {
index: 0,
};
}
_onClickNext = () => {
const nextID = SCENE_DEF[this.state.index].next;
this.setState({index: nextID});
dataStore.emit('dataChange', nextID);
};
render() {
const currentScene = SCENE_DEF[this.state.index];
const nextScene = SCENE_DEF[SCENE_DEF[this.state.index].next];
return (
<View style={styles.panel}>
<MediaAppTemplateScenePage
currentScene={currentScene}
nextScene={nextScene}
onClickNext={this._onClickNext} />
</View>
);
}
};
// The root react component of the subtitle surface
export class MediaAppTemplateSubtitle extends React.Component {
state = {
index: 0,
};
componentWillMount() {
dataStore.addListener('dataChange', this._onDataChange);
}
componentWillUnmount() {
dataStore.removeListener('dataChange', this._onDataChange);
}
_onDataChange = (index) => {
this.setState({index: index});
};
render() {
const currentScene = SCENE_DEF[this.state.index];
return (
<View style={styles.subtitle}>
<MediaAppTemplateSubtitleText text={currentScene.subtitle} />
</View>
);
}
};
// defining StyleSheet
const styles = StyleSheet.create({
panel: {
width: 700,
height: 300,
justifyContent: 'center',
alignItems: 'center',
padding: 20,
},
subtitle: {
width: 300,
height: 100,
justifyContent: 'center',
alignItems: 'center',
top: 300,
},
});
// register the root component
// this will be used from client.js by r360.createRoot('MediaAppTemplate' ...)
AppRegistry.registerComponent('MediaAppTemplate', () => MediaAppTemplate);
// register another root component
// this will be used from client.js by r360.createRoot('MediaAppTemplate' ...)
AppRegistry.registerComponent('MediaAppTemplateSubtitle', () => MediaAppTemplateSubtitle);