mirror of https://github.com/laurent22/joplin.git
Improved nav
parent
53c23b1149
commit
4b44a8a782
|
@ -20,14 +20,6 @@ const styles = StyleSheet.create({
|
|||
|
||||
class ScreenHeaderComponent extends Component {
|
||||
|
||||
showBackButton() {
|
||||
// Note: this is hardcoded for now because navigation.state doesn't tell whether
|
||||
// it's possible to go back or not. Maybe it's possible to get this information
|
||||
// from somewhere else.
|
||||
return true;
|
||||
return this.props.navState.routeName != 'Notes';
|
||||
}
|
||||
|
||||
sideMenuButton_press() {
|
||||
this.props.dispatch({ type: 'SIDE_MENU_TOGGLE' });
|
||||
}
|
||||
|
@ -71,10 +63,12 @@ class ScreenHeaderComponent extends Component {
|
|||
|
||||
let title = 'title' in this.props && this.props.title !== null ? this.props.title : _(this.props.navState.routeName);
|
||||
|
||||
console.info('CAN', this.props.historyCanGoBack);
|
||||
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', padding: 10, backgroundColor: '#ffffff', alignItems: 'center' }} >
|
||||
<Button title="☰" onPress={() => this.sideMenuButton_press()} />
|
||||
<Button disabled={!this.showBackButton()} title="<" onPress={() => this.backButton_press()}></Button>
|
||||
<Button disabled={!this.props.historyCanGoBack} title="<" onPress={() => this.backButton_press()}></Button>
|
||||
<Text style={{ flex:1, marginLeft: 10 }} >{title}</Text>
|
||||
<Menu onSelect={(value) => this.menu_select(value)}>
|
||||
<MenuTrigger>
|
||||
|
@ -95,7 +89,12 @@ ScreenHeaderComponent.defaultProps = {
|
|||
};
|
||||
|
||||
const ScreenHeader = connect(
|
||||
//(state) => {}
|
||||
(state) => {
|
||||
console.info('CONNECT', state.historyCanGoBack);
|
||||
return {
|
||||
historyCanGoBack: state.historyCanGoBack,
|
||||
};
|
||||
}
|
||||
)(ScreenHeaderComponent)
|
||||
|
||||
export { ScreenHeader };
|
|
@ -59,11 +59,14 @@ const reducer = (state = defaultState, action) => {
|
|||
|
||||
case 'Navigation/BACK':
|
||||
|
||||
if (!navHistory.length) break;
|
||||
if (navHistory.length < 2) break;
|
||||
|
||||
action = navHistory.pop(); // Current page
|
||||
if (!navHistory.length) break;
|
||||
action = navHistory.pop(); // Previous page
|
||||
|
||||
// newState = Object.assign({}, state);
|
||||
// newState.historyCanGoBack = false;
|
||||
|
||||
// Fall throught
|
||||
|
||||
case 'Navigation/NAVIGATE':
|
||||
|
@ -98,7 +101,6 @@ const reducer = (state = defaultState, action) => {
|
|||
if (currentRouteName == action.routeName) {
|
||||
// If the current screen is already the requested screen, don't do anything
|
||||
} else {
|
||||
//const nextStateNav = AppNavigator.router.getStateForAction(action, currentRouteName != 'Loading' ? state.nav : null);
|
||||
const nextStateNav = AppNavigator.router.getStateForAction(action, state.nav);
|
||||
if (nextStateNav) {
|
||||
newState.nav = nextStateNav;
|
||||
|
@ -106,6 +108,10 @@ const reducer = (state = defaultState, action) => {
|
|||
}
|
||||
}
|
||||
|
||||
newState.historyCanGoBack = navHistory.length >= 2;
|
||||
|
||||
console.info(navHistory.length, newState.historyCanGoBack);
|
||||
|
||||
break;
|
||||
|
||||
// Replace all the notes with the provided array
|
||||
|
@ -203,10 +209,6 @@ const reducer = (state = defaultState, action) => {
|
|||
|
||||
}
|
||||
|
||||
if (action.type == 'Navigation/NAVIGATE' || action.type == 'Navigation/BACK') {
|
||||
newState.historyCanGoBack = !!navHistory.length;
|
||||
}
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue