Skip to content Skip to sidebar Skip to footer

Function To Call Onrightbuttonpress In Navigatorios - React Native

I'm using the onRightButton in a react-native NavigatorIOS. I'd like to be able to call a function which resides into the component I'm pushing, but I can't get how to achieve that

Solution 1:

The ref callback prop is your friend! https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute

goToResults() {
    this.props.navigator.push({
      component: SingleResultView,
      title: "SomeTitle",
      rightButtonIcon: require('image!mapsmarker'),
      passProps: {
        userPosition: this.props.userPosition,
        ref: this.onResultsRef,
      },
      onRightButtonPress: () => { this._resultsView && this._resultsView.foo(); }
    });
  }

  onResultsRef(resultsViewRef) {
    this._resultsView = resultsViewRef;
  }

Solution 2:

SingleResultView hasn't instantiated yet, so you have no access to its methods.

The following would work:

this.props.navigator.push({
  onRightButtonPress: SingleResultView.prototype.foo
});

Post a Comment for "Function To Call Onrightbuttonpress In Navigatorios - React Native"