Skip to content

Commit 5b6ff01

Browse files
sahrensfacebook-github-bot
authored andcommittedJul 5, 2018
Remove ScrollView.propTypes
Summary: We're unifying on flow types, and propTypes require non-trivial resources to initialize in aggregate. Some open source code might depend on extracting ScrollView.propTypes which will now fail. To fix, simplly remove these dependencies and use flow or typescript for verifying correct prop usage instead. Reviewed By: TheSavior Differential Revision: D8726371 fbshipit-source-id: 19e9540794db97a9e356615b544759a0753fd68c
1 parent f40de0e commit 5b6ff01

File tree

4 files changed

+112
-245
lines changed

4 files changed

+112
-245
lines changed
 

‎Libraries/Components/ScrollView/InternalScrollViewType.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class InternalScrollViewType<Props> extends ReactNative.NativeComponent<Props> {
2222
) {}
2323

2424
flashScrollIndicators() {}
25-
scrollToEnd(options?: {animated?: boolean}) {}
25+
propTypes: empty;
26+
scrollToEnd(options?: ?{animated?: boolean}) {}
2627
scrollWithoutAnimationTo(y: number = 0, x: number = 0) {}
2728

2829
getScrollResponder(): any {}

‎Libraries/Components/ScrollView/ScrollView.js

+1-109
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,13 @@
1111
'use strict';
1212

1313
const AnimatedImplementation = require('AnimatedImplementation');
14-
const ColorPropType = require('ColorPropType');
15-
const EdgeInsetsPropType = require('EdgeInsetsPropType');
1614
const Platform = require('Platform');
17-
const PointPropType = require('PointPropType');
18-
const PropTypes = require('prop-types');
1915
const React = require('React');
2016
const ReactNative = require('ReactNative');
2117
const ScrollResponder = require('ScrollResponder');
2218
const ScrollViewStickyHeader = require('ScrollViewStickyHeader');
2319
const StyleSheet = require('StyleSheet');
24-
const StyleSheetPropType = require('StyleSheetPropType');
2520
const View = require('View');
26-
const ViewPropTypes = require('ViewPropTypes');
27-
const ViewStylePropTypes = require('ViewStylePropTypes');
2821
const InternalScrollViewType = require('InternalScrollViewType');
2922

3023
const createReactClass = require('create-react-class');
@@ -531,95 +524,6 @@ export type Props = $ReadOnly<{|
531524
*/
532525
const ScrollView = createReactClass({
533526
displayName: 'ScrollView',
534-
propTypes: {
535-
...ViewPropTypes,
536-
automaticallyAdjustContentInsets: PropTypes.bool,
537-
contentInset: EdgeInsetsPropType,
538-
contentOffset: PointPropType,
539-
bounces: PropTypes.bool,
540-
bouncesZoom: PropTypes.bool,
541-
alwaysBounceHorizontal: PropTypes.bool,
542-
alwaysBounceVertical: PropTypes.bool,
543-
centerContent: PropTypes.bool,
544-
contentContainerStyle: StyleSheetPropType(ViewStylePropTypes),
545-
decelerationRate: PropTypes.oneOfType([
546-
PropTypes.oneOf(['fast', 'normal']),
547-
PropTypes.number,
548-
]),
549-
horizontal: PropTypes.bool,
550-
indicatorStyle: PropTypes.oneOf([
551-
'default', // default
552-
'black',
553-
'white',
554-
]),
555-
invertStickyHeaders: PropTypes.bool,
556-
directionalLockEnabled: PropTypes.bool,
557-
canCancelContentTouches: PropTypes.bool,
558-
keyboardDismissMode: PropTypes.oneOf([
559-
'none', // default
560-
'on-drag', // Cross-platform
561-
'interactive', // iOS-only
562-
]),
563-
keyboardShouldPersistTaps: PropTypes.oneOf([
564-
'always',
565-
'never',
566-
'handled',
567-
false,
568-
true,
569-
]),
570-
maintainVisibleContentPosition: PropTypes.shape({
571-
minIndexForVisible: PropTypes.number.isRequired,
572-
autoscrollToTopThreshold: PropTypes.number,
573-
}),
574-
maximumZoomScale: PropTypes.number,
575-
minimumZoomScale: PropTypes.number,
576-
nestedScrollEnabled: PropTypes.bool,
577-
onMomentumScrollBegin: PropTypes.func,
578-
onMomentumScrollEnd: PropTypes.func,
579-
onScroll: PropTypes.func,
580-
onScrollBeginDrag: PropTypes.func,
581-
onScrollEndDrag: PropTypes.func,
582-
onContentSizeChange: PropTypes.func,
583-
pagingEnabled: PropTypes.bool,
584-
pinchGestureEnabled: PropTypes.bool,
585-
scrollEnabled: PropTypes.bool,
586-
scrollEventThrottle: PropTypes.number,
587-
scrollIndicatorInsets: EdgeInsetsPropType,
588-
scrollsToTop: PropTypes.bool,
589-
showsHorizontalScrollIndicator: PropTypes.bool,
590-
showsVerticalScrollIndicator: PropTypes.bool,
591-
stickyHeaderIndices: PropTypes.arrayOf(PropTypes.number),
592-
snapToInterval: PropTypes.number,
593-
snapToAlignment: PropTypes.oneOf([
594-
'start', // default
595-
'center',
596-
'end',
597-
]),
598-
removeClippedSubviews: PropTypes.bool,
599-
zoomScale: PropTypes.number,
600-
contentInsetAdjustmentBehavior: PropTypes.oneOf([
601-
'automatic',
602-
'scrollableAxes',
603-
'never', // default
604-
'always',
605-
]),
606-
refreshControl: PropTypes.element,
607-
608-
endFillColor: ColorPropType,
609-
610-
scrollPerfTag: PropTypes.string,
611-
612-
overScrollMode: PropTypes.oneOf(['auto', 'always', 'never']),
613-
DEPRECATED_sendUpdatedChildFrames: PropTypes.bool,
614-
scrollBarThumbImage: PropTypes.oneOfType([
615-
PropTypes.shape({
616-
uri: PropTypes.string,
617-
}),
618-
// Opaque type returned by import IMAGE from './image.jpg'
619-
PropTypes.number,
620-
]),
621-
},
622-
623527
mixins: [ScrollResponder.Mixin],
624528

625529
_scrollAnimatedValue: (new AnimatedImplementation.Value(
@@ -637,11 +541,9 @@ const ScrollView = createReactClass({
637541

638542
UNSAFE_componentWillMount: function() {
639543
this._scrollAnimatedValue = new AnimatedImplementation.Value(
640-
// $FlowFixMe
641544
this.props.contentOffset ? this.props.contentOffset.y : 0,
642545
);
643546
this._scrollAnimatedValue.setOffset(
644-
// $FlowFixMe
645547
this.props.contentInset ? this.props.contentInset.top : 0,
646548
);
647549
this._stickyHeaderRefs = new Map();
@@ -784,7 +686,6 @@ const ScrollView = createReactClass({
784686
if (!this.props.stickyHeaderIndices) {
785687
return;
786688
}
787-
// $FlowFixMe Invalid prop usage
788689
const childArray = React.Children.toArray(this.props.children);
789690
if (key !== this._getKeyForIndex(index, childArray)) {
790691
// ignore stale layout update
@@ -794,10 +695,8 @@ const ScrollView = createReactClass({
794695
const layoutY = event.nativeEvent.layout.y;
795696
this._headerLayoutYs.set(key, layoutY);
796697

797-
// $FlowFixMe Invalid prop usage
798698
const indexOfIndex = this.props.stickyHeaderIndices.indexOf(index);
799699
const previousHeaderIndex = this.props.stickyHeaderIndices[
800-
// $FlowFixMe Invalid prop usage
801700
indexOfIndex - 1
802701
];
803702
if (previousHeaderIndex != null) {
@@ -918,16 +817,13 @@ const ScrollView = createReactClass({
918817
const hasStickyHeaders =
919818
stickyHeaderIndices && stickyHeaderIndices.length > 0;
920819
const childArray =
921-
// $FlowFixMe Invalid prop usage
922820
hasStickyHeaders && React.Children.toArray(this.props.children);
923821
const children = hasStickyHeaders
924822
? // $FlowFixMe Invalid prop usage
925823
childArray.map((child, index) => {
926-
// $FlowFixMe Invalid prop usage
927824
const indexOfIndex = child ? stickyHeaderIndices.indexOf(index) : -1;
928825
if (indexOfIndex > -1) {
929826
const key = child.key;
930-
// $FlowFixMe Invalid prop usage
931827
const nextIndex = stickyHeaderIndices[indexOfIndex + 1];
932828
return (
933829
<ScrollViewStickyHeader
@@ -949,8 +845,7 @@ const ScrollView = createReactClass({
949845
return child;
950846
}
951847
})
952-
: // $FlowFixMe Invalid prop usage
953-
this.props.children;
848+
: this.props.children;
954849
const contentContainer = (
955850
<ScrollContentContainerViewClass
956851
{...contentSizeChangeProps}
@@ -1039,7 +934,6 @@ const ScrollView = createReactClass({
1039934
// On iOS the RefreshControl is a child of the ScrollView.
1040935
// tvOS lacks native support for RefreshControl, so don't include it in that case
1041936
return (
1042-
// $FlowFixMe Invalid prop usage
1043937
<ScrollViewClass {...props} ref={this._setScrollViewRef}>
1044938
{Platform.isTV ? null : refreshControl}
1045939
{contentContainer}
@@ -1058,15 +952,13 @@ const ScrollView = createReactClass({
1058952
<ScrollViewClass
1059953
{...props}
1060954
style={baseStyle}
1061-
// $FlowFixMe Invalid prop usage
1062955
ref={this._setScrollViewRef}>
1063956
{contentContainer}
1064957
</ScrollViewClass>,
1065958
);
1066959
}
1067960
}
1068961
return (
1069-
// $FlowFixMe Invalid prop usage
1070962
<ScrollViewClass {...props} ref={this._setScrollViewRef}>
1071963
{contentContainer}
1072964
</ScrollViewClass>

‎Libraries/Components/WebView/WebView.ios.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ class WebView extends React.Component {
203203
* - fast: 0.99 (the default for iOS web view)
204204
* @platform ios
205205
*/
206-
decelerationRate: ScrollView.propTypes.decelerationRate,
206+
decelerationRate: PropTypes.oneOfType([
207+
PropTypes.oneOf(['fast', 'normal']),
208+
PropTypes.number,
209+
]),
207210
/**
208211
* Boolean value that determines whether scrolling is enabled in the
209212
* `WebView`. The default value is `true`.

‎Libraries/Lists/ListView/ListView.js

+105-134
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const InternalListViewType = require('InternalListViewType');
1313
const ListViewDataSource = require('ListViewDataSource');
1414
const Platform = require('Platform');
1515
const React = require('React');
16-
const PropTypes = require('prop-types');
1716
const ReactNative = require('ReactNative');
1817
const RCTScrollViewManager = require('NativeModules').ScrollViewManager;
1918
const ScrollView = require('ScrollView');
@@ -37,22 +36,124 @@ const DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;
3736
type Props = $ReadOnly<{|
3837
...ScrollViewProps,
3938

39+
/**
40+
* An instance of [ListView.DataSource](docs/listviewdatasource.html) to use
41+
*/
4042
dataSource: ListViewDataSource,
43+
/**
44+
* (sectionID, rowID, adjacentRowHighlighted) => renderable
45+
*
46+
* If provided, a renderable component to be rendered as the separator
47+
* below each row but not the last row if there is a section header below.
48+
* Take a sectionID and rowID of the row above and whether its adjacent row
49+
* is highlighted.
50+
*/
4151
renderSeparator?: ?Function,
52+
/**
53+
* (rowData, sectionID, rowID, highlightRow) => renderable
54+
*
55+
* Takes a data entry from the data source and its ids and should return
56+
* a renderable component to be rendered as the row. By default the data
57+
* is exactly what was put into the data source, but it's also possible to
58+
* provide custom extractors. ListView can be notified when a row is
59+
* being highlighted by calling `highlightRow(sectionID, rowID)`. This
60+
* sets a boolean value of adjacentRowHighlighted in renderSeparator, allowing you
61+
* to control the separators above and below the highlighted row. The highlighted
62+
* state of a row can be reset by calling highlightRow(null).
63+
*/
4264
renderRow: Function,
65+
/**
66+
* How many rows to render on initial component mount. Use this to make
67+
* it so that the first screen worth of data appears at one time instead of
68+
* over the course of multiple frames.
69+
*/
4370
initialListSize?: ?number,
71+
/**
72+
* Called when all rows have been rendered and the list has been scrolled
73+
* to within onEndReachedThreshold of the bottom. The native scroll
74+
* event is provided.
75+
*/
4476
onEndReached?: ?Function,
77+
/**
78+
* Threshold in pixels (virtual, not physical) for calling onEndReached.
79+
*/
4580
onEndReachedThreshold?: ?number,
81+
/**
82+
* Number of rows to render per event loop. Note: if your 'rows' are actually
83+
* cells, i.e. they don't span the full width of your view (as in the
84+
* ListViewGridLayoutExample), you should set the pageSize to be a multiple
85+
* of the number of cells per row, otherwise you're likely to see gaps at
86+
* the edge of the ListView as new pages are loaded.
87+
*/
4688
pageSize?: ?number,
89+
/**
90+
* () => renderable
91+
*
92+
* The header and footer are always rendered (if these props are provided)
93+
* on every render pass. If they are expensive to re-render, wrap them
94+
* in StaticContainer or other mechanism as appropriate. Footer is always
95+
* at the bottom of the list, and header at the top, on every render pass.
96+
* In a horizontal ListView, the header is rendered on the left and the
97+
* footer on the right.
98+
*/
4799
renderFooter?: ?Function,
48100
renderHeader?: ?Function,
101+
/**
102+
* (sectionData, sectionID) => renderable
103+
*
104+
* If provided, a header is rendered for this section.
105+
*/
49106
renderSectionHeader?: ?Function,
107+
/**
108+
* (props) => renderable
109+
*
110+
* A function that returns the scrollable component in which the list rows
111+
* are rendered. Defaults to returning a ScrollView with the given props.
112+
*/
50113
renderScrollComponent?: ?Function,
114+
/**
115+
* How early to start rendering rows before they come on screen, in
116+
* pixels.
117+
*/
51118
scrollRenderAheadDistance?: ?number,
119+
/**
120+
* (visibleRows, changedRows) => void
121+
*
122+
* Called when the set of visible rows changes. `visibleRows` maps
123+
* { sectionID: { rowID: true }} for all the visible rows, and
124+
* `changedRows` maps { sectionID: { rowID: true | false }} for the rows
125+
* that have changed their visibility, with true indicating visible, and
126+
* false indicating the view has moved out of view.
127+
*/
52128
onChangeVisibleRows?: ?Function,
129+
/**
130+
* A performance optimization for improving scroll perf of
131+
* large lists, used in conjunction with overflow: 'hidden' on the row
132+
* containers. This is enabled by default.
133+
*/
53134
removeClippedSubviews?: ?boolean,
135+
/**
136+
* Makes the sections headers sticky. The sticky behavior means that it
137+
* will scroll with the content at the top of the section until it reaches
138+
* the top of the screen, at which point it will stick to the top until it
139+
* is pushed off the screen by the next section header. This property is
140+
* not supported in conjunction with `horizontal={true}`. Only enabled by
141+
* default on iOS because of typical platform standards.
142+
*/
54143
stickySectionHeadersEnabled?: ?boolean,
144+
/**
145+
* An array of child indices determining which children get docked to the
146+
* top of the screen when scrolling. For example, passing
147+
* `stickyHeaderIndices={[0]}` will cause the first child to be fixed to the
148+
* top of the scroll view. This property is not supported in conjunction
149+
* with `horizontal={true}`.
150+
*/
55151
stickyHeaderIndices?: ?$ReadOnlyArray<number>,
152+
/**
153+
* Flag indicating whether empty section headers should be rendered. In the future release
154+
* empty section headers will be rendered by default, and the flag will be deprecated.
155+
* If empty sections are not desired to be rendered their indices should be excluded from sectionID object.
156+
*/
56157
enableEmptySections?: ?boolean,
57158
|}>;
58159

@@ -128,136 +229,6 @@ const ListView = createReactClass({
128229
DataSource: ListViewDataSource,
129230
},
130231

131-
/**
132-
* You must provide a renderRow function. If you omit any of the other render
133-
* functions, ListView will simply skip rendering them.
134-
*
135-
* - renderRow(rowData, sectionID, rowID, highlightRow);
136-
* - renderSectionHeader(sectionData, sectionID);
137-
*/
138-
propTypes: {
139-
...ScrollView.propTypes,
140-
/**
141-
* An instance of [ListView.DataSource](docs/listviewdatasource.html) to use
142-
*/
143-
dataSource: PropTypes.instanceOf(ListViewDataSource).isRequired,
144-
/**
145-
* (sectionID, rowID, adjacentRowHighlighted) => renderable
146-
*
147-
* If provided, a renderable component to be rendered as the separator
148-
* below each row but not the last row if there is a section header below.
149-
* Take a sectionID and rowID of the row above and whether its adjacent row
150-
* is highlighted.
151-
*/
152-
renderSeparator: PropTypes.func,
153-
/**
154-
* (rowData, sectionID, rowID, highlightRow) => renderable
155-
*
156-
* Takes a data entry from the data source and its ids and should return
157-
* a renderable component to be rendered as the row. By default the data
158-
* is exactly what was put into the data source, but it's also possible to
159-
* provide custom extractors. ListView can be notified when a row is
160-
* being highlighted by calling `highlightRow(sectionID, rowID)`. This
161-
* sets a boolean value of adjacentRowHighlighted in renderSeparator, allowing you
162-
* to control the separators above and below the highlighted row. The highlighted
163-
* state of a row can be reset by calling highlightRow(null).
164-
*/
165-
renderRow: PropTypes.func.isRequired,
166-
/**
167-
* How many rows to render on initial component mount. Use this to make
168-
* it so that the first screen worth of data appears at one time instead of
169-
* over the course of multiple frames.
170-
*/
171-
initialListSize: PropTypes.number.isRequired,
172-
/**
173-
* Called when all rows have been rendered and the list has been scrolled
174-
* to within onEndReachedThreshold of the bottom. The native scroll
175-
* event is provided.
176-
*/
177-
onEndReached: PropTypes.func,
178-
/**
179-
* Threshold in pixels (virtual, not physical) for calling onEndReached.
180-
*/
181-
onEndReachedThreshold: PropTypes.number.isRequired,
182-
/**
183-
* Number of rows to render per event loop. Note: if your 'rows' are actually
184-
* cells, i.e. they don't span the full width of your view (as in the
185-
* ListViewGridLayoutExample), you should set the pageSize to be a multiple
186-
* of the number of cells per row, otherwise you're likely to see gaps at
187-
* the edge of the ListView as new pages are loaded.
188-
*/
189-
pageSize: PropTypes.number.isRequired,
190-
/**
191-
* () => renderable
192-
*
193-
* The header and footer are always rendered (if these props are provided)
194-
* on every render pass. If they are expensive to re-render, wrap them
195-
* in StaticContainer or other mechanism as appropriate. Footer is always
196-
* at the bottom of the list, and header at the top, on every render pass.
197-
* In a horizontal ListView, the header is rendered on the left and the
198-
* footer on the right.
199-
*/
200-
renderFooter: PropTypes.func,
201-
renderHeader: PropTypes.func,
202-
/**
203-
* (sectionData, sectionID) => renderable
204-
*
205-
* If provided, a header is rendered for this section.
206-
*/
207-
renderSectionHeader: PropTypes.func,
208-
/**
209-
* (props) => renderable
210-
*
211-
* A function that returns the scrollable component in which the list rows
212-
* are rendered. Defaults to returning a ScrollView with the given props.
213-
*/
214-
renderScrollComponent: PropTypes.func.isRequired,
215-
/**
216-
* How early to start rendering rows before they come on screen, in
217-
* pixels.
218-
*/
219-
scrollRenderAheadDistance: PropTypes.number.isRequired,
220-
/**
221-
* (visibleRows, changedRows) => void
222-
*
223-
* Called when the set of visible rows changes. `visibleRows` maps
224-
* { sectionID: { rowID: true }} for all the visible rows, and
225-
* `changedRows` maps { sectionID: { rowID: true | false }} for the rows
226-
* that have changed their visibility, with true indicating visible, and
227-
* false indicating the view has moved out of view.
228-
*/
229-
onChangeVisibleRows: PropTypes.func,
230-
/**
231-
* A performance optimization for improving scroll perf of
232-
* large lists, used in conjunction with overflow: 'hidden' on the row
233-
* containers. This is enabled by default.
234-
*/
235-
removeClippedSubviews: PropTypes.bool,
236-
/**
237-
* Makes the sections headers sticky. The sticky behavior means that it
238-
* will scroll with the content at the top of the section until it reaches
239-
* the top of the screen, at which point it will stick to the top until it
240-
* is pushed off the screen by the next section header. This property is
241-
* not supported in conjunction with `horizontal={true}`. Only enabled by
242-
* default on iOS because of typical platform standards.
243-
*/
244-
stickySectionHeadersEnabled: PropTypes.bool,
245-
/**
246-
* An array of child indices determining which children get docked to the
247-
* top of the screen when scrolling. For example, passing
248-
* `stickyHeaderIndices={[0]}` will cause the first child to be fixed to the
249-
* top of the scroll view. This property is not supported in conjunction
250-
* with `horizontal={true}`.
251-
*/
252-
stickyHeaderIndices: PropTypes.arrayOf(PropTypes.number).isRequired,
253-
/**
254-
* Flag indicating whether empty section headers should be rendered. In the future release
255-
* empty section headers will be rendered by default, and the flag will be deprecated.
256-
* If empty sections are not desired to be rendered their indices should be excluded from sectionID object.
257-
*/
258-
enableEmptySections: PropTypes.bool,
259-
},
260-
261232
/**
262233
* Exports some data, e.g. for perf investigations or analytics.
263234
*/
@@ -296,7 +267,7 @@ const ListView = createReactClass({
296267
*
297268
* See `ScrollView#scrollTo`.
298269
*/
299-
scrollTo: function(...args: Array<mixed>) {
270+
scrollTo: function(...args: any) {
300271
if (this._scrollComponent && this._scrollComponent.scrollTo) {
301272
this._scrollComponent.scrollTo(...args);
302273
}
@@ -312,7 +283,7 @@ const ListView = createReactClass({
312283
*
313284
* See `ScrollView#scrollToEnd`.
314285
*/
315-
scrollToEnd: function(options?: ?{animated?: ?boolean}) {
286+
scrollToEnd: function(options?: ?{animated?: boolean}) {
316287
if (this._scrollComponent) {
317288
if (this._scrollComponent.scrollToEnd) {
318289
this._scrollComponent.scrollToEnd(options);
@@ -366,7 +337,7 @@ const ListView = createReactClass({
366337
},
367338

368339
getInnerViewNode: function() {
369-
return this._scrollComponent.getInnerViewNode();
340+
return this._scrollComponent && this._scrollComponent.getInnerViewNode();
370341
},
371342

372343
UNSAFE_componentWillMount: function() {

0 commit comments

Comments
 (0)
Please sign in to comment.