Skip to content

Commit

Permalink
Adding $FlowFixMe to invalid prop accesses
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7977387

fbshipit-source-id: 442e7445be62f78bdf166a2b97ef031e39877355
  • Loading branch information
elicwhite authored and facebook-github-bot committed May 12, 2018
1 parent 7ba7acd commit f19ee28
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ const ScrollView = createReactClass({
},

_getKeyForIndex: function(index, childArray) {
// $FlowFixMe Invalid prop usage
const child = childArray[index];
return child && child.key;
},
Expand Down Expand Up @@ -668,6 +669,7 @@ const ScrollView = createReactClass({
if (!this.props.stickyHeaderIndices) {
return;
}
// $FlowFixMe Invalid prop usage
const childArray = React.Children.toArray(this.props.children);
if (key !== this._getKeyForIndex(index, childArray)) {
// ignore stale layout update
Expand All @@ -677,8 +679,10 @@ const ScrollView = createReactClass({
const layoutY = event.nativeEvent.layout.y;
this._headerLayoutYs.set(key, layoutY);

// $FlowFixMe Invalid prop usage
const indexOfIndex = this.props.stickyHeaderIndices.indexOf(index);
const previousHeaderIndex = this.props.stickyHeaderIndices[
// $FlowFixMe Invalid prop usage
indexOfIndex - 1
];
if (previousHeaderIndex != null) {
Expand Down Expand Up @@ -799,12 +803,16 @@ const ScrollView = createReactClass({
const hasStickyHeaders =
stickyHeaderIndices && stickyHeaderIndices.length > 0;
const childArray =
// $FlowFixMe Invalid prop usage
hasStickyHeaders && React.Children.toArray(this.props.children);
const children = hasStickyHeaders
// $FlowFixMe Invalid prop usage
? childArray.map((child, index) => {
// $FlowFixMe Invalid prop usage
const indexOfIndex = child ? stickyHeaderIndices.indexOf(index) : -1;
if (indexOfIndex > -1) {
const key = child.key;
// $FlowFixMe Invalid prop usage
const nextIndex = stickyHeaderIndices[indexOfIndex + 1];
return (
<ScrollViewStickyHeader
Expand All @@ -826,10 +834,12 @@ const ScrollView = createReactClass({
return child;
}
})
// $FlowFixMe Invalid prop usage
: this.props.children;
const contentContainer = (
<ScrollContentContainerViewClass
{...contentSizeChangeProps}
// $FlowFixMe Invalid prop usage
ref={this._setInnerViewRef}
style={contentContainerStyle}
removeClippedSubviews={
Expand Down Expand Up @@ -913,6 +923,7 @@ const ScrollView = createReactClass({
// On iOS the RefreshControl is a child of the ScrollView.
// tvOS lacks native support for RefreshControl, so don't include it in that case
return (
// $FlowFixMe Invalid prop usage
<ScrollViewClass {...props} ref={this._setScrollViewRef}>
{Platform.isTVOS ? null : refreshControl}
{contentContainer}
Expand All @@ -931,13 +942,15 @@ const ScrollView = createReactClass({
<ScrollViewClass
{...props}
style={baseStyle}
// $FlowFixMe Invalid prop usage
ref={this._setScrollViewRef}>
{contentContainer}
</ScrollViewClass>,
);
}
}
return (
// $FlowFixMe Invalid prop usage
<ScrollViewClass {...props} ref={this._setScrollViewRef}>
{contentContainer}
</ScrollViewClass>
Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ const TextInput = createReactClass({
},

_onTextInput: function(event: Event) {
// $FlowFixMe Invalid prop usage
this.props.onTextInput && this.props.onTextInput(event);
},

Expand Down
1 change: 1 addition & 0 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const TouchableBounce = createReactClass({
},

touchableGetPressRectOffset: function(): typeof PRESS_RETENTION_OFFSET {
// $FlowFixMe Invalid prop usage
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

Expand Down
12 changes: 12 additions & 0 deletions Libraries/Components/Touchable/TouchableHighlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ const TouchableHighlight = createReactClass({
getDefaultProps: () => DEFAULT_PROPS,

getInitialState: function() {
// $FlowFixMe Invalid prop usage
this._isMounted = false;
if (this.props.testOnly_pressed) {
return {
Expand All @@ -211,11 +212,13 @@ const TouchableHighlight = createReactClass({
},

componentDidMount: function() {
// $FlowFixMe Invalid prop usage
this._isMounted = true;
ensurePositiveDelayProps(this.props);
},

componentWillUnmount: function() {
// $FlowFixMe Invalid prop usage
this._isMounted = false;
clearTimeout(this._hideTimeout);
},
Expand All @@ -235,12 +238,14 @@ const TouchableHighlight = createReactClass({
*/
touchableHandleActivePressIn: function(e: PressEvent) {
clearTimeout(this._hideTimeout);
// $FlowFixMe Invalid prop usage
this._hideTimeout = null;
this._showUnderlay();
this.props.onPressIn && this.props.onPressIn(e);
},

touchableHandleActivePressOut: function(e: PressEvent) {
// $FlowFixMe Invalid prop usage
if (!this._hideTimeout) {
this._hideUnderlay();
}
Expand All @@ -251,6 +256,7 @@ const TouchableHighlight = createReactClass({
clearTimeout(this._hideTimeout);
if (!Platform.isTVOS) {
this._showUnderlay();
// $FlowFixMe Invalid prop usage
this._hideTimeout = setTimeout(
this._hideUnderlay,
this.props.delayPressOut,
Expand Down Expand Up @@ -284,6 +290,7 @@ const TouchableHighlight = createReactClass({
},

_showUnderlay: function() {
// $FlowFixMe Invalid prop usage
if (!this._isMounted || !this._hasPressHandler()) {
return;
}
Expand All @@ -300,6 +307,7 @@ const TouchableHighlight = createReactClass({

_hideUnderlay: function() {
clearTimeout(this._hideTimeout);
// $FlowFixMe Invalid prop usage
this._hideTimeout = null;
if (this.props.testOnly_pressed) {
return;
Expand All @@ -323,10 +331,12 @@ const TouchableHighlight = createReactClass({
},

render: function() {
// $FlowFixMe Invalid prop usage
const child = React.Children.only(this.props.children);
return (
<View
accessible={this.props.accessible !== false}
// $FlowFixMe Invalid prop usage
accessibilityLabel={this.props.accessibilityLabel}
accessibilityComponentType={this.props.accessibilityComponentType}
accessibilityTraits={this.props.accessibilityTraits}
Expand All @@ -347,7 +357,9 @@ const TouchableHighlight = createReactClass({
onResponderMove={this.touchableHandleResponderMove}
onResponderRelease={this.touchableHandleResponderRelease}
onResponderTerminate={this.touchableHandleResponderTerminate}
// $FlowFixMe Invalid prop usage
nativeID={this.props.nativeID}
// $FlowFixMe Invalid prop usage
testID={this.props.testID}>
{React.cloneElement(child, {
style: StyleSheet.compose(
Expand Down
4 changes: 4 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const TouchableWithoutFeedback = createReactClass({
},

touchableGetPressRectOffset: function(): typeof PRESS_RETENTION_OFFSET {
// $FlowFixMe Invalid prop usage
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},

Expand Down Expand Up @@ -194,10 +195,13 @@ const TouchableWithoutFeedback = createReactClass({
: child.props.style;
return (React: any).cloneElement(child, {
accessible: this.props.accessible !== false,
// $FlowFixMe Invalid prop usage
accessibilityLabel: this.props.accessibilityLabel,
accessibilityComponentType: this.props.accessibilityComponentType,
accessibilityTraits: this.props.accessibilityTraits,
// $FlowFixMe Invalid prop usage
nativeID: this.props.nativeID,
// $FlowFixMe Invalid prop usage
testID: this.props.testID,
onLayout: this.props.onLayout,
hitSlop: this.props.hitSlop,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Experimental/SwipeableRow/SwipeableListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ class SwipeableListView extends React.Component<Props, State> {

render(): React.Node {
return (
// $FlowFixMe Invalid prop usage
<ListView
{...this.props}
ref={ref => {
// $FlowFixMe Invalid prop usage
this._listViewRef = ref;
}}
dataSource={this.state.dataSource.getDataSource()}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
_virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];

_captureRef = ref => {
// $FlowFixMe Invalid prop usage
this._listRef = ref;
};

Expand Down
2 changes: 2 additions & 0 deletions Libraries/Lists/ListView/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,10 @@ const ListView = createReactClass({
if (props.removeClippedSubviews === undefined) {
props.removeClippedSubviews = true;
}
// $FlowFixMe Invalid prop usage
Object.assign(props, {
onScroll: this._onScroll,
// $FlowFixMe Invalid prop usage
stickyHeaderIndices: this.props.stickyHeaderIndices.concat(
stickySectionHeaderIndices,
),
Expand Down
7 changes: 7 additions & 0 deletions Libraries/Lists/MetroListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
}
scrollToOffset(params: {animated?: ?boolean, offset: number}) {
const {animated, offset} = params;
// $FlowFixMe Invalid prop usage
this._listRef.scrollTo(
this.props.horizontal ? {x: offset, animated} : {y: offset, animated},
);
Expand All @@ -94,6 +95,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
}
setNativeProps(props: Object) {
if (this._listRef) {
// $FlowFixMe Invalid prop usage
this._listRef.setNativeProps(props);
}
}
Expand All @@ -102,6 +104,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
renderScrollComponent: (props: Props) => {
if (props.onRefresh) {
return (
// $FlowFixMe Invalid prop usage
<ScrollView
{...props}
refreshControl={
Expand All @@ -117,6 +120,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
/>
);
} else {
// $FlowFixMe Invalid prop usage
return <ScrollView {...props} />;
}
},
Expand All @@ -135,13 +139,15 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
}
render() {
return (
// $FlowFixMe Invalid prop usage
<ListView
{...this.props}
dataSource={this.state.ds}
ref={this._captureRef}
renderRow={this._renderRow}
renderFooter={this.props.FooterComponent && this._renderFooter}
renderSectionHeader={this.props.sections && this._renderSectionHeader}
// $FlowFixMe Invalid prop usage
renderSeparator={this.props.SeparatorComponent && this._renderSeparator}
/>
);
Expand All @@ -167,6 +173,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
} else {
invariant(!props.sections, 'Cannot have both sections and items props.');
return {
// $FlowFixMe Invalid prop usage
ds: state.ds.cloneWithRows(props.items),
sectionHeaderData,
};
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Lists/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
*/
recordInteraction() {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
// $FlowFixMe Invalid prop usage
listRef && listRef.recordInteraction();
}

Expand All @@ -294,6 +295,7 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
*/
flashScrollIndicators() {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
// $FlowFixMe Invalid prop usage
listRef && listRef.flashScrollIndicators();
}

Expand All @@ -303,20 +305,23 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
getScrollResponder(): ?ScrollView {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
// $FlowFixMe Invalid prop usage
return listRef.getScrollResponder();
}
}

getScrollableNode() {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
// $FlowFixMe Invalid prop usage
return listRef.getScrollableNode();
}
}

setNativeProps(props: Object) {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
// $FlowFixMe Invalid prop usage
listRef.setNativeProps(props);
}
}
Expand Down
3 changes: 3 additions & 0 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
(this.props.renderScrollComponent || this._defaultRenderScrollComponent)(
scrollProps,
),
// $FlowFixMe Invalid prop usage
{
ref: this._captureScrollRef,
},
Expand Down Expand Up @@ -1016,6 +1017,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
'`',
);
return (
// $FlowFixMe Invalid prop usage
<ScrollView
{...props}
refreshControl={
Expand All @@ -1032,6 +1034,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
/>
);
} else {
// $FlowFixMe Invalid prop usage
return <ScrollView {...props} />;
}
};
Expand Down
4 changes: 4 additions & 0 deletions RNTester/js/ScrollViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exports.examples = [
<View>
<ScrollView
ref={scrollView => {
// $FlowFixMe Invalid prop usage
_scrollView = scrollView;
}}
automaticallyAdjustContentInsets={false}
Expand Down Expand Up @@ -96,18 +97,21 @@ exports.examples = [
<Button
label="Scroll to start"
onPress={() => {
// $FlowFixMe Invalid prop usage
_scrollView.scrollTo({x: 0});
}}
/>
<Button
label="Scroll to end"
onPress={() => {
// $FlowFixMe Invalid prop usage
_scrollView.scrollToEnd({animated: true});
}}
/>
<Button
label="Flash scroll indicators"
onPress={() => {
// $FlowFixMe Invalid prop usage
_scrollView.flashScrollIndicators();
}}
/>
Expand Down

0 comments on commit f19ee28

Please sign in to comment.