react native - Getting access to this.props.navigator from inside NavigatorIOS.onRightButtonPress -
i'm struggling 'onrightbuttonpress' event on navigatorios component. handler doesn't seem ref this.props.navigator.
var cbsupport = react.createclass({ _handlenextbuttonpress: function() { debugger alertios.alert("be lert"); // this.props not contain 'navigator' property this.props.navigator.push({ component: login, title: 'login' }); }, render: function() { return( <navigatorios style={styles.container} initialroute={{ component: accounts, title: 'accounts', rightbuttontitle: 'add', onrightbuttonpress: this._handlenextbuttonpress, }} /> ) } })
i'm doing wrong, i'm trying navigate new scene tapping right button on navigatorios component.
what missing?
many help, ijonas.
update
after colin ramsay's suggestion below of using refs got following solution work me:
var cbsupport = react.createclass({ _handlenextbuttonpress: function() { this.refs.nav.push({ component: login, title: 'login' }); }, render: function() { return( <navigatorios ref="nav" style={styles.container} initialroute={{ component: accounts, title: 'accounts', rightbuttontitle: 'add', onrightbuttonpress: this._handlenextbuttonpress, }} /> ) } })
many colin.
in documentation says:
it [navigator] passed prop component rendered navigatorios.
i take mean child of navigatorios whereas in example have navigatorios child of cbsupport component. way of doing this:
var cbsupport = react.createclass({ _handlenextbuttonpress: function() { // ref not prop this.refs.nav.push({ component: login, title: 'login' }); }, render: function() { return( <navigatorios style={styles.container}, ref: 'nav', // added initialroute={{ component: accounts, title: 'accounts', rightbuttontitle: 'add', onrightbuttonpress: this._handlenextbuttonpress, }} /> ) } })
notice have added ref value of "nav" navigatorios , can use hold of in event handler. because of navigator methods automatically available on navigatorios too, should enable call push
desired.
Comments
Post a Comment