-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
138 lines (125 loc) · 3.38 KB
/
Main.js
File metadata and controls
138 lines (125 loc) · 3.38 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
127
128
129
130
131
132
133
134
135
136
137
import React from 'react';
import { StyleSheet, Text, View, ScrollView } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import { connect } from 'react-redux';
import Welcome from './Welcome';
import Question from './Question';
import Joke from './Joke';
import { store } from './reducers';
import Menu, { MenuItem } from 'react-native-material-menu';
import Spinner from 'react-native-loading-spinner-overlay';
import { leaveEvent } from './actions';
import * as strings from './strings';
class Main extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
_menu = null;
setMenuRef = ref => {
this._menu = ref;
};
hideMenu = () => {
this._menu.hide();
};
showMenu = () => {
this._menu.show();
};
scrollTo = (y) => {
this.scrollView.scrollTo({y: y, animated: true});
}
render() {
const gradient = (<LinearGradient
colors={['transparent', 'rgba(39,76,177,0.6)']}
style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: 400, }}
/>);
// TODO: use navigation instead of this if.
if (this.props.event == null) {
return (
<View style={styles.container}>
<Spinner
visible={this.props.spinner}
cancelable={true}
/>
{gradient}
<Welcome
store={store}
/>
</View>
);
}
let innerComponent = (
<View>
<Text style={styles.textStyle}>
{this.props.noQuestionText}
</Text>
<Joke scrollTo={this.scrollTo}/>
</View>
);
if (this.props.questionToShow != "") {
innerComponent = (<Question store={store}/>);
}
return (
<View style={styles.container}>
<View style={{ alignSelf: 'stretch', flexDirection: 'row', justifyContent: 'center', alignItems: 'center', margin: 10, marginTop: 40 }}>
<Text style={styles.eventTextStyle}>{this.props.event.data.name}</Text>
<View style={{position: 'absolute', right: 5 }}>
<Menu
ref={this.setMenuRef}
button={<Text onPress={this.showMenu} style={styles.menuDotsStyle}>⠇</Text>}
style={{ marginTop: 40 }}
>
<MenuItem onPress={() => store.dispatch(leaveEvent())}>
{strings.EXIT_TEXT}
</MenuItem>
</Menu>
</View>
</View>
<Spinner
visible={this.props.spinner}
cancelable={true}
/>
{gradient}
<ScrollView
style={{alignSelf: 'stretch'}}
ref={(view) => {this.scrollView = view}}>
{innerComponent}
</ScrollView>
</View>
);
}
}
const mapStateToProps = state => ({
event: state.event,
questionToShow: state.questionToShow,
spinner: state.spinner,
noQuestionText: state.noQuestionText,
});
export default connect(mapStateToProps)(Main);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#0b1633',
color: '#fff',
alignItems: 'center',
justifyContent: 'flex-start',
},
textStyle: {
marginTop: 30,
fontSize: 20,
color: '#fff',
textAlign: "center",
margin: 20,
},
eventTextStyle: {
margin: 10,
fontSize: 30,
color: '#d3d3d3',
textAlign: "center"
},
menuDotsStyle: {
color:'#fff',
fontSize: 30
},
});