Skip to content

Commit

Permalink
Improve Flow Type for ScrollResponder
Browse files Browse the repository at this point in the history
Summary: FlatList and VirtualizedList were typing this value as any instead of using the actual type from ScrollView. I started with that change and then fixed the type to solve the other callsites in the codebase.

Reviewed By: zackargyle

Differential Revision: D17089934

fbshipit-source-id: bfc22cec9993904d779cad37b1de7cb3c0484d2c
  • Loading branch information
elicwhite authored and facebook-github-bot committed Aug 28, 2019
1 parent c526b3f commit f8e5093
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,21 @@ if (Platform.OS === 'android') {
}

export type ScrollResponderType = {
...ScrollView,
// We'd like to do ...ScrollView here, however Flow doesn't seem
// to see the imperative methods of ScrollView that way. Workaround the
// issue by specifying them manually.
getScrollableNode: $PropertyType<ScrollView, 'getScrollableNode'>,
getInnerViewNode: $PropertyType<ScrollView, 'getInnerViewNode'>,
getNativeScrollRef: $PropertyType<ScrollView, 'getNativeScrollRef'>,

setNativeProps: $PropertyType<ScrollView, 'setNativeProps'>,
scrollTo: $PropertyType<ScrollView, 'scrollTo'>,
scrollWithoutAnimationTo: $PropertyType<
ScrollView,
'scrollWithoutAnimationTo',
>,
flashScrollIndicators: $PropertyType<ScrollView, 'flashScrollIndicators'>,

...typeof ScrollResponder.Mixin,
};

Expand Down
3 changes: 2 additions & 1 deletion Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const StyleSheet = require('../StyleSheet/StyleSheet');

const invariant = require('invariant');

import type {ScrollResponderType} from '../Components/ScrollView/ScrollView';
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {
ViewabilityConfig,
Expand Down Expand Up @@ -445,7 +446,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
/**
* Provides a handle to the underlying scroll responder.
*/
getScrollResponder(): any {
getScrollResponder(): ?ScrollResponderType {
if (this._listRef) {
return this._listRef.getScrollResponder();
}
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Lists/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const React = require('react');
const ScrollView = require('../Components/ScrollView/ScrollView');
const VirtualizedSectionList = require('./VirtualizedSectionList');

import type {ScrollResponderType} from '../Components/ScrollView/ScrollView';
import type {ViewToken} from './ViewabilityHelper';
import type {
SectionBase as _SectionBase,
Expand Down Expand Up @@ -275,7 +276,7 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
/**
* Provides a handle to the underlying scroll responder.
*/
getScrollResponder(): ?ScrollView {
getScrollResponder(): ?ScrollResponderType {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
if (listRef) {
return listRef.getScrollResponder();
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const warning = require('fbjs/lib/warning');

const {computeWindowedRenderLimits} = require('./VirtualizeUtils');

import type {ScrollResponderType} from '../Components/ScrollView/ScrollView';
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {
ViewabilityConfig,
Expand Down Expand Up @@ -431,7 +432,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
* Note that `this._scrollRef` might not be a `ScrollView`, so we
* need to check that it responds to `getScrollResponder` before calling it.
*/
getScrollResponder(): any {
getScrollResponder(): ?ScrollResponderType {
if (this._scrollRef && this._scrollRef.getScrollResponder) {
return this._scrollRef.getScrollResponder();
}
Expand Down

0 comments on commit f8e5093

Please sign in to comment.