Skip to content

Commit

Permalink
RN: Migrate ScrollView to NativeComponentRegistry
Browse files Browse the repository at this point in the history
Summary:
Migrates `ScrollView` (and its related native components) to use `NativeComponentRegistry`. This will enable it to be configured using experiments to conditionally use the native `ViewConfig` or verify the static `ViewConfig`.

This also cleans up a bunch of the modules and types related to defining the native `ScrollView` component.

This also proposes adopting the same module naming protocol was has been adopted for TurboModules (i.e. `NativeScrollView` instead of `ScrollViewNativeComponent`).

Changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D25098530

fbshipit-source-id: ff1394bfac023daf58e85d5f9068e4f8da3538be
  • Loading branch information
yungsters authored and facebook-github-bot committed Nov 19, 2020
1 parent d4e29ec commit 00e623d
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 148 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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 strict-local
* @format
*/

'use strict';

import {type HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentRegistry';
import {type ViewProps as Props} from '../View/ViewPropTypes';

const NativeAndroidHorizontalScrollContentView: HostComponent<Props> = NativeComponentRegistry.get<Props>(
'AndroidHorizontalScrollContentView',
() => ({
uiViewClassName: 'AndroidHorizontalScrollContentView',
bubblingEventTypes: {},
directEventTypes: {},
validAttributes: {},
}),
);

export default NativeAndroidHorizontalScrollContentView;
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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 strict-local
* @format
*/

'use strict';

import {type ScrollViewNativeProps as Props} from './ScrollViewNativeComponentType';
import {type HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentRegistry';

const NativeAndroidHorizontalScrollView: HostComponent<Props> = NativeComponentRegistry.get<Props>(
'AndroidHorizontalScrollView',
() => ({
uiViewClassName: 'AndroidHorizontalScrollView',
bubblingEventTypes: {},
directEventTypes: {},
validAttributes: {
decelerationRate: true,
disableIntervalMomentum: true,
endFillColor: {process: require('../../StyleSheet/processColor')},
fadingEdgeLength: true,
nestedScrollEnabled: true,
overScrollMode: true,
pagingEnabled: true,
persistentScrollbar: true,
scrollEnabled: true,
scrollPerfTag: true,
sendMomentumEvents: true,
showsHorizontalScrollIndicator: true,
snapToEnd: true,
snapToInterval: true,
snapToStart: true,
snapToOffsets: true,
contentOffset: true,
},
}),
);

export default NativeAndroidHorizontalScrollView;
87 changes: 87 additions & 0 deletions Libraries/Components/ScrollView/NativeScrollView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* 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 strict-local
* @format
*/

'use strict';

import {type ScrollViewNativeProps as Props} from './ScrollViewNativeComponentType';
import {type HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import * as NativeComponentRegistry from '../../NativeComponent/NativeComponentRegistry';

const NativeScrollView: HostComponent<Props> = NativeComponentRegistry.get<Props>(
'RCTScrollView',
() => ({
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,
inverted: 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,
},
}),
);

export default NativeScrollView;
27 changes: 13 additions & 14 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,30 @@ import type {
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {State as ScrollResponderState} from '../ScrollResponder';
import type {ViewProps} from '../View/ViewPropTypes';
import type {Props as ScrollViewStickyHeaderProps} from './ScrollViewStickyHeader';

import NativeAndroidHorizontalScrollContentView from './NativeAndroidHorizontalScrollContentView';
import NativeAndroidHorizontalScrollView from './NativeAndroidHorizontalScrollView';
import NativeScrollContentView from './NativeScrollContentView';
import NativeScrollView from './NativeScrollView';
import ScrollViewContext, {HORIZONTAL, VERTICAL} from './ScrollViewContext';
import ScrollViewNativeComponent from './ScrollViewNativeComponent';
import ScrollContentViewNativeComponent from './ScrollContentViewNativeComponent';
import AndroidHorizontalScrollViewNativeComponent from './AndroidHorizontalScrollViewNativeComponent';
import AndroidHorizontalScrollContentViewNativeComponent from './AndroidHorizontalScrollContentViewNativeComponent';
import type {Props as ScrollViewStickyHeaderProps} from './ScrollViewStickyHeader';

const {NativeHorizontalScrollViewTuple, NativeVerticalScrollViewTuple} =
Platform.OS === 'android'
? {
NativeHorizontalScrollViewTuple: [
AndroidHorizontalScrollViewNativeComponent,
AndroidHorizontalScrollContentViewNativeComponent,
NativeAndroidHorizontalScrollView,
NativeAndroidHorizontalScrollContentView,
],
NativeVerticalScrollViewTuple: [ScrollViewNativeComponent, View],
NativeVerticalScrollViewTuple: [NativeScrollView, View],
}
: {
NativeHorizontalScrollViewTuple: [
ScrollViewNativeComponent,
ScrollContentViewNativeComponent,
NativeScrollView,
NativeScrollContentView,
],
NativeVerticalScrollViewTuple: [
ScrollViewNativeComponent,
ScrollContentViewNativeComponent,
NativeScrollView,
NativeScrollContentView,
],
};

Expand Down Expand Up @@ -593,7 +592,7 @@ export type Props = $ReadOnly<{|
* measure, measureLayout, etc.
*/
scrollViewRef?: React.Ref<
typeof ScrollViewNativeComponent & ScrollViewImperativeMethods,
typeof NativeScrollView & ScrollViewImperativeMethods,
>,
|}>;

Expand Down
32 changes: 0 additions & 32 deletions Libraries/Components/ScrollView/ScrollViewNativeComponent.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

'use strict';

import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {ViewProps} from '../View/ViewPropTypes';
import type {ColorValue} from '../../StyleSheet/StyleSheet';
import type {EdgeInsetsProp} from '../../StyleSheet/EdgeInsetsPropType';
Expand Down Expand Up @@ -77,5 +76,3 @@ export type ScrollViewNativeProps = $ReadOnly<{
onResponderGrant?: ?(e: $FlowFixMe) => void | boolean,
...
}>;

export type ScrollViewNativeComponentType = HostComponent<ScrollViewNativeProps>;
4 changes: 2 additions & 2 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const StyleSheet = require('../StyleSheet/StyleSheet');

const invariant = require('invariant');

import typeof NativeScrollView from '../Components/ScrollView/NativeScrollView';
import {type ScrollResponderType} from '../Components/ScrollView/ScrollView';
import type {ScrollViewNativeComponentType} from '../Components/ScrollView/ScrollViewNativeComponentType.js';
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {
ViewToken,
Expand Down Expand Up @@ -373,7 +373,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
*/
getNativeScrollRef():
| ?React.ElementRef<typeof View>
| ?React.ElementRef<ScrollViewNativeComponentType> {
| ?React.ElementRef<NativeScrollView> {
if (this._listRef) {
return this._listRef.getScrollRef();
}
Expand Down

0 comments on commit 00e623d

Please sign in to comment.