2019-08-07 10:24:35 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
|
|
|
import SideMenu from "react-native-side-menu";
|
|
|
|
import SideBar from "./Sidebar";
|
2019-08-08 19:45:21 +02:00
|
|
|
import {View} from "react-native";
|
2019-08-07 10:24:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
children: React.Node,
|
|
|
|
isOpen: boolean,
|
2019-08-08 19:45:21 +02:00
|
|
|
onChange: Function,
|
2019-08-07 10:24:35 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:45:21 +02:00
|
|
|
type State = {
|
|
|
|
shouldShowMenu: boolean, // Prevent menu from showing in transitions between tabs
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class CustomSideMenu extends React.Component<Props, State> {
|
|
|
|
|
|
|
|
state = {
|
|
|
|
shouldShowMenu: this.props.isOpen,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Stop the side menu from being shown while tab transition is playing
|
|
|
|
// => Hide the menu when behind the actual screen
|
|
|
|
onMenuMove(percent: number) {
|
|
|
|
if (percent <= 0)
|
|
|
|
this.setState({shouldShowMenu: false});
|
|
|
|
else if (this.state.shouldShowMenu === false)
|
|
|
|
this.setState({shouldShowMenu: true});
|
|
|
|
}
|
|
|
|
|
2019-08-07 10:24:35 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2019-08-08 19:45:21 +02:00
|
|
|
<SideMenu menu={
|
|
|
|
this.state.shouldShowMenu ?
|
|
|
|
<SideBar navigation={this.props.navigation}/>
|
|
|
|
: <View/>}
|
2019-08-07 10:24:35 +02:00
|
|
|
isOpen={this.props.isOpen}
|
2019-08-08 19:45:21 +02:00
|
|
|
onChange={this.props.onChange}
|
|
|
|
onSliding={(percent) => this.onMenuMove(percent)}>
|
2019-08-07 10:24:35 +02:00
|
|
|
{this.props.children}
|
|
|
|
</SideMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|