Skip to content

Commit b0348ed

Browse files
committed
[react_native] JS files from D2001635: [react_native] Use hardware layers during adsmanager Navigator navigation
1 parent 765779a commit b0348ed

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

Libraries/CustomComponents/Navigator/Navigator.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ var Navigator = React.createClass({
494494

495495
_completeTransition: function() {
496496
if (this.spring.getCurrentValue() === 1) {
497+
this._onAnimationEnd();
497498
var presentedIndex = this.state.toIndex;
498499
this.state.presentedIndex = presentedIndex;
499500
this.state.fromIndex = presentedIndex;
@@ -515,6 +516,7 @@ var Navigator = React.createClass({
515516
// For visual consistency, the from index is always used to configure the spring
516517
this.state.sceneConfigStack[this.state.fromIndex]
517518
);
519+
this._onAnimationStart();
518520
this.state.isAnimating = true;
519521
this.spring.setVelocity(v);
520522
this.spring.setEndValue(1);
@@ -573,6 +575,34 @@ var Navigator = React.createClass({
573575
}
574576
},
575577

578+
_onAnimationStart: function() {
579+
this._setRenderSceneToHarwareTextureAndroid(this.state.fromIndex, true);
580+
this._setRenderSceneToHarwareTextureAndroid(this.state.toIndex, true);
581+
582+
var navBar = this._navBar;
583+
if (navBar && navBar.onAnimationStart) {
584+
navBar.onAnimationStart(this.state.fromIndex, this.state.toIndex);
585+
}
586+
},
587+
588+
_onAnimationEnd: function() {
589+
this._setRenderSceneToHarwareTextureAndroid(this.state.fromIndex, false);
590+
this._setRenderSceneToHarwareTextureAndroid(this.state.toIndex, false);
591+
592+
var navBar = this._navBar;
593+
if (navBar && navBar.onAnimationEnd) {
594+
navBar.onAnimationEnd(this.state.fromIndex, this.state.toIndex);
595+
}
596+
},
597+
598+
_setRenderSceneToHarwareTextureAndroid: function(sceneIndex, shouldRenderToHardwareTexture) {
599+
var viewAtIndex = this.refs['scene_' + sceneIndex];
600+
if (viewAtIndex === null || viewAtIndex === undefined) {
601+
return;
602+
}
603+
viewAtIndex.setNativeProps({renderToHardwareTextureAndroid: shouldRenderToHardwareTexture});
604+
},
605+
576606
/**
577607
* Becomes the responder on touch start (capture) while animating so that it
578608
* blocks all touch interactions inside of it. However, this responder lock
@@ -610,6 +640,7 @@ var Navigator = React.createClass({
610640
this.state.fromIndex = this.state.presentedIndex;
611641
var gestureSceneDelta = this._deltaForGestureAction(this._activeGestureAction);
612642
this.state.toIndex = this.state.presentedIndex + gestureSceneDelta;
643+
this.onAnimationStart();
613644
}
614645
},
615646

Libraries/CustomComponents/Navigator/NavigatorBreadcrumbNavigationBar.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,37 @@ var NavigatorBreadcrumbNavigationBar = React.createClass({
138138
}
139139
},
140140

141+
onAnimationStart: function(fromIndex, toIndex) {
142+
var max = Math.max(fromIndex, toIndex);
143+
var min = Math.min(fromIndex, toIndex);
144+
for (var index = min; index <= max; index++) {
145+
this._setRenderViewsToHardwareTextureAndroid(index, true);
146+
}
147+
},
148+
149+
onAnimationEnd: function(fromIndex, toIndex) {
150+
var max = Math.max(fromIndex, toIndex);
151+
var min = Math.min(fromIndex, toIndex);
152+
for (var index = min; index <= max; index++) {
153+
this._setRenderViewsToHardwareTextureAndroid(index, false);
154+
}
155+
},
156+
157+
_setRenderViewsToHardwareTextureAndroid: function(index, renderToHardwareTexture) {
158+
var props = {
159+
renderToHardwareTextureAndroid: renderToHardwareTexture,
160+
};
161+
162+
this.refs['crumb_' + index].setNativeProps(props);
163+
this.refs['icon_' + index].setNativeProps(props);
164+
this.refs['separator_' + index].setNativeProps(props);
165+
this.refs['title_' + index].setNativeProps(props);
166+
var right = this.refs['right_' + index];
167+
if (right) {
168+
right.setNativeProps(props);
169+
}
170+
},
171+
141172
render: function() {
142173
var navState = this.props.navState;
143174
var icons = navState && navState.routeStack.map(this._renderOrReturnBreadcrumb);

0 commit comments

Comments
 (0)