-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
95 lines (84 loc) · 2.67 KB
/
index.android.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
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
AsyncStorage,
Dimensions,
Text,
View,
} from 'react-native';
import Api from './lib/api';
import CaptionScene from './components/captionScene';
import CaptionsScene from './components/captionsScene';
import SubmissionsScene from './components/submissionsScene';
import SubmissionScene from './components/submissionScene';
import NoScene from './components/noScene';
import KilledScene from './components/killedScene';
import TermsScene from './components/termsScene';
import CurrentUser from './lib/currentUser';
import Scratch from './components/scratch';
import FCM from 'react-native-fcm';
class RootNav extends Component {
constructor(props) {
super(props);
this.state = { props: {}};
this.state.scene = 'CaptionScene';
this.navigator = {
navigate: (component, props) => {
let stateChange = { scene: component, props: props || {} };
if( props && props.clearTerms ) { stateChange.needsTerms = false; }
this.setState(stateChange);
}
}
}
componentDidMount() {
FCM.getFCMToken().then(token => {
token && Api.pushTokens.registerAndroid(token);
});
FCM.on('refreshToken', (token) => {
token && Api.pushTokens.registerAndroid(token);
})
FCM.subscribeToTopic('/topics/all');
Api.killSwitch().then(kill => {
if( !kill ) return;
this.setState({
killed: true,
})
}).catch(err => {
// swallow error on kill switch
console.log(err);
})
CurrentUser.hasAcceptedTerms().then(yes => {
if( yes ) return;
this.setState({
needsTerms: true,
})
}).catch(err => {
// swallow error on accepting terms
console.log(err);
})
}
render() {
// return <Scratch />
return (
<View style={{flex: 1}}>
{ this.state.killed ?
<KilledScene />
: this.state.needsTerms ?
<TermsScene {...this.state.props} navigator={this.navigator}/>
: this.state.scene == 'CaptionScene' ?
<CaptionScene {...this.state.props} navigator={this.navigator}/>
: this.state.scene == 'CaptionsScene' ?
<CaptionsScene {...this.state.props} navigator={this.navigator}/>
: this.state.scene == 'SubmissionsScene' ?
<SubmissionsScene {...this.state.props} navigator={this.navigator}/>
: this.state.scene == 'SubmissionScene' ?
<SubmissionScene {...this.state.props} navigator={this.navigator}/>
:
<NoScene />
}
</View>
)
}
}
AppRegistry.registerComponent('giggles', () => RootNav);