Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf7e2a8

Browse files
committed
[Navigator] Vertically hide disabled scenes and use pointerEvents="none"
Summary: Hides disabled scenes using `top` instead of `left`, which fixes a bug with the native UITabBar. When the UITabBar's width is zeroed because the scene has `left: SCREEN_WIDTH, right: 0` applied, this triggers a bug with the kerning of the tab titles. Instead, zeroing the height by setting `top: SCREEN_HEIGHT` avoids the bug. Also applies `pointerEvents="none"` to disabled scenes so that views in the off-screen scenes definitely don't receive touches, which was occurring before. Fixes facebook#1401, fixes facebook#2011 Closes facebook#2104 Github Author: James Ide <[email protected]>
1 parent d10e4db commit bf7e2a8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Libraries/CustomComponents/Navigator/Navigator.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ var PropTypes = React.PropTypes;
5656
var SCREEN_WIDTH = Dimensions.get('window').width;
5757
var SCREEN_HEIGHT = Dimensions.get('window').height;
5858
var SCENE_DISABLED_NATIVE_PROPS = {
59+
pointerEvents: 'none',
5960
style: {
60-
left: SCREEN_WIDTH,
61+
top: SCREEN_HEIGHT,
6162
opacity: 0,
6263
},
6364
};
@@ -107,7 +108,7 @@ var styles = StyleSheet.create({
107108
top: 0,
108109
},
109110
disabledScene: {
110-
left: SCREEN_WIDTH,
111+
top: SCREEN_HEIGHT,
111112
},
112113
transitioner: {
113114
flex: 1,
@@ -529,15 +530,18 @@ var Navigator = React.createClass({
529530
_enableScene: function(sceneIndex) {
530531
// First, determine what the defined styles are for scenes in this navigator
531532
var sceneStyle = flattenStyle([styles.baseScene, this.props.sceneStyle]);
532-
// Then restore the left value for this scene
533+
// Then restore the pointer events and top value for this scene
533534
var enabledSceneNativeProps = {
534-
left: sceneStyle.left,
535+
pointerEvents: 'auto',
536+
style: {
537+
top: sceneStyle.top,
538+
},
535539
};
536540
if (sceneIndex !== this.state.transitionFromIndex &&
537541
sceneIndex !== this.state.presentedIndex) {
538542
// If we are not in a transition from this index, make sure opacity is 0
539543
// to prevent the enabled scene from flashing over the presented scene
540-
enabledSceneNativeProps.opacity = 0;
544+
enabledSceneNativeProps.style.opacity = 0;
541545
}
542546
this.refs['scene_' + sceneIndex] &&
543547
this.refs['scene_' + sceneIndex].setNativeProps(enabledSceneNativeProps);
@@ -1021,8 +1025,10 @@ var Navigator = React.createClass({
10211025

10221026
_renderScene: function(route, i) {
10231027
var disabledSceneStyle = null;
1028+
var disabledScenePointerEvents = 'auto';
10241029
if (i !== this.state.presentedIndex) {
10251030
disabledSceneStyle = styles.disabledScene;
1031+
disabledScenePointerEvents = 'none';
10261032
}
10271033
return (
10281034
<View
@@ -1031,6 +1037,7 @@ var Navigator = React.createClass({
10311037
onStartShouldSetResponderCapture={() => {
10321038
return (this.state.transitionFromIndex != null) || (this.state.transitionFromIndex != null);
10331039
}}
1040+
pointerEvents={disabledScenePointerEvents}
10341041
style={[styles.baseScene, this.props.sceneStyle, disabledSceneStyle]}>
10351042
{this.props.renderScene(
10361043
route,

0 commit comments

Comments
 (0)