React Native Onlayout Nativeevent.layout.y Always Returns 0
I'm creating a grid of Views. I'm doing it using pure flex. i.e. no absolute positioning. Actual screenshot: I need to know the positions of each View in the grid and for that I'm
Solution 1:
Ok.. I was suspecting that so I ended up saving the row's Y position and then assigning it to the "cells". Thanks for your help @HaitaoLi
Solution 2:
My version
const handleTabLayout = useCallback(
(e: LayoutChangeEvent, index: number) => {
const { width, x: nativeX } = e.nativeEvent.layoutconst x =
Platform.OS === 'android' ? tabsWidth.reduce((sum, el, i) => (i < index ? sum + el.width : sum), 0) : nativeX
if (tabsWidth[index]?.width !== width) {
const newTabsWidth = tabsWidth.map((tw, twIndex) => (twIndex === index ? { ...tw, width, x } : tw))
setTabsWidth(newTabsWidth)
}
},
[tabsWidth]
)
Post a Comment for "React Native Onlayout Nativeevent.layout.y Always Returns 0"