-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
onLayout width&height rounded numbers #2424
Comments
Closing this as all the number will be rounded now, as part of fixing significant differences in values. There's no way to get sub pixel values with the web APIs necessary to fix other issues. |
Hi @necolas we are having an issue where we measure a component and use the resulting When I open the inspect element and try adjusting the It appears that web browsers to allow fractional pixel values as I was able to find a number of components with calculated dimensions that had fractional values. I've looked around and I don't know what options I have left to get this to align correctly. I'm guessing that if I had access to the raw numbers I could get the result I'm looking for. Any thoughts or suggestions? |
For those that are running into this as well. I was able to develop a workaround by making use of In my situation, this is a step in the right direction anyways as reanimated allows me to make measurements on the UI thread, store the result in a shared value and then pass that down to the child component which can use |
Is there an existing issue for this?
Describe the issue
onLayout returns rounded numbers for width and height.
offsetWidth, offsetHeight are the reason why it is returns rounded number.
Note: This property will round the value to an integer.
(https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight)
Might be one solution to fix this is using this approach to calculate width without include transform
https://stackoverflow.com/a/35543016
also worth to mention that React Native doesn't round the numbers for width&height.
Expected behavior
value without rounded
Steps to reproduce
Open codesandbox link:
1: Look console to see View's rounded width.
Test case
https://codesandbox.io/s/vigorous-glitter-u2pddb
Additional comments
No response
The text was updated successfully, but these errors were encountered: