Skip to content

Commit

Permalink
[ReactNative] Navigator improved willFocus logic
Browse files Browse the repository at this point in the history
Summary:
This makes sure to call willFocus before new scenes get mounted. This fixes cases where the keyboard is dismissed on willfocus events which incorrectly happens *after* the autofocus in a new scene. The keyboard was opening and getting immediately closed

@public

Test Plan: Test keyboard autofocus in new nav scenes on iOS
  • Loading branch information
Eric Vicenti committed Jun 25, 2015
1 parent 7159a4e commit e3e6098
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Libraries/CustomComponents/Navigator/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ var Navigator = React.createClass({
this.spring.getSpringConfig().tension = sceneConfig.springTension;
this.spring.setVelocity(velocity || sceneConfig.defaultTransitionVelocity);
this.spring.setEndValue(1);
this._emitWillFocus(this.state.routeStack[this.state.presentedIndex]);
},

/**
Expand Down Expand Up @@ -458,6 +457,7 @@ var Navigator = React.createClass({
if (this.state.transitionQueue.length) {
var queuedTransition = this.state.transitionQueue.shift();
this._enableScene(queuedTransition.destIndex);
this._emitWillFocus(this.state.routeStack[queuedTransition.destIndex]);
this._transitionTo(
queuedTransition.destIndex,
queuedTransition.velocity,
Expand Down Expand Up @@ -657,6 +657,7 @@ var Navigator = React.createClass({
}
} else {
// The gesture has enough velocity to complete, so we transition to the gesture's destination
this._emitWillFocus(this.state.routeStack[destIndex]);
this._transitionTo(
destIndex,
transitionVelocity,
Expand Down Expand Up @@ -844,6 +845,7 @@ var Navigator = React.createClass({
_jumpN: function(n) {
var destIndex = this._getDestIndexWithinBounds(n);
this._enableScene(destIndex);
this._emitWillFocus(this.state.routeStack[destIndex]);
this._transitionTo(destIndex);
},

Expand Down Expand Up @@ -876,6 +878,7 @@ var Navigator = React.createClass({
var nextAnimationConfigStack = activeAnimationConfigStack.concat([
this.props.configureScene(route),
]);
this._emitWillFocus(nextStack[destIndex]);
this.setState({
idStack: nextIDStack,
routeStack: nextStack,
Expand All @@ -896,6 +899,7 @@ var Navigator = React.createClass({
);
var popIndex = this.state.presentedIndex - n;
this._enableScene(popIndex);
this._emitWillFocus(this.state.routeStack[popIndex]);
this._transitionTo(
popIndex,
null, // default velocity
Expand Down Expand Up @@ -935,13 +939,15 @@ var Navigator = React.createClass({
nextRouteStack[index] = route;
nextAnimationModeStack[index] = this.props.configureScene(route);

if (index === this.state.presentedIndex) {
this._emitWillFocus(route);
}
this.setState({
idStack: nextIDStack,
routeStack: nextRouteStack,
sceneConfigStack: nextAnimationModeStack,
}, () => {
if (index === this.state.presentedIndex) {
this._emitWillFocus(route);
this._emitDidFocus(route);
}
cb && cb();
Expand Down

0 comments on commit e3e6098

Please sign in to comment.