Flatlist support
See original GitHub issueI wanted to use an animated Flatlist to extract the scroll offset and use it to hide and show my header,
but i got an error:
Invariant violation: element type is invalid: expect a string or class/function but got undefined.
import React from 'react';
import {Text, View, Button} from 'react-native';
import Animated from 'react-native-reanimated';
const Screen= props=> {
return (
<View>
<Button
title= "Go back"
onPress= {() => props.navigation.goBack()}
/>
<Text>This is the Test screen</Text>
<Animated.Flatlist />
</View>
);
}
Screen.navigationOptions = ({navigation}) => {
return {title: 'Test'}
}
export default Screen;
Any suggestion it doesn’t work with Flatlist, knowing that if i change Animatet.Flatlist to Animated.Scrollview it works.
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (7 by maintainers)
Top Results From Across the Web
FlatList - React Native
A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform. Optional horizontal mode.
Read more >How to use the FlatList Component — React Native Basics
There are two primary props you need to know about in a FlatList and that's data and renderItem. The first is an array...
Read more >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle ... FlatList also has support for header components....
Read more >Displaying a List in React Native: Map Method or FlatList ...
Scroll to a specific position in the list; Multiple column support. Under the hood, FlatList uses the ScrollView component to render scrollable elements....
Read more >FlatList · React Native
Scroll loading. ScrollToIndex support. If you need section support, use <SectionList> . Minimal Example: <FlatList data={ ...
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 FreeTop 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
Top GitHub Comments
I’d like to reopen this.
While using the
renderScrollComponent
does work, it doesn’t allow all props to work.If you use the
renderScrollComponent
with anonScroll
prop for theAnimated.ScrollView
, theonViewableItemsChanged
callback never fires after the first time when the component mounts.Hi everyone, There is alternative solution to use Animated FlatList in react-native-reanimated v2.0.0.
import React from ‘react’; import {View, Image, FlatList, StyleSheet} from ‘react-native’; import Animated, { useAnimatedScrollHandler, useSharedValue, } from ‘react-native-reanimated’;
import {StatusBarHeight, Stylebase} from ‘…/…/Constants/Stylebase’; import RenderItems from ‘./RenderItem’;
const data = […Array(30).keys()].map((_, i) => { return { key: Math.random().toString(36).slice(2), image:
https://randomuser.me/api/portraits/women/${Math.floor( Math.random() * 100, )}.jpg
, jobtitle: Math.random().toString(36).slice(2), email: Math.random().toString(36).slice(2), }; });const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
const backgroundImage = ‘https://i.pinimg.com/originals/73/7d/01/737d014f201a5cd79257dd313e09b7d7.jpg’;
function FirstAnimation() { const onScrollY = useSharedValue(0);
const scrollHandler = useAnimatedScrollHandler(event => { onScrollY.value = event.contentOffset.y; });
return ( <View style={Stylebase.flex1}> <Image source={{uri: backgroundImage}} style={StyleSheet.absoluteFillObject} blurRadius={50} /> <AnimatedFlatList data={data} keyExtractor={item => item.key} showsVerticalScrollIndicator={false} contentContainerStyle={{ alignItem: ‘center’, paddingTop: StatusBarHeight, }} onScroll={scrollHandler} renderItem={({item, index}) => { const inputRange = [-1, 0, item_size * index, item_size * (index + 2)]; const opacityInputRange = [-1, 0, item_size * index, item_size * (index + 1)];
); } export default FirstAnimation;
Please ignore the style part. It’s gonna definitely work. Thanks in advance.