-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement intrinsic size based on viewBox (height / width auto) #1720
base: main
Are you sure you want to change the base?
Conversation
87a49b0
to
3bcd041
Compare
Would you be able to update the PR so it works on the newest version of the library on both architectures? |
Sure, will try to find some time in the next few weeks |
33148c5
to
cf7a1ce
Compare
@WoLewicki I've updated this to support fabric, turns out it was a bit harder than expected. To add a measure function the yoga node needs to be marked as a leaf node, this means it should not have any layoutable children. However this is not the case currently since all our views are The solution is to use Then comes android :) Android has a concept of virtual nodes and also has a check to see if a view is layoutable which makes our new shadow nodes type not work at all. See https://github.com/facebook/react-native/blob/main/ReactCommon/react/renderer/mounting/ShadowViewMutation.cpp#L100-L108 and https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java#L837-L847. However for some reason that I haven't fully investigated using |
cf7a1ce
to
9a12253
Compare
@WoLewicki Any change you or someone else could have a look at this, just rebased and improved the implementation. |
Fabric on Android actually requires shadow nodes to be subclasses of LayoutableShadowNode to be able to create a native view for it so I am now using that instead of having different implementations of iOS / Android. |
Also note that currently the example app crashes on fabric Android because of a known issue in reanimated, I updated to a nightly version to test. |
Hello @janicduplessis, |
@bohdanprog Were you able to get it working? I can try to have a look again in the next week. |
Yeah, I managed to check and prepare everything. |
@janicduplessis, could you take a look at the documentation for SVG sizing? There is a note about using auto for width and height on the 'svg' element, which is considered as 100%. Additionally, we encountered an edge case when attempting to display the component as follows:
Would you mind taking a look at this situation, please? Thank you. |
Sure I’ll try to have a look this week. |
Any way I could help move this along (testing, etc)? I keep running into this issue, and would love to have this functionality merged. |
Summary
This implements intrinsic size for Svg element based on the viewBox size. When width or height is unset or set to auto it will use the viewBox size to calculate the auto dimension value.
This uses yoga measure function to calculate and return the proper size to yoga.
Test Plan
I've compared my implementation with the web version to make sure it behaves the same. I found some edge cases where the behavior is different, probably because of some differences with how yoga implements flexbox, or just some odd web behavior that might be there for legacy purposes.
Before
Expected (Web)
Actual (iOS)
After
Actual (iOS)
What's required for testing (prerequisites)?
N/A
What are the steps to reproduce (after prerequisites)?
Run example app and use new auto width / height examples
Compatibility
Checklist
README.md
__tests__
folder