diff --git a/Actions.js b/Actions.js index bb0869c5d..8ba109677 100644 --- a/Actions.js +++ b/Actions.js @@ -8,6 +8,8 @@ const BEFORE_POP = 'BEFORE_ROUTER_POP'; const AFTER_POP = 'AFTER_ROUTER_POP'; const BEFORE_DISMISS = 'BEFORE_ROUTER_DISMISS'; const AFTER_DISMISS = 'AFTER_ROUTER_DISMISS'; +const AFTER_FOCUS = 'AFTER_ROUTER_FOCUS'; +const BEFORE_FOCUS = 'BEFORE_ROUTER_FOCUS'; function isNumeric(n){ return !isNaN(parseFloat(n)) && isFinite(n); @@ -152,4 +154,6 @@ actions.BEFORE_POP = BEFORE_POP; actions.AFTER_POP = AFTER_POP; actions.BEFORE_DISMISS = BEFORE_DISMISS; actions.AFTER_DISMISS = AFTER_DISMISS; +actions.BEFORE_FOCUS = BEFORE_FOCUS; +actions.AFTER_FOCUS = AFTER_FOCUS; export default actions; diff --git a/Router.js b/Router.js index 9a06908cf..d3820a61b 100644 --- a/Router.js +++ b/Router.js @@ -29,6 +29,30 @@ export default class Router extends React.Component { componentDidMount(){ this.router.delegate = this.refs.router; + + if (this.props.dispatch) { + this.router.delegate.refs.nav.navigationContext.addListener('willfocus', function (ev) { + let name = ev.data.route.name; + let title = ev.data.route.title; + + this.props.dispatch({ + type: Actions.BEFORE_FOCUS, + name: name, + title: title + }); + }.bind(this)); + + this.router.delegate.refs.nav.navigationContext.addListener('didfocus', function (ev) { + let name = ev.data.route.name; + let title = ev.data.route.title; + + this.props.dispatch({ + type: Actions.AFTER_FOCUS, + name: name, + title: title + }); + }.bind(this)); + } } render(){