expo / ex-navigator

Route-centric navigation built on top of React Native's Navigator
MIT License
522 stars 68 forks source link

getNavigatorByUID() -> "Navigator does not exist" #133

Closed msageryd closed 8 years ago

msageryd commented 8 years ago

I'm trying to make a save-button to use as rightButton in the navigationBar. It only need to do two things:

  1. Dispatch an action
  2. Pop the route, i.e. go back to previous route

On other places where I need to pop the current route I'm doing:

const parentNavigator = this.props.navigator.getParentNavigator();
parentNavigator.pop();

But when I try to do this from within my component I get "Navigator does not exist". This is because navigatorUID is undefined. What have I done wrong?

@withNavigation
class _CommitEditProjectButton extends React.Component {
  render() {
    if(!this.props.isEditing) return null;

    return (
      <View style={styles.buttonContainer}>
        <TouchableOpacity
          onPress={this.commitEditProject}
          hitSlop={{top: 15, bottom: 15, left: 30, right: 10}}>
          <Text style={styles.text}>Spara</Text>
        </TouchableOpacity>
      </View>
    );
  }

  commitEditProject = () => {
    this.props.dispatch(ProjectState.projectEditCommitAction());
    const parentNavigator = this.props.navigator.getParentNavigator();
    parentNavigator.pop();
  }
}

export const CommitEditProjectButton = connect(
  state => ({
    isEditing: ProjectSelectors.selectIsEditingProject(state)
  })
)(_CommitEditProjectButton)
msageryd commented 8 years ago

Closing this because...

  1. I'm using "ex-navigation", not "ex-navigator"
  2. this.props.navigator.pop() works. I don't know why I complicated it.