Skip to content

Commit

Permalink
[change] Update vendor code
Browse files Browse the repository at this point in the history
* FlatList
* SectionList
* VirtualizedList
* VirtualizedSectionList
  • Loading branch information
necolas committed Aug 9, 2019
1 parent 34f0ce2 commit 1966844
Show file tree
Hide file tree
Showing 36 changed files with 1,299 additions and 1,346 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/preset-flow": "^7.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/babel-plugin-react-native-web/src/moduleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ module.exports = {
Share: true,
StatusBar: true,
StyleSheet: true,
SwipeableFlatList: true,
Switch: true,
Systrace: true,
TVEventHandler: true,
Expand Down
12 changes: 0 additions & 12 deletions packages/react-native-web/src/exports/SwipeableFlatList/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/react-native-web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import SafeAreaView from './exports/SafeAreaView';
import ScrollView from './exports/ScrollView';
import SectionList from './exports/SectionList';
import StatusBar from './exports/StatusBar';
import SwipeableFlatList from './exports/SwipeableFlatList';
import Switch from './exports/Switch';
import Text from './exports/Text';
import TextInput from './exports/TextInput';
Expand Down Expand Up @@ -132,7 +131,6 @@ export {
ScrollView,
SectionList,
StatusBar,
SwipeableFlatList,
Switch,
Text,
TextInput,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* 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
* @format
* @flow strict-local
*/

'use strict';

import InteractionManager from '../../../exports/InteractionManager';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* @format
*/

'use strict';

import performanceNow from 'fbjs/lib/performanceNow';
import warning from 'fbjs/lib/warning';

Expand Down
178 changes: 90 additions & 88 deletions packages/react-native-web/src/vendor/react-native/FlatList/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* 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.
*
* @noflow
* @flow
* @format
*/
'use strict';

import UnimplementedView from '../../../modules/UnimplementedView';
import React from 'react';
import deepDiffer from '../deepDiffer';
import * as React from 'react';
import StyleSheet from '../../../exports/StyleSheet';
import View from '../../../exports/View';
import VirtualizedList, { type Props as VirtualizedListProps } from '../VirtualizedList';
import VirtualizedList from '../VirtualizedList';

import invariant from 'fbjs/lib/invariant';

import type {ViewProps} from '../../../exports/View/ViewPropTypes';

import type {
ViewabilityConfig,
ViewToken,
ViewabilityConfigCallbackPair
ViewabilityConfigCallbackPair,
} from '../ViewabilityHelper';
import invariant from 'fbjs/lib/invariant';
import type {Props as VirtualizedListProps} from '../VirtualizedList';

export type SeparatorsObj = {
highlight: () => void,
unhighlight: () => void,
updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
};

type ViewStyleProp = $PropertyType<ViewProps, 'style'>;

type RequiredProps<ItemT> = {
/**
* Takes an item from `data` and renders it into the list. Example usage:
Expand Down Expand Up @@ -56,7 +65,7 @@ type RequiredProps<ItemT> = {
item: ItemT,
index: number,
separators: SeparatorsObj,
}) => ?React.Element<any>,
}) => ?React.Node,
/**
* For simplicity, data is just a plain array. If you want to use something else, like an
* immutable list, use the underlying `VirtualizedList` directly.
Expand All @@ -81,15 +90,23 @@ type OptionalProps<ItemT> = {
* a rendered element.
*/
ListFooterComponent?: ?(React.ComponentType<any> | React.Element<any>),
/**
* Styling for internal View for ListFooterComponent
*/
ListFooterComponentStyle?: ViewStyleProp,
/**
* Rendered at the top of all the items. Can be a React Component Class, a render function, or
* a rendered element.
*/
ListHeaderComponent?: ?(React.ComponentType<any> | React.Element<any>),
/**
* Styling for internal View for ListHeaderComponent
*/
ListHeaderComponentStyle?: ViewStyleProp,
/**
* Optional custom style for multi-item rows generated when numColumns > 1.
*/
columnWrapperStyle?: any,
columnWrapperStyle?: ViewStyleProp,
/**
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
Expand Down Expand Up @@ -174,7 +191,10 @@ type OptionalProps<ItemT> = {
* @platform android
*/
progressViewOffset?: number,
legacyImplementation?: ?boolean,
/**
* The legacy implementation is no longer supported.
*/
legacyImplementation?: empty,
/**
* Set this true while waiting for new data from a refresh.
*/
Expand Down Expand Up @@ -202,6 +222,12 @@ export type Props<ItemT> = RequiredProps<ItemT> &
const defaultProps = {
...VirtualizedList.defaultProps,
numColumns: 1,
/**
* Enabling this prop on Android greatly improves scrolling performance with no known issues.
* The alternative is that scrolling on Android is unusably bad. Enabling it on iOS has a few
* known issues.
*/
removeClippedSubviews: false,
};
export type DefaultProps = typeof defaultProps;

Expand Down Expand Up @@ -408,41 +434,15 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
}

setNativeProps(props: Object) {
setNativeProps(props: {[string]: mixed}) {
if (this._listRef) {
this._listRef.setNativeProps(props);
}
}

UNSAFE_componentWillMount() {
this._checkProps(this.props);
}

UNSAFE_componentWillReceiveProps(nextProps: Props<ItemT>) {
invariant(
nextProps.numColumns === this.props.numColumns,
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
'changing the number of columns to force a fresh render of the component.',
);
invariant(
nextProps.onViewableItemsChanged === this.props.onViewableItemsChanged,
'Changing onViewableItemsChanged on the fly is not supported',
);
invariant(
nextProps.viewabilityConfig === this.props.viewabilityConfig,
'Changing viewabilityConfig on the fly is not supported',
);
invariant(
nextProps.viewabilityConfigCallbackPairs ===
this.props.viewabilityConfigCallbackPairs,
'Changing viewabilityConfigCallbackPairs on the fly is not supported',
);

this._checkProps(nextProps);
}

constructor(props: Props<*>) {
constructor(props: Props<ItemT>) {
super(props);
this._checkProps(this.props);
if (this.props.viewabilityConfigCallbackPairs) {
this._virtualizedListPairs = this.props.viewabilityConfigCallbackPairs.map(
pair => ({
Expand All @@ -465,8 +465,30 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
}

_hasWarnedLegacy = false;
_listRef: null | VirtualizedList;
componentDidUpdate(prevProps: Props<ItemT>) {
invariant(
prevProps.numColumns === this.props.numColumns,
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
'changing the number of columns to force a fresh render of the component.',
);
invariant(
prevProps.onViewableItemsChanged === this.props.onViewableItemsChanged,
'Changing onViewableItemsChanged on the fly is not supported',
);
invariant(
!deepDiffer(prevProps.viewabilityConfig, this.props.viewabilityConfig),
'Changing viewabilityConfig on the fly is not supported',
);
invariant(
prevProps.viewabilityConfigCallbackPairs ===
this.props.viewabilityConfigCallbackPairs,
'Changing viewabilityConfigCallbackPairs on the fly is not supported',
);

this._checkProps(this.props);
}

_listRef: ?React.ElementRef<typeof VirtualizedList>;
_virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];

_captureRef = ref => {
Expand All @@ -478,7 +500,6 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
getItem,
getItemCount,
horizontal,
legacyImplementation,
numColumns,
columnWrapperStyle,
onViewableItemsChanged,
Expand All @@ -496,21 +517,6 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
'columnWrapperStyle not supported for single column lists',
);
}
if (legacyImplementation) {
invariant(
numColumns === 1,
'Legacy list does not support multiple columns.',
);
// Warning: may not have full feature parity and is meant more for debugging and performance
// comparison.
if (!this._hasWarnedLegacy) {
console.warn(
'FlatList: Using legacyImplementation - some features not supported and performance ' +
'may suffer',
);
this._hasWarnedLegacy = true;
}
}
invariant(
!(onViewableItemsChanged && viewabilityConfigCallbackPairs),
'FlatList does not support setting both onViewableItemsChanged and ' +
Expand All @@ -524,7 +530,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
const ret = [];
for (let kk = 0; kk < numColumns; kk++) {
const item = data[index * numColumns + kk];
item && ret.push(item);
if (item != null) {
ret.push(item);
}
}
return ret;
} else {
Expand Down Expand Up @@ -592,7 +600,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
};
}

_renderItem = (info: Object) => {
_renderItem = (info: Object): ?React.Node => {
const {renderItem, numColumns, columnWrapperStyle} = this.props;
if (numColumns > 1) {
const {item, index} = info;
Expand All @@ -601,14 +609,20 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
'Expected array of items with numColumns > 1',
);
return (
<View style={[{flexDirection: 'row'}, columnWrapperStyle]}>
<View
style={StyleSheet.compose(
styles.row,
columnWrapperStyle,
)}>
{item.map((it, kk) => {
const element = renderItem({
item: it,
index: index * numColumns + kk,
separators: info.separators,
});
return element && React.cloneElement(element, {key: kk});
return element != null ? (
<React.Fragment key={kk}>{element}</React.Fragment>
) : null;
})}
</View>
);
Expand All @@ -618,34 +632,22 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
};

render() {
if (this.props.legacyImplementation) {
return (
/* $FlowFixMe(>=0.66.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.66 was deployed. To see the error delete
* this comment and run Flow. */
<UnimplementedView
{...this.props}
/* $FlowFixMe(>=0.66.0 site=react_native_fb) This comment suppresses
* an error found when Flow v0.66 was deployed. To see the error
* delete this comment and run Flow. */
items={this.props.data}
ref={this._captureRef}
/>
);
} else {
return (
<VirtualizedList
{...this.props}
renderItem={this._renderItem}
getItem={this._getItem}
getItemCount={this._getItemCount}
keyExtractor={this._keyExtractor}
ref={this._captureRef}
viewabilityConfigCallbackPairs={this._virtualizedListPairs}
/>
);
}
return (
<VirtualizedList
{...this.props}
renderItem={this._renderItem}
getItem={this._getItem}
getItemCount={this._getItemCount}
keyExtractor={this._keyExtractor}
ref={this._captureRef}
viewabilityConfigCallbackPairs={this._virtualizedListPairs}
/>
);
}
}

const styles = StyleSheet.create({
row: {flexDirection: 'row'},
});

export default FlatList;
Loading

0 comments on commit 1966844

Please sign in to comment.