Skip to content

Commit

Permalink
Merge pull request #204 from lynndylanhurley/master
Browse files Browse the repository at this point in the history
Add BEFORE_FOCUS and AFTER_FOCUS for swipe gesture handling.
  • Loading branch information
Pavlo Aksonov committed Feb 12, 2016
2 parents 4457af0 + a58e9fb commit a34fe37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
24 changes: 24 additions & 0 deletions Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down

1 comment on commit a34fe37

@xhyp0
Copy link
Contributor

@xhyp0 xhyp0 commented on a34fe37 Feb 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can get the Example project updated to show this working? I seem to be getting the same No current router is set error when pulling in this update while running the example. Adding BEFORE_FOCUS and AFTER_FOCUS to the reducer does work, but I'm not sure if there's any code that needs to be added there.

Please sign in to comment.