-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UIManager.measure returns wrong results on Android #29526
Comments
|
Also, I have opened a thread on StackOverflow in which one user commented that there was a similar problem with an older RN version. Think that the only way to go on for now is to calculate the position using basic maths. |
I have the same problem, ios is ok, but android is 0 every time. |
I think the only way to go on for now is using the function I wrote on the Stack Overflow thread |
@Paul0523 did you use it correctly? I did something really similar few weeks ago and worked fine on my Samsung. Just make a ref to the parent view of the child red too, and call the function of StackOverflow. This has to work because this function substracts the pageX/Y of the child to the pageX/Y of the parent, and pageX/Y are not undefined on Android. Hope you solve your issue! |
Hi @VictorioMolina and @Paul0523 sorry you are having issues with this and investigating! Any conclusions or workarounds y'all have observed? |
@safaiyeh there is a work around implementing your own relative-to-parent function to get the correct offsets but it is absolutelly a big. |
This is new development but UIManager is going to be deprecated in a future release: https://youtu.be/DduUntL2Sv4?t=3125 ^ shows a better way to call measure, let me know if that helps. |
@safaiyeh I have updated my RN version and try the new method but this is still returning 0 (the ox and oy values) on android |
@Paul0523 did you find any solution? |
This is breaking my head, I have tested the measurement in a native View component (which is inside an ImageBackground) with pageX and pageY instead, but when I change to release mode, wrong results again on my Android. |
Okey, I have found a solution to my problem... Trying to measure the ImageBackground component on Android with release mode results on undefined values... so, I have decided put a View (with the same width and height as my ImageBackground component) inside it and then measure it instead... In a first moment, again, wrong results... but I have noticed that some Androids make optimizations removing unnecesary Views, so I set collapsable={false} to the View and working!! Maybe useful for someone in the future...
Views that are only used to layout their children or otherwise don't draw anything may be automatically removed from the native hierarchy as an optimization. Set this property to false to disable this optimization and ensure that this View exists in the native view hierarchy. Also, maybe, that was happening too with the ImageBackground component on Android. |
I think that the bug still continues alive but there are some workarounds explained here that can solve the problem... so I think I can close this thread... |
@VictorioMolina Yes, I found problem, when you set style background color, it will be correct. It's possible when you don't set color or some other style, android will ignore to draw it, so the measure method not work. |
Summary of Issue
I am trying to get the x and y relative-to-parent position every time I move an animated view. It is working fine on iOS, but on Android those values are always 0.
Snack
https://snack.expo.io/@victoriomolina/measure-issue-android
Environment Information
System:
OS: Windows 10 10.0.18362
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 8.44 GB / 15.85 GB
Binaries:
Node: 12.18.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6241897
npmPackages:
react: ~16.9.0 => 16.9.0
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
npmGlobalPackages:
react-native-cli: 2.0.1
Reproducible Demo
Just create an Animated.View inside a View (at the middle for example) and get it position using this function
as follows:
Expected Behaviour
x and y should be different from 0 on Android. Just like on iOS.
The text was updated successfully, but these errors were encountered: