Open evelant opened 4 years ago
Thank you so much for this! I was looking for a solution, and setting collapsable={false} fixed it for me!
collapsable={false}
was a great workaround for me after upgrading to react-native 0.64.0, thank you @AndrewMorsillo
Same issue here. Another quick solution that work : bind a noop function to the onLayout
collapsable={false}
worked for me too! Pity this is needed though. I agree with this:
If there's a ref the view should essentially have collapsable={false} automatically.
Thank you @AndrewMorsillo. collapsable={false}
worked for me.
Thanks man. collapsable={false}
worked for me.
Thanks! collapsable={false}
is working.
And instead of measure()
better use onLayout={}
View
attribute (it works without collapsable={false}
).
const onLayout = ({nativeEvent: {layout: { x, y, width:w, height:h }}}: LayoutChangeEvent) => {
console.log('onLayout: ',x,y,w,h)
}
return <View onLayout={onLayout}></View>
And instead of
measure()
better useonLayout={}
View
attribute (it works withoutcollapsable={false}
).const onLayout = ({nativeEvent: {layout: { x, y, width:w, height:h }}}: LayoutChangeEvent) => { console.log('onLayout: ',x,y,w,h) } return <View onLayout={onLayout}></View>
However onLayout
doesn't provide pageX
and pageY
, so it's not a direct replacement. https://reactnative.dev/docs/direct-manipulation#measurecallback
Hey, any updates on this issue? I got similar problem, but collapsible and empty onLayout are doing nothing. Still getting 0 and 0 for x and y values on android, but on ios works perfectly.
Thank you very much! collapsable={false}
work for me.
Just going to bump this up - collapsable={false}
works as expected, but seems like an unnecessary hack.
Thank you for documenting this. Adding collapsable={false}
has worked for me too.
use pageX and pageY instead of x and y
@bozaigao pageY will be undefined in these cases as well
pageX and x serves a bit different purposes, and I don't think I can replace it with pageX in my use-case. I'm also having the same issue as #4753 and collapsable=false didn't help.
Tried different solutions (collapsible, requestAnimationFrame, etc), and it doesn't work for me
Work around by wrapping measure
with setTimeout 500ms now but I think it's not a proper fix
In my case:
measure
in the renderItem
Only the first component measure has values in (x, y, width, height, pageX, pageY) The other components measure are undefined
The issue only occur on Android. IOS work fine
any updates on this one?
I've taken a closer look into this issue, and I'm assuming Yoga wasn't able to find the shadow node in case if the view has been flattened out (unsure about the word choice): https://github.com/facebook/react-native/blob/76bf71e2cc12cf0ca3d3e04ac898c4a62a9df400/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp#L584
In my case the view was not visible on the screen when measure was called (the second page of a swiper). It worked after I move the view to the first page. Not totally satisfied with the solution though :/
Tried different solutions (collapsible, requestAnimationFrame, etc), and it doesn't work for me Work around by wrapping
measure
with setTimeout 500ms now but I think it's not a proper fixIn my case:
- I have a horizontal flat list
- the component I want to
measure
in therenderItem
Only the first component measure has values in (x, y, width, height, pageX, pageY) The other components measure are undefined
The issue only occur on Android. IOS work fine
Hey @tranquan did you find the solution for this if yes then please share with me
@najil-12 I just wait some timeout before call measure
Tried different solutions (collapsible, requestAnimationFrame, etc), and it doesn't work for me Work around by wrapping
measure
with setTimeout 500ms now but I think it's not a proper fixIn my case:
- I have a horizontal flat list
- the component I want to
measure
in therenderItem
Only the first component measure has values in (x, y, width, height, pageX, pageY) The other components measure are undefined
The issue only occur on Android. IOS work fine
Try adding removeClippedSubviews={false}
to the FlatList. RN defaults this to true for android.
Thank you so much for this! I was looking for a solution, and setting collapsable={false} fixed it for me!
Here on december 2023, thanks, it worked for me, a View ref was giving me an undefined using .measure
collapsable={false}
does not work for me so I used onLayout
as a trigger for the .measure
Have other people's workarounds had success in getting x and y values to be anything other than 0
?
Have other people's workarounds had success in getting x and y values to be anything other than
0
?
No, i still got 0 for x and y
Description
If you call
.measure
on a ref to aView
on Android but you don't also haveonLayout
orcollapsable={false}
specified then.measure
will call its success callback withundefined
.This issue got closed but it was never fixed https://github.com/facebook/react-native/issues/3282 Seems it got reported again and was also closed without a fix https://github.com/facebook/react-native/issues/19103
The issue here is identical, a 5 year old bug! I suspect it's due to android removing "unnecessary" views when it shouldn't. If there's a
ref
theview
should essentially havecollapsable={false}
automatically.React Native version:
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
Expected Results
It should return the measurement results
Snack, code example, screenshot, or link to a repository:
Not needed, can be reproduced immediately on any react native android project of any version