From e9f044faf6b1abc3c1eb8189b37584d767a136d4 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Mon, 30 Oct 2017 11:17:55 +0100 Subject: [PATCH] Set initialLayout in defaultProps on Android (#2843) * Revert "Workaround nested TabNavigation swipe issue (#2733)" This reverts commit 7b88a475bc283ce01fc9b6d57d0c28f4b34879d0. * Set initialLayout in defaultProps on Android This reverts the previous PR (#2733) and takes into account #2385 In order to fix https://github.com/react-native-community/react-native-tab-view/issues/312 * Don't use window's dimensions --- .../react-navigation/src/views/TabView/TabView.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-navigation/src/views/TabView/TabView.js b/packages/react-navigation/src/views/TabView/TabView.js index c3bce61a..bc92bf0f 100644 --- a/packages/react-navigation/src/views/TabView/TabView.js +++ b/packages/react-navigation/src/views/TabView/TabView.js @@ -20,7 +20,6 @@ export type TabViewConfig = { tabBarComponent?: ReactClass<*>, tabBarPosition?: 'top' | 'bottom', tabBarOptions?: {}, - initialLayout?: { width: number, height: number }, swipeEnabled?: boolean, animationEnabled?: boolean, lazy?: boolean, @@ -38,7 +37,6 @@ type Props = { tabBarComponent?: ReactClass<*>, tabBarPosition?: 'top' | 'bottom', tabBarOptions?: {}, - initialLayout?: { width: number, height: number }, swipeEnabled?: boolean, animationEnabled?: boolean, lazy?: boolean, @@ -56,7 +54,14 @@ type Props = { }, }; -class TabView extends PureComponent { +class TabView extends PureComponent<$Shape, Props, void> { + static defaultProps = { + // fix for https://github.com/react-native-community/react-native-tab-view/issues/312 + initialLayout: Platform.select({ + android: { width: 1, height: 0 }, + }), + }; + props: Props; _handlePageChanged = (index: number) => { @@ -208,9 +213,6 @@ class TabView extends PureComponent { screenProps: this.props.screenProps, style: styles.container, }; - if (Platform.OS === 'android') { - props.initialLayout = { width: 1, height: 0 }; - } return ; }