-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
94 lines (86 loc) · 2.5 KB
/
App.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
import React, { Component } from 'react'
import { DefaultTheme, Provider as PaperProvider } from 'react-native-paper'
import { Provider } from 'react-redux'
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from 'react-apollo'
import MainNavigator from './src/navigators/MainNavigator'
import LoginNavigator from './src/navigators/LoginNavigator'
import Header from './src/ui/Header'
import store from './src/state/store'
import HeaderContext from './src/ui/Header/context'
import { setTopLevelNavigator } from './src/actions/navigation'
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: '#4B307A',
accent: '#B3A53C',
},
fonts: {
regular: 'GloberRegular',
medium: 'GloberSemiBold',
light: 'GloberLight',
thin: 'GloberThin',
},
}
// apollo client setup
const client = new ApolloClient({
uri: 'https://api-useast.graphcms.com/v1/cjuj6y3ym0xga01f4wz55hg24/master',
})
const getCurrentRouteName = (navState) => {
if (navState.hasOwnProperty('index')) { // eslint-disable-line
return getCurrentRouteName(navState.routes[navState.index])
}
return navState.routeName
}
export default class App extends Component {
state = {
showBackButton: false,
}
displayBackButton = () => {
this.setState({
showBackButton: true,
})
}
handleRouteChange = (newState) => {
if (getCurrentRouteName(newState) === 'PostDetail') {
if (!this.state.showBackButton) {
this.setState({
showBackButton: true,
})
}
} else if (this.state.showBackButton === true) {
this.setState({
showBackButton: false,
})
}
}
render() {
return (
<ApolloProvider client={client}>
<Provider store={store}>
<PaperProvider theme={theme}>
{/* <HeaderContext.Provider value={this.state}>
<HeaderContext.Consumer>
{
headerConfigs => (
<Header headerConfigs={headerConfigs} />
)
}
</HeaderContext.Consumer>
<MainNavigator
onNavigationStateChange={(prevState, newState) => {
this.handleRouteChange(newState)
}}
ref={(navigatorRef) => {
setTopLevelNavigator(navigatorRef)
}}
/>
</HeaderContext.Provider> */}
<LoginNavigator />
</PaperProvider>
</Provider>
</ApolloProvider>
)
}
}