-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
ObjectChooser.js
108 lines (98 loc) · 3.25 KB
/
ObjectChooser.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
import React from 'react';
import { StyleSheet, View, TouchableHighlight, Image , Dimensions} from 'react-native';
import { StackNavigator } from 'react-navigation';
import { videos } from './config';
import { Button } from "./component/Button.js";
function renderVideoWithNavigation(navigate, shouldDisableRemnant, imgSize) {
return (video) => {
const disabled = video.isRemnant && shouldDisableRemnant;
return (
<Button key={video.youtubeVideoId}
onPress={() => navigate(video)}
style={[styles.touchableStyle, { opacity: disabled ? 0 : 1 }]}
disabled={disabled}
image={video.asset}
pressAnimation="spring"
resizeMode="contain"
imageStyle={styles.objectImage}/>
);
}
}
class ObjectChooser extends React.Component {
constructor(props) {
super(props);
const window = Dimensions.get('window');
this.state = {
imgwidth: window.width,
watchedVideos: [],
}
this.handleLayoutChange = this.handleLayoutChange.bind(this);
}
handleLayoutChange(e) {
this.setState({
imgwidth: e.nativeEvent.layout.width
})
}
render() {
const navigation = this.props.navigation;
const shouldDisableRemnant = this.state.watchedVideos.length < 2;
const renderVideo = renderVideoWithNavigation((video) => {
const watchedVideos = new Set(this.state.watchedVideos);
watchedVideos.add(video.youtubeVideoId);
this.setState({ watchedVideos: Array.from(watchedVideos) });
navigation.navigate('Player', { videoId: video.youtubeVideoId });
}, shouldDisableRemnant, this.state.imgwidth / 3);
return (
<View style={{flex:1, flexDirection: 'row'}}>
<Image source={require('./assets/BackgroundForObjectsAndHelpAbout.png')} style={styles.backgroundImage} />
<View style={styles.objectChooser} onLayout={this.handleLayoutChange}>
{videos.map(renderVideo)}
</View>
<View style={{ flex: 1.5, flexDirection: 'row', alignItems: 'flex-end', justifyContent: 'flex-end' }}>
<View style={{backgroundColor: '#aa99dd', height: 80, width: 160, position: 'absolute'}}></View>
<Button image={require('./assets/AboutIcon.png')}
pressAnimation="spring"
style={styles.navIcon}
navigation={navigation}
route="About"
/>
<Button image={require('./assets/HelpIcon.png')}
pressAnimation="spring"
style={styles.navIcon}
navigation={navigation}
route="Help" />
</View>
</View>
);
}
}
export default ObjectChooser
const styles = StyleSheet.create({
objectChooser: {
flex: 3,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'center',
justifyContent: 'center',
},
touchableStyle: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 60,
paddingBottom: 0,
paddingRight: 60,
paddingTop: 0,
margin: 10,
},
navIcon: {
height: 100,
width: 100,
margin: -12,
},
backgroundImage: {
position: 'absolute',
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
},
});