diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 0015a9daabfde1..0492c76bf6e60a 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -48,20 +48,25 @@ import ScrollContentViewNativeComponent from './ScrollContentViewNativeComponent import AndroidHorizontalScrollViewNativeComponent from './AndroidHorizontalScrollViewNativeComponent'; import AndroidHorizontalScrollContentViewNativeComponent from './AndroidHorizontalScrollContentViewNativeComponent'; -let AndroidScrollView; -let AndroidHorizontalScrollContentView; -let AndroidHorizontalScrollView; -let RCTScrollView; -let RCTScrollContentView; - -if (Platform.OS === 'android') { - AndroidScrollView = ScrollViewNativeComponent; - AndroidHorizontalScrollView = AndroidHorizontalScrollViewNativeComponent; - AndroidHorizontalScrollContentView = AndroidHorizontalScrollContentViewNativeComponent; -} else { - RCTScrollView = ScrollViewNativeComponent; - RCTScrollContentView = ScrollContentViewNativeComponent; -} +const {NativeHorizontalScrollViewTuple, NativeVerticalScrollViewTuple} = + Platform.OS === 'android' + ? { + NativeHorizontalScrollViewTuple: [ + AndroidHorizontalScrollViewNativeComponent, + AndroidHorizontalScrollContentViewNativeComponent, + ], + NativeVerticalScrollViewTuple: [ScrollViewNativeComponent, View], + } + : { + NativeHorizontalScrollViewTuple: [ + ScrollViewNativeComponent, + ScrollContentViewNativeComponent, + ], + NativeVerticalScrollViewTuple: [ + ScrollViewNativeComponent, + ScrollContentViewNativeComponent, + ], + }; // Public methods for ScrollView export type ScrollViewImperativeMethods = $ReadOnly<{| @@ -1008,30 +1013,10 @@ class ScrollView extends React.Component { }); render(): React.Node | React.Element { - let ScrollViewClass; - let ScrollContentContainerViewClass; - if (Platform.OS === 'android') { - if (this.props.horizontal === true) { - ScrollViewClass = AndroidHorizontalScrollView; - ScrollContentContainerViewClass = AndroidHorizontalScrollContentView; - } else { - ScrollViewClass = AndroidScrollView; - ScrollContentContainerViewClass = View; - } - } else { - ScrollViewClass = RCTScrollView; - ScrollContentContainerViewClass = RCTScrollContentView; - } - - invariant( - ScrollViewClass !== undefined, - 'ScrollViewClass must not be undefined', - ); - - invariant( - ScrollContentContainerViewClass !== undefined, - 'ScrollContentContainerViewClass must not be undefined', - ); + const [NativeDirectionalScrollView, NativeDirectionalScrollContentView] = + this.props.horizontal === true + ? NativeHorizontalScrollViewTuple + : NativeVerticalScrollViewTuple; const contentContainerStyle = [ this.props.horizontal === true && styles.contentContainerHorizontal, @@ -1050,12 +1035,12 @@ class ScrollView extends React.Component { ); } - let contentSizeChangeProps = {}; - if (this.props.onContentSizeChange) { - contentSizeChangeProps = { - onLayout: this._handleContentOnLayout, - }; - } + const contentSizeChangeProps = + this.props.onContentSizeChange == null + ? null + : { + onLayout: this._handleContentOnLayout, + }; const {stickyHeaderIndices} = this.props; let children = this.props.children; @@ -1101,10 +1086,7 @@ class ScrollView extends React.Component { Array.isArray(stickyHeaderIndices) && stickyHeaderIndices.length > 0; const contentContainer = ( - /* $FlowFixMe(>=0.112.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.112 was deployed. To see the error, delete - * this comment and run Flow. */ - { } collapsable={false}> {children} - + ); const alwaysBounceHorizontal = @@ -1207,13 +1189,10 @@ class ScrollView extends React.Component { if (Platform.OS === 'ios') { // On iOS the RefreshControl is a child of the ScrollView. return ( - /* $FlowFixMe(>=0.117.0 site=react_native_fb) This comment suppresses - * an error found when Flow v0.117 was deployed. To see the error, - * delete this comment and run Flow. */ - + {refreshControl} {contentContainer} - + ); } else if (Platform.OS === 'android') { // On Android wrap the ScrollView with a AndroidSwipeRefreshLayout. @@ -1225,19 +1204,19 @@ class ScrollView extends React.Component { return React.cloneElement( refreshControl, {style: StyleSheet.compose(baseStyle, outer)}, - {contentContainer} - , + , ); } } return ( - + {contentContainer} - + ); } } diff --git a/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js b/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js index a6366e8b62b347..13af2ed6146c83 100644 --- a/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js +++ b/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js @@ -4,18 +4,14 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow strict-local * @format - * @flow */ 'use strict'; import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import type {ViewProps} from '../View/ViewPropTypes'; -import type { - ViewStyleProp, - DangerouslyImpreciseStyle, -} from '../../StyleSheet/StyleSheet'; import type {ColorValue} from '../../StyleSheet/StyleSheet'; import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType'; import type {ScrollEvent} from '../../Types/CoreEventTypes'; @@ -45,10 +41,10 @@ export type ScrollViewNativeProps = $ReadOnly<{ fadingEdgeLength?: ?number, indicatorStyle?: ?('default' | 'black' | 'white'), keyboardDismissMode?: ?('none' | 'on-drag' | 'interactive'), - maintainVisibleContentPosition?: ?$ReadOnly<{| + maintainVisibleContentPosition?: ?$ReadOnly<{ minIndexForVisible: number, autoscrollToTopThreshold?: ?number, - |}>, + }>, maximumZoomScale?: ?number, minimumZoomScale?: ?number, nestedScrollEnabled?: ?boolean, @@ -78,8 +74,7 @@ export type ScrollViewNativeProps = $ReadOnly<{ snapToStart?: ?boolean, zoomScale?: ?number, // Overrides - style?: {...ViewStyleProp, ...} | DangerouslyImpreciseStyle, - onResponderGrant?: ?(e: any) => void | boolean, + onResponderGrant?: ?(e: $FlowFixMe) => void | boolean, ... }>;