forked from react-navigation/react-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppFrame.js
More file actions
114 lines (102 loc) · 3.08 KB
/
Copy pathAppFrame.js
File metadata and controls
114 lines (102 loc) · 3.08 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
import React from 'react';
import Link from './Link';
import Footer from './Footer';
import DocSearchBar from './DocSearchBar';
import { addNavigationHelpers } from 'react-navigation';
const NavigationLinks = ({ navigation, className, reverse }) => {
let links = [
...navigation.state.routes.map((route, i) => {
if (route.routeName === 'Home' || route.routeName === 'NotFound') {
return null;
}
return (
<Link
to={route.routeName}
className={i === navigation.state.index ? 'active' : ''}
key={route.routeName}
>
{route.routeName}
</Link>
);
}),
<a
href="https://exp.host/@react-navigation/NavigationPlayground"
key="demo"
>
Demo
</a>,
<a href="https://github.com/react-community/react-navigation" key="github">
GitHub
</a>,
];
if (reverse) {
links = links.reverse();
}
return <div className={className}>{links}</div>;
};
class AppFrame extends React.Component {
state = { isMobileMenuOpen: false };
componentWillReceiveProps(props) {
if (this.props.navigation.state !== props.navigation.state) {
this.setState({ isMobileMenuOpen: false });
window.scrollTo(0, 0);
}
}
render() {
const { navigation, router } = this.props;
const { isMobileMenuOpen } = this.state;
const childNavigation = addNavigationHelpers({
...navigation,
state: navigation.state.routes[navigation.state.index],
});
const { state } = navigation;
const ScreenView = router.getComponentForRouteName(
state.routes[state.index].routeName
);
const { routes, index } = state;
const route = routes[index];
const hasChildNavigation = !!route.routes;
return (
<div className={`main-app ${isMobileMenuOpen ? 'mobileMenuActive' : ''}`}>
<nav className="pt-navbar" id="navbar">
<div className="inner-navbar">
<Link
className="pt-navbar-group pt-align-left project-title"
to="Home"
>
<img
src="/assets/react-nav-logo.svg"
role="presentation"
className="logo"
/>
<h1 className="pt-navbar-heading">React Navigation</h1>
</Link>
<NavigationLinks navigation={navigation} className="navbuttons" />
<DocSearchBar />
{hasChildNavigation && (
<span
className={`pt-icon-properties openMenuButton ${isMobileMenuOpen
? 'active'
: ''}`}
onClick={() => {
this.setState(s => ({
isMobileMenuOpen: !s.isMobileMenuOpen,
}));
window.scrollTo(0, 0);
}}
/>
)}
</div>
</nav>
<NavigationLinks
navigation={navigation}
className="mobile-navbuttons"
reverse
/>
<ScreenView navigation={childNavigation} />
<Footer />
</div>
);
}
}
export default AppFrame;