Skip to content

Commit

Permalink
move focus action dispatch out of render method, prevent duplicate di…
Browse files Browse the repository at this point in the history
…spatches
  • Loading branch information
lynndylanhurley committed Apr 17, 2016
1 parent 29e2fd1 commit a74f7fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ export default class DefaultRenderer extends Component {
navigationState: PropTypes.any,
};

componentDidMount() {
this.dispatchFocusAction(this.props);
}

componentWillReceiveProps(nextProps) {
if (nextProps.navigationState !== this.props.navigationState) {
this.dispatchFocusAction(nextProps);
}
}

dispatchFocusAction({navigationState}) {
if (!navigationState || navigationState.component || navigationState.tabs) {
return;
}
const scene = navigationState.children[navigationState.index];
Actions.focus({scene});
}

getChildContext() {
return {
navigationState: this.props.navigationState,
Expand All @@ -54,7 +72,6 @@ export default class DefaultRenderer extends Component {

const selected = navigationState.children[navigationState.index];
//return <DefaultRenderer key={selected.key} navigationState={selected}/>
Actions.focus({scene: selected});

let applyAnimation = selected.applyAnimation || navigationState.applyAnimation;
let style = selected.style || navigationState.style;
Expand Down
2 changes: 1 addition & 1 deletion src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
*/

import {PUSH_ACTION, POP_ACTION2, FOCUS_ACTION, JUMP_ACTION, INIT_ACTION, REPLACE_ACTION, RESET_ACTION, POP_ACTION, REFRESH_ACTION} from "./Actions";
import {PUSH_ACTION, POP_ACTION2, JUMP_ACTION, INIT_ACTION, REPLACE_ACTION, RESET_ACTION, POP_ACTION, REFRESH_ACTION} from "./Actions";
import assert from "assert";
import {getInitialState} from "./State";

Expand Down

0 comments on commit a74f7fd

Please sign in to comment.