question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to get y position of render items on Flatlist

See original GitHub issue

Unable 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:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
gaurav107commented, May 15, 2020

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 and renderItem 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).

1reaction
gibrangulcommented, May 5, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found