-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ios.js
More file actions
66 lines (59 loc) · 1.66 KB
/
Copy pathindex.ios.js
File metadata and controls
66 lines (59 loc) · 1.66 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react"
import { AppRegistry } from "react-native"
import { TabNavigator } from "react-navigation"
import Welcome from "./Welcome"
export default class Router extends Component {
constructor(props) {
super(props)
this.state = {
hideMainTabBar: false,
}
}
onComponentDidMount() {
/* I know it's super weird, but this global functions
* it's the simplest example of programmatical navigation.
*/
window.goTo = (routeName, params = {})=> {
this.navigator.dispatch({
type: "Navigation/NAVIGATE",
routeName: routeName,
params,
action: undefined, // for nested actions
})
}
}
/**
* The great news is that this callback is executed wherever a navigation
* event happens in the tree, no matter the depth.
*/
onNavigationStateChange(prevState, newState, action) {
/* the logic for hiding the main TabBar is hosted here, at top level
* based on the value of the route
*/
if (action.routeName === "Thread") {
this.setState({
hideMainTabBar: true,
})
} else if (this.state.hideMainTabBar) {
// We don't want to trigger a change if not necessary
this.setState({
hideMainTabBar: false,
})
}
}
render() {
return <Welcome
ref={navigatorRef => this.navigator = navigatorRef}
screenProps={{
hideMainTabBar: this.state.hideMainTabBar,
}}
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
/>
}
}
AppRegistry.registerComponent("Router", () => Router)