Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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