Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting Flow related changes from CI 15749 to get builds back in order #12526

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Improve flow typing"
This reverts commit 63d3ea1.
  • Loading branch information
hramos committed Feb 22, 2017
commit fb093a46a89f65e7da7ad20037c15857e2cf6b0d
1 change: 0 additions & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ suppress_type=$FixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-9]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-9]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

unsafe.enable_getters_and_setters=true

Expand Down
5 changes: 2 additions & 3 deletions Examples/UIExplorer/js/FlatListExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class FlatListExample extends React.PureComponent {
key={(this.state.horizontal ? 'h' : 'v') + (this.state.fixedHeight ? 'f' : 'd')}
legacyImplementation={false}
numColumns={1}
onRefresh={this._onRefresh}
onRefresh={() => alert('onRefresh: nothing to refresh :P')}
onViewableItemsChanged={this._onViewableItemsChanged}
ref={this._captureRef}
refreshing={false}
Expand All @@ -121,7 +121,6 @@ class FlatListExample extends React.PureComponent {
_getItemLayout = (data: any, index: number) => {
return getItemLayout(data, index, this.state.horizontal);
};
_onRefresh = () => alert('onRefresh: nothing to refresh :P');
_renderItemComponent = ({item}) => {
return (
<ItemComponent
Expand Down Expand Up @@ -155,7 +154,7 @@ class FlatListExample extends React.PureComponent {
_pressItem = (key: number) => {
pressItem(this, key);
};
_listRef: FlatList<*>;
_listRef: FlatList;
}


Expand Down
56 changes: 22 additions & 34 deletions Libraries/Experimental/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,23 @@ const VirtualizedList = require('VirtualizedList');
const invariant = require('invariant');

import type {StyleObj} from 'StyleSheetTypes';
import type {ViewabilityConfig, Viewable} from 'ViewabilityHelper';
import type {Props as VirtualizedListProps} from 'VirtualizedList';
import type {Viewable} from 'ViewabilityHelper';

type Item = any;

type RequiredProps<ItemT> = {
type RequiredProps = {
/**
* Note this can be a normal class component, or a functional component, such as a render method
* on your main component.
*/
ItemComponent: ReactClass<{item: ItemT, index: number}>,
ItemComponent: ReactClass<{item: Item, index: number}>,
/**
* For simplicity, data is just a plain array. If you want to use something else, like an
* immutable list, use the underlying `VirtualizedList` directly.
*/
data: ?Array<ItemT>,
data: ?Array<Item>,
};
type OptionalProps<ItemT> = {
type OptionalProps = {
/**
* Rendered at the bottom of all the items.
*/
Expand All @@ -80,7 +79,7 @@ type OptionalProps<ItemT> = {
* Remember to include separator length (height or width) in your offset calculation if you
* specify `SeparatorComponent`.
*/
getItemLayout?: (data: ?Array<ItemT>, index: number) =>
getItemLayout?: (data: ?Array<Item>, index: number) =>
{length: number, offset: number, index: number},
/**
* If true, renders items next to each other horizontally instead of stacked vertically.
Expand All @@ -91,7 +90,7 @@ type OptionalProps<ItemT> = {
* and as the react key to track item re-ordering. The default extractor checks item.key, then
* falls back to using the index, like react does.
*/
keyExtractor: (item: ItemT, index: number) => string,
keyExtractor: (item: Item, index: number) => string,
/**
* Multiple columns can only be rendered with horizontal={false} and will zig-zag like a flexWrap
* layout. Items should all be the same height - masonry layouts are not supported.
Expand All @@ -112,7 +111,6 @@ type OptionalProps<ItemT> = {
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
legacyImplementation?: ?boolean,
/**
* Set this true while waiting for new data from a refresh.
*/
Expand All @@ -125,23 +123,15 @@ type OptionalProps<ItemT> = {
* Optional optimization to minimize re-rendering items.
*/
shouldItemUpdate: (
prevProps: {item: ItemT, index: number},
nextProps: {item: ItemT, index: number}
prevProps: {item: Item, index: number},
nextProps: {item: Item, index: number}
) => boolean,
/**
* See ViewabilityHelper for flow type and comments.
*/
viewabilityConfig?: ViewabilityConfig,
};
type Props<ItemT> = RequiredProps<ItemT> & OptionalProps<ItemT> & VirtualizedListProps;

const defaultProps = {
...VirtualizedList.defaultProps,
getItem: undefined,
getItemCount: undefined,
numColumns: 1,
};
type DefaultProps = typeof defaultProps;
type Props = RequiredProps & OptionalProps; // plus props from the underlying implementation

/**
* A performant interface for rendering simple, flat lists, supporting the most handy features:
Expand All @@ -162,9 +152,13 @@ type DefaultProps = typeof defaultProps;
* ItemComponent={({item}) => <Text>{item.key}</Text>}
* />
*/
class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, void> {
static defaultProps: DefaultProps = defaultProps;
props: Props<ItemT>;
class FlatList extends React.PureComponent {
static defaultProps = {
keyExtractor: VirtualizedList.defaultProps.keyExtractor,
numColumns: 1,
shouldItemUpdate: VirtualizedList.defaultProps.shouldItemUpdate,
};
props: Props;
/**
* Scrolls to the end of the content. May be janky without getItemLayout prop.
*/
Expand Down Expand Up @@ -201,7 +195,7 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
this._checkProps(this.props);
}

componentWillReceiveProps(nextProps: Props<ItemT>) {
componentWillReceiveProps(nextProps: Props) {
this._checkProps(nextProps);
}

Expand All @@ -210,7 +204,7 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo

_captureRef = (ref) => { this._listRef = ref; };

_checkProps(props: Props<ItemT>) {
_checkProps(props: Props) {
const {
getItem,
getItemCount,
Expand Down Expand Up @@ -239,7 +233,7 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
}
}

_getItem = (data: Array<ItemT>, index: number): ItemT | Array<ItemT> => {
_getItem = (data: Array<Item>, index: number): Item | Array<Item> => {
const {numColumns} = this.props;
if (numColumns > 1) {
const ret = [];
Expand All @@ -253,19 +247,13 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
}
};

_getItemCount = (data: Array<ItemT>): number => {
_getItemCount = (data: Array<Item>): number => {
return Math.floor(data.length / this.props.numColumns);
};

_keyExtractor = (items: ItemT | Array<ItemT>, index: number): string => {
_keyExtractor = (items: Item | Array<Item>, index: number): string => {
const {keyExtractor, numColumns} = this.props;
if (numColumns > 1) {
invariant(
Array.isArray(items),
'FlatList: Encountered internal consistency error, expected each item to consist of an ' +
'array with 1-%s columns; instead, received a single item.',
numColumns,
);
return items.map((it, kk) => keyExtractor(it, index * numColumns + kk)).join(':');
} else {
return keyExtractor(items, index);
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Experimental/MetroListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type NormalProps = {

// Provide either `items` or `sections`
items?: ?Array<Item>, // By default, an Item is assumed to be {key: string}
sections?: ?Array<{key: string, data: Array<Item>}>,
sections?: ?Array<{key: string, items: Array<Item>}>,

/**
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
Expand Down Expand Up @@ -146,7 +146,7 @@ class MetroListView extends React.Component {
const sections = {};
props.sections.forEach((sectionIn, ii) => {
const sectionID = 's' + ii;
sections[sectionID] = sectionIn.data;
sections[sectionID] = sectionIn.itemData;
sectionHeaderData[sectionID] = sectionIn;
});
return {
Expand Down
39 changes: 16 additions & 23 deletions Libraries/Experimental/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,43 +37,43 @@ const React = require('React');
const VirtualizedSectionList = require('VirtualizedSectionList');

import type {Viewable} from 'ViewabilityHelper';
import type {Props as VirtualizedSectionListProps} from 'VirtualizedSectionList';

type Item = any;
type SectionItem = any;

type SectionBase<SectionItemT> = {
type SectionBase = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-unused-vars: 'SectionBase' is defined but never used.

// Must be provided directly on each section.
data: Array<SectionItemT>,
data: Array<SectionItem>,
key: string,

// Optional props will override list-wide props just for this section.
ItemComponent?: ?ReactClass<{item: SectionItemT, index: number}>,
ItemComponent?: ?ReactClass<{item: SectionItem, index: number}>,
SeparatorComponent?: ?ReactClass<*>,
keyExtractor?: (item: SectionItemT) => string,
keyExtractor?: (item: SectionItem) => string,

// TODO: support more optional/override props
// FooterComponent?: ?ReactClass<*>,
// HeaderComponent?: ?ReactClass<*>,
// onViewableItemsChanged?: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,

// TODO: support recursive sections
// SectionHeaderComponent?: ?ReactClass<{section: SectionBase<*>}>,
// SectionHeaderComponent?: ?ReactClass<{section: SectionBase}>,
// sections?: ?Array<Section>;
};

type RequiredProps<SectionT: SectionBase<*>> = {
type RequiredProps<SectionT: SectionBase> = {
sections: Array<SectionT>,
};

type OptionalProps<SectionT: SectionBase<*>> = {
type OptionalProps<SectionT: SectionBase> = {
/**
* Rendered after the last item in the last section.
*/
FooterComponent?: ?ReactClass<*>,
/**
* Default renderer for every item in every section.
*/
ItemComponent: ReactClass<{item: Item, index: number}>,
ItemComponent?: ?ReactClass<{item: Item, index: number}>,
/**
* Rendered at the top of each section. In the future, a sticky option will be added.
*/
Expand All @@ -93,8 +93,8 @@ type OptionalProps<SectionT: SectionBase<*>> = {
* stored outside of the recursive `ItemComponent` instance tree.
*/
enableVirtualization?: ?boolean,
keyExtractor: (item: Item, index: number) => string,
onEndReached?: ?({distanceFromEnd: number}) => void,
keyExtractor?: (item: Item) => string,
onEndReached?: ({distanceFromEnd: number}) => void,
/**
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
* sure to also set the `refreshing` prop correctly.
Expand All @@ -104,25 +104,21 @@ type OptionalProps<SectionT: SectionBase<*>> = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
/**
* Set this true while waiting for new data from a refresh.
*/
refreshing?: ?boolean,
refreshing?: boolean,
/**
* This is an optional optimization to minimize re-rendering items.
*/
shouldItemUpdate: (
shouldItemUpdate?: (
prevProps: {item: Item, index: number},
nextProps: {item: Item, index: number}
) => boolean,
};

type Props<SectionT> = RequiredProps<SectionT>
& OptionalProps<SectionT>
& VirtualizedSectionListProps<SectionT>;

type DefaultProps = typeof VirtualizedSectionList.defaultProps;
type Props<SectionT> = RequiredProps<SectionT> & OptionalProps<SectionT>;

/**
* A performant interface for rendering sectioned lists, supporting the most handy features:
Expand All @@ -136,11 +132,8 @@ type DefaultProps = typeof VirtualizedSectionList.defaultProps;
*
* If you don't need section support and want a simpler interface, use FlatList.
*/
class SectionList<SectionT: SectionBase<*>>
extends React.PureComponent<DefaultProps, Props<SectionT>, *>
{
class SectionList<SectionT: SectionBase> extends React.Component<void, Props<SectionT>, void> {
props: Props<SectionT>;
static defaultProps: DefaultProps = VirtualizedSectionList.defaultProps;

render() {
if (this.props.legacyImplementation) {
Expand Down
25 changes: 10 additions & 15 deletions Libraries/Experimental/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type RequiredProps = {
* The default accessor functions assume this is an Array<{key: string}> but you can override
* getItem, getItemCount, and keyExtractor to handle any type of index-based data.
*/
data?: any,
data: any,
};
type OptionalProps = {
FooterComponent?: ?ReactClass<*>,
Expand All @@ -89,12 +89,12 @@ type OptionalProps = {
getItemCount: (items: any) => number,
getItemLayout?: (items: any, index: number) =>
{length: number, offset: number, index: number}, // e.g. height, y
horizontal?: ?boolean,
horizontal: boolean,
initialNumToRender: number,
keyExtractor: (item: Item, index: number) => string,
maxToRenderPerBatch: number,
onEndReached?: ?({distanceFromEnd: number}) => void,
onEndReachedThreshold?: ?number, // units of visible length
onEndReached: ({distanceFromEnd: number}) => void,
onEndReachedThreshold: number, // units of visible length
onLayout?: ?Function,
/**
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make
Expand All @@ -105,11 +105,11 @@ type OptionalProps = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
/**
* Set this true while waiting for new data from a refresh.
*/
refreshing?: ?boolean,
refreshing?: boolean,
removeClippedSubviews?: boolean,
renderScrollComponent: (props: Object) => React.Element<*>,
shouldItemUpdate: (
Expand All @@ -120,11 +120,11 @@ type OptionalProps = {
viewabilityConfig?: ViewabilityConfig,
windowSize: number, // units of visible length
};
export type Props = RequiredProps & OptionalProps;
type Props = RequiredProps & OptionalProps;

let _usedIndexForKey = false;

class VirtualizedList extends React.PureComponent<OptionalProps, Props, *> {
class VirtualizedList extends React.PureComponent {
props: Props;

// scrollToEnd may be janky without getItemLayout prop
Expand Down Expand Up @@ -176,7 +176,7 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, *> {
);
}

static defaultProps = {
static defaultProps: OptionalProps = {
disableVirtualization: false,
getItem: (data: any, index: number) => data[index],
getItemCount: (data: any) => data ? data.length : 0,
Expand Down Expand Up @@ -384,12 +384,7 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, *> {

_onCellLayout = (e, cellKey, index) => {
const layout = e.nativeEvent.layout;
const next = {
offset: this._selectOffset(layout),
length: this._selectLength(layout),
index,
inLayout: true,
};
const next = {offset: this._selectOffset(layout), length: this._selectLength(layout), index, inLayout: true};
const curr = this._frames[cellKey];
if (!curr ||
next.offset !== curr.offset ||
Expand Down
Loading