Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benvium/0c5be05bfe81a465da9ae67bc6ef9388 to your computer and use it in GitHub Desktop.
Save benvium/0c5be05bfe81a465da9ae67bc6ef9388 to your computer and use it in GitHub Desktop.
React Native NavigatorIOS - how to use onRightButtonPress to call a component method
const MyComponent = React.createClass({
statics: {
getRoute: function (props:Object) {
// To pass in the onLeft/RightButton press
// to out instance we need to use the 'ref'
// function (in passProps).
// This'll be passed the component instance, that we can call the methods on.. Phew!
let instance = null;
const route = {
component: MyComponent,
title: "My Title",
rightButtonIcon: require("../../images/lightbulb.png"),
onRightButtonPress: () => {
if (instance && instance._onRightPressed) {
instance._onRightPressed();
}
},
backButtonTitle: "Back",
passProps: Object.assign({}, {ref: (item)=>instance = item}, props),
};
return route;
}
},
.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment