Unable to get y position of render items on Flatlist
See original GitHub issueUnable to get position of render items on Flatlist
I am trying to get an item’s position in flatlist but it always returns “0”.sample code are attached bellow.
Here is sample code :
<FlatList
data={["test1","test2","test2"]}
renderItem={({item,index}) => {
return(
<View
onLayout={(event) => {
let {x, y, width, height} = event.nativeEvent.layout;
}}
>
<Text>{item}</Text>
</View>
)
}}
/>
Can you please help me to get out from this stuff.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Get position of individual Items in flatlist - react native
Whenever Item entered the viewport , I want to add animation to that element.I can get X and Y position of scroll with...
Read more >FlatList - React Native
FlatList. A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform.
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 >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle and minimal code. Learn how to customize FlatList....
Read more >React Native FlatList scrollToIndex with Fixed or ... - YouTube
Your browser can't play this video. ... to get scrollToIndex working on a list where the list items are of a variable dynamic...
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
Here’s a working example: https://snack.expo.io/@gaurav107/b735d9. Select Android/iOS on the right, and click on the bottom left bar to see the Logs window. I can see the correct (x,y) coordinates getting logged here.
And here’s the documentation for CellRendererComponent
The only difference between
CellRendererComponent
andrenderItem
props of FlatList is that renderItem wraps the item in a container<View>
, whereas CellRendererComponent doesn’t. Hence, the (x, y) layout coordinates for CellRendererComponent come relative FlatList layout, whereas in renderItem, they come relative to parent<View>
and hence are (0, 0).@hramos Is there any update on this issue? I’m still getting { x: 0, y: 0 } from event.nativeEvent.layout in flatlist children onLayout methods.