FlatList inverted, itemLayoutAnimation and Typescript not working
See original GitHub issueDescription
I found this issue when use Animated.FlatList with inverted. You can see my video below:
Expected behavior
inverted, itemLayoutAnimation and Typescript working
Actual behavior & steps to reproduce
Install library then use Animated.FlatList
Snack or minimal code example
import React, {memo, useCallback, useState} from 'react';
import isEqual from 'react-fast-compare';
import {Button, Text, View} from 'react-native';
import Animated, {Layout} from 'react-native-reanimated';
import {SafeAreaView} from 'react-native-safe-area-context';
const LoginComponent = () => {
// state
const [data, setData] = useState<Array<string>>([
'Hello',
'Hi',
'My name is Jon',
]);
// func
const onPush = useCallback(() => {
setData(d => ['New Text'].concat(d));
}, []);
// render
return (
<SafeAreaView style={{flex: 1}}>
<Animated.FlatList
inverted
itemLayoutAnimation={Layout.springify()}
renderItem={({item, index}) => {
return (
<View key={index}>
<Text>{item}</Text>
</View>
);
}}
data={data}
/>
<Button title={'PUSH'} onPress={onPush} />
</SafeAreaView>
);
};
export const Login = memo(LoginComponent, isEqual);
Typescript error
Package versions
- React Native: 0.66.4
- React Native Reanimated: 2.3.1
- NodeJS: 17.3.0
- Xcode: 12.5.1
Affected platforms
- [] Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Animation lags with inverted Flatlist (Expo / TypeScript)
I was trying to implement a WhatsApp like cancelling recording button. Everything was working fine, all animations lauching correctly, ...
Read more >FlatList - React Native
FlatList. A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform.
Read more >[FlatList] Scrolling goes wrong with inverted prop - Gitcoin
[FlatList] Scrolling goes wrong with inverted prop. TypeScript. JavaScript. React Native. react-native-modalize. FlatList. 0.25 ETH. 0.00 USD. cancelled.
Read more >react-native-inverted-flat-list - npm
React native inverted flat list with the ability to use pull to refresh. ... your project by running `npm i react-native-inverted-flat-list`.
Read more >MessageList | Stream Chat - React Native SDK Docs
Since we use inverted FlatList, this component will be rendered at top of the list. In absence of this prop, an inline loading...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perhaps I am getting the same issue. It’s not typescript, it’s
inverted
behavior.expected behavior
https://reactnative.dev/docs/flatlist#inverted
actual behavior
inverted
is mirroring the list elements against X axis. Instead of reversing the direction of scroll.FlatList
Animated.FlatList
I fixed my issue by rotating elements back on X axis.
I also notice that using:
or:
breaks type inference of the children. For the first example:
can be used to restore the types. This should probably be handled more generically with
Animated.FlatList
. The definition forAnimated.FlatList
should probably be something along the lines of: