diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index f172525a5e3..996bca72c97 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -42,6 +42,8 @@ import type {State as ScrollResponderState} from '../ScrollResponder'; import type {ViewProps} from '../View/ViewPropTypes'; import type {Props as ScrollViewStickyHeaderProps} from './ScrollViewStickyHeader'; +import ScrollViewNativeComponent from './ScrollViewNativeComponent'; + let AndroidScrollView; let AndroidHorizontalScrollContentView; let AndroidHorizontalScrollView; @@ -49,7 +51,7 @@ let RCTScrollView; let RCTScrollContentView; if (Platform.OS === 'android') { - AndroidScrollView = requireNativeComponent('RCTScrollView'); + AndroidScrollView = ScrollViewNativeComponent; AndroidHorizontalScrollView = requireNativeComponent( 'AndroidHorizontalScrollView', ); @@ -57,7 +59,7 @@ if (Platform.OS === 'android') { 'AndroidHorizontalScrollContentView', ); } else if (Platform.OS === 'ios') { - RCTScrollView = requireNativeComponent('RCTScrollView'); + RCTScrollView = ScrollViewNativeComponent; RCTScrollContentView = requireNativeComponent('RCTScrollContentView'); } else { RCTScrollView = requireNativeComponent('RCTScrollView'); diff --git a/Libraries/Components/ScrollView/ScrollViewNativeComponent.js b/Libraries/Components/ScrollView/ScrollViewNativeComponent.js new file mode 100644 index 00000000000..6284822823b --- /dev/null +++ b/Libraries/Components/ScrollView/ScrollViewNativeComponent.js @@ -0,0 +1,32 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +const registerGeneratedViewConfig = require('../../Utilities/registerGeneratedViewConfig'); +const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); +import ScrollViewViewConfig from './ScrollViewViewConfig'; + +import type { + ScrollViewNativeProps, + ScrollViewNativeComponentType, +} from './ScrollViewNativeComponentType'; + +let ScrollViewNativeComponent; +if (global.RN$Bridgeless) { + registerGeneratedViewConfig('RCTScrollView', ScrollViewViewConfig); + ScrollViewNativeComponent = 'RCTScrollView'; +} else { + ScrollViewNativeComponent = requireNativeComponent( + 'RCTScrollView', + ); +} + +export default ((ScrollViewNativeComponent: any): ScrollViewNativeComponentType); diff --git a/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js b/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js new file mode 100644 index 00000000000..f53358d5e5d --- /dev/null +++ b/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js @@ -0,0 +1,89 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @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/StyleSheetTypes'; +import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType'; +import type {ScrollEvent} from '../../Types/CoreEventTypes'; +import type {PointProp} from '../../StyleSheet/PointPropType'; + +export type ScrollViewNativeProps = $ReadOnly<{ + ...ViewProps, + + alwaysBounceHorizontal?: ?boolean, + alwaysBounceVertical?: ?boolean, + automaticallyAdjustContentInsets?: ?boolean, + bounces?: ?boolean, + bouncesZoom?: ?boolean, + canCancelContentTouches?: ?boolean, + centerContent?: ?boolean, + contentInset?: ?EdgeInsetsProp, + contentInsetAdjustmentBehavior?: ?( + | 'automatic' + | 'scrollableAxes' + | 'never' + | 'always' + ), + contentOffset?: ?PointProp, + decelerationRate?: ?('fast' | 'normal' | number), + directionalLockEnabled?: ?boolean, + disableIntervalMomentum?: ?boolean, + endFillColor?: ?ColorValue, + fadingEdgeLength?: ?number, + indicatorStyle?: ?('default' | 'black' | 'white'), + keyboardDismissMode?: ?('none' | 'on-drag' | 'interactive'), + maintainVisibleContentPosition?: ?$ReadOnly<{| + minIndexForVisible: number, + autoscrollToTopThreshold?: ?number, + |}>, + maximumZoomScale?: ?number, + minimumZoomScale?: ?number, + nestedScrollEnabled?: ?boolean, + onMomentumScrollBegin?: ?(event: ScrollEvent) => void, + onMomentumScrollEnd?: ?(event: ScrollEvent) => void, + onScroll?: ?(event: ScrollEvent) => void, + onScrollBeginDrag?: ?(event: ScrollEvent) => void, + onScrollEndDrag?: ?(event: ScrollEvent) => void, + onScrollToTop?: (event: ScrollEvent) => void, + overScrollMode?: ?('auto' | 'always' | 'never'), + pagingEnabled?: ?boolean, + persistentScrollbar?: ?boolean, + pinchGestureEnabled?: ?boolean, + scrollEnabled?: ?boolean, + scrollEventThrottle?: ?number, + scrollIndicatorInsets?: ?EdgeInsetsProp, + scrollPerfTag?: ?string, + scrollToOverflowEnabled?: ?boolean, + scrollsToTop?: ?boolean, + sendMomentumEvents?: ?boolean, + showsHorizontalScrollIndicator?: ?boolean, + showsVerticalScrollIndicator?: ?boolean, + snapToAlignment?: ?('start' | 'center' | 'end'), + snapToEnd?: ?boolean, + snapToInterval?: ?number, + snapToOffsets?: ?$ReadOnlyArray, + snapToStart?: ?boolean, + zoomScale?: ?number, + + DEPRECATED_sendUpdatedChildFrames?: ?boolean, + + // Overrides + style?: {...ViewStyleProp} | DangerouslyImpreciseStyle, + onResponderGrant?: ?(e: any) => void | boolean, +}>; + +export type ScrollViewNativeComponentType = HostComponent; diff --git a/Libraries/Components/ScrollView/ScrollViewViewConfig.js b/Libraries/Components/ScrollView/ScrollViewViewConfig.js new file mode 100644 index 00000000000..d962bc6f402 --- /dev/null +++ b/Libraries/Components/ScrollView/ScrollViewViewConfig.js @@ -0,0 +1,79 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +import {} from '../../Utilities/differ/pointsDiffer'; + +import type {GeneratedViewConfig} from '../../Utilities/registerGeneratedViewConfig'; + +const ScrollViewViewConfig = { + uiViewClassName: 'RCTScrollView', + bubblingEventTypes: {}, + directEventTypes: { + topScrollToTop: { + registrationName: 'onScrollToTop', + }, + }, + validAttributes: { + alwaysBounceHorizontal: true, + alwaysBounceVertical: true, + automaticallyAdjustContentInsets: true, + bounces: true, + bouncesZoom: true, + canCancelContentTouches: true, + centerContent: true, + contentInset: {diff: require('../../Utilities/differ/pointsDiffer')}, + contentOffset: {diff: require('../../Utilities/differ/pointsDiffer')}, + contentInsetAdjustmentBehavior: true, + decelerationRate: true, + directionalLockEnabled: true, + disableIntervalMomentum: true, + endFillColor: {process: require('../../StyleSheet/processColor')}, + fadingEdgeLength: true, + indicatorStyle: true, + keyboardDismissMode: true, + maintainVisibleContentPosition: true, + maximumZoomScale: true, + minimumZoomScale: true, + nestedScrollEnabled: true, + onMomentumScrollBegin: true, + onMomentumScrollEnd: true, + onScroll: true, + onScrollBeginDrag: true, + onScrollEndDrag: true, + onScrollToTop: true, + overScrollMode: true, + pagingEnabled: true, + persistentScrollbar: true, + pinchGestureEnabled: true, + scrollEnabled: true, + scrollEventThrottle: true, + scrollIndicatorInsets: { + diff: require('../../Utilities/differ/pointsDiffer'), + }, + scrollPerfTag: true, + scrollToOverflowEnabled: true, + scrollsToTop: true, + sendMomentumEvents: true, + showsHorizontalScrollIndicator: true, + showsVerticalScrollIndicator: true, + snapToAlignment: true, + snapToEnd: true, + snapToInterval: true, + snapToOffsets: true, + snapToStart: true, + zoomScale: true, + + DEPRECATED_sendUpdatedChildFrames: true, + }, +}; + +module.exports = (ScrollViewViewConfig: GeneratedViewConfig); diff --git a/Libraries/Utilities/registerGeneratedViewConfig.js b/Libraries/Utilities/registerGeneratedViewConfig.js index cad4622fb26..8164fede07f 100644 --- a/Libraries/Utilities/registerGeneratedViewConfig.js +++ b/Libraries/Utilities/registerGeneratedViewConfig.js @@ -14,7 +14,7 @@ const ReactNativeViewConfigRegistry = require('../Renderer/shims/ReactNativeView const ReactNativeViewViewConfig = require('../Components/View/ReactNativeViewViewConfig'); import verifyComponentAttributeEquivalence from './verifyComponentAttributeEquivalence'; -type GeneratedViewConfig = { +export type GeneratedViewConfig = { uiViewClassName: string, bubblingEventTypes?: $ReadOnly<{ [eventName: string]: $ReadOnly<{|