Skip to content

Commit daa7c78

Browse files
Yunyu Linfacebook-github-bot
authored andcommitted
Add FlatList and SectionList to Animated exports
Summary: There are several cases for creating an animated implementation of FlatList or SectionList (e.g. passing Animated.Event for onScroll with useNativeDriver enabled, see FlatListExample or SectionListExample), so we might as well add them to the exports. Reviewed By: sahrens Differential Revision: D8886446 fbshipit-source-id: 4b207500ea4d8d10de8c1b2639a5f492bc62e560
1 parent e64e13f commit daa7c78

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

Libraries/Animated/src/Animated.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
'use strict';
1212

1313
const AnimatedImplementation = require('AnimatedImplementation');
14+
const FlatList = require('FlatList');
1415
const Image = require('Image');
1516
const ScrollView = require('ScrollView');
17+
const SectionList = require('SectionList');
1618
const Text = require('Text');
1719
const View = require('View');
1820

@@ -22,4 +24,6 @@ module.exports = {
2224
Text: AnimatedImplementation.createAnimatedComponent(Text),
2325
Image: AnimatedImplementation.createAnimatedComponent(Image),
2426
ScrollView: AnimatedImplementation.createAnimatedComponent(ScrollView),
27+
FlatList: AnimatedImplementation.createAnimatedComponent(FlatList),
28+
SectionList: AnimatedImplementation.createAnimatedComponent(SectionList),
2529
};

Libraries/Animated/src/__tests__/AnimatedNative-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jest
1919
.setMock('View', ClassComponentMock)
2020
.setMock('Image', ClassComponentMock)
2121
.setMock('ScrollView', ClassComponentMock)
22+
.setMock('FlatList', ClassComponentMock)
23+
.setMock('SectionList', ClassComponentMock)
2224
.setMock('React', {Component: class {}})
2325
.setMock('NativeModules', {
2426
NativeAnimatedModule: {},

RNTester/js/FlatListExample.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
const Alert = require('Alert');
1414
const React = require('react');
1515
const ReactNative = require('react-native');
16-
const {Animated, FlatList, StyleSheet, View} = ReactNative;
16+
const {Animated, StyleSheet, View} = ReactNative;
1717

1818
const RNTesterPage = require('./RNTesterPage');
1919

@@ -34,8 +34,6 @@ const {
3434
renderSmallSwitchOption,
3535
} = require('./ListExampleShared');
3636

37-
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
38-
3937
const VIEWABILITY_CONFIG = {
4038
minimumViewTime: 3000,
4139
viewAreaCoveragePercentThreshold: 100,
@@ -114,7 +112,7 @@ class FlatListExample extends React.PureComponent<{}, $FlowFixMeState> {
114112
</View>
115113
</View>
116114
<SeparatorComponent />
117-
<AnimatedFlatList
115+
<Animated.FlatList
118116
ItemSeparatorComponent={ItemSeparatorComponent}
119117
ListHeaderComponent={<HeaderComponent />}
120118
ListFooterComponent={FooterComponent}
@@ -201,7 +199,7 @@ class FlatListExample extends React.PureComponent<{}, $FlowFixMeState> {
201199
this._listRef.getNode().recordInteraction();
202200
pressItem(this, key);
203201
};
204-
_listRef: AnimatedFlatList;
202+
_listRef: Animated.FlatList;
205203
}
206204

207205
const styles = StyleSheet.create({

RNTester/js/SectionListExample.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@
1212

1313
const React = require('react');
1414
const ReactNative = require('react-native');
15-
const {
16-
Alert,
17-
Animated,
18-
Button,
19-
SectionList,
20-
StyleSheet,
21-
Text,
22-
View,
23-
} = ReactNative;
15+
const {Alert, Animated, Button, StyleSheet, Text, View} = ReactNative;
2416

2517
const RNTesterPage = require('./RNTesterPage');
2618

@@ -39,8 +31,6 @@ const {
3931
renderStackedItem,
4032
} = require('./ListExampleShared');
4133

42-
const AnimatedSectionList = Animated.createAnimatedComponent(SectionList);
43-
4434
const VIEWABILITY_CONFIG = {
4535
minimumViewTime: 3000,
4636
viewAreaCoveragePercentThreshold: 100,
@@ -90,7 +80,7 @@ class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> {
9080
{useNativeDriver: true},
9181
);
9282

93-
_sectionListRef: any;
83+
_sectionListRef: Animated.SectionList;
9484
_captureRef = ref => {
9585
this._sectionListRef = ref;
9686
};
@@ -150,7 +140,7 @@ class SectionListExample extends React.PureComponent<{}, $FlowFixMeState> {
150140
</View>
151141
</View>
152142
<SeparatorComponent />
153-
<AnimatedSectionList
143+
<Animated.SectionList
154144
ref={this._captureRef}
155145
ListHeaderComponent={HeaderComponent}
156146
ListFooterComponent={FooterComponent}

0 commit comments

Comments
 (0)