-
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
fixed (iOS) setState
is not working properly for text inline image #41236
#41287
Conversation
setState
is not working properly for text inline imagesetState
is not working properly for text inline image #41236
Base commit: 53a2742 |
Let me try testing this out as well |
@ehsemloh can you also provide more detail on how this fixes the setState issue? |
/rebase - this comment will rebase this PR on top of main. |
...and it failed to push the rebase. :/ @ehsemloh could you please rebase and push? I'd like to see that the tests on Ruby 3.2.0 are passing. |
@cipolleschi Thank you so much help out! Let me do that. |
445d543
to
e24fa08
Compare
@cipolleschi done. |
Hi @NickGerleman , thanks for being involved! I believe this PR is ready for review. |
Thank you for adding the detailed description! |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @ehsemloh in 36ef646. When will my fix make it into a release? | Upcoming Releases |
…acebook#41236 (facebook#41287) Summary: Closes facebook#41236 `setState` is not working properly for text inline image ## Fixed demo (please see the animation as in rendering pass rather than re-mounting pass) https://github.com/facebook/react-native/assets/149237137/d4b894bf-2283-4963-8dc7-b8f5a9f81315 ## How it works **Background** Inline views are not included in the Yoga node tree, rather, they are retained as attachments of `NSAttributedString` and are managed by the respective text fragment (`RCTTextShadowView`) that includes them (Code snippet 1). ``` <div layout="width: 393; height: 852; top: 0; left: 0;" style="" > <div layout="width: 393; height: 852; top: 0; left: 0;" style="flex: 1; " > <div layout="width: 393; height: 852; top: 0; left: 0;" style="flex: 1; " > <div layout="width: 393; height: 241; top: 0; left: 0;" style="padding-top: 59px; " > <div layout="width: 393; height: 50; top: 59; left: 0;" style="width: 100%; height: 50px; " > <div layout="width: 393; height: 17.3333; top: 0; left: 0;" style="" has-custom-measure="true"></div> </div> <div layout="width: 393; height: 50; top: 109; left: 0;" style="width: 100%; height: 50px; " > <div layout="width: 393; height: 17.3333; top: 0; left: 0;" style="" has-custom-measure="true"></div> </div> /* Text node that does not contain inline view that is supposed to be there */ <div layout="width: 393; height: 74.3333; top: 167; left: 0;" style="margin-top: 8px; " has-custom-measure="true"></div> </div> </div> </div> </div> ``` **Code snippet 1, output of YGNodePrint() in _normal layout_ flow** The layout of such node is handled ad-hoc (_inline layout_) inside `RCTTextShadowView` (Code snippet 2) ``` /* Inline node is calculated on its own */ <div layout="width: 48; height: 48; top: 0; left: 0;" style="overflow: hidden; width: 48px; height: 48px; min-width: 0px; min-height: 0px; " ></div> ``` **Code snippet 2, output of YGNodePrint() in _inline layout_ flow** **Problem description** The issue happens when the sizes given by `setState()` are smaller than those in the last round `setState()`. Since the `min-width` and `min-height` are already populated (Code snippet 3) with greater values, the new layout pass gives rather a `noop`. ``` /* min sizes are greater than them in the new style */ <div layout="width: 48; height: 48; top: 0; left: 0;" style="overflow: hidden; width: 32px; height: 32px; min-width: 48px; min-height: 48px; " ></div> ``` **Code snippet 3, output of YGNodePrint() in _inline layout (issue)_ flow** **Fix description** This biased `min-width` and `min-height` are given using the **current frame size** (i.e., sizes set in the last round `setState()`) in the _inline layout_ (in `RCTTextShadowView` § Background), whilst the same parameters are given as ~~CGSizeZero~~ `_minimumSize` in _normal layout_ (§ Background). The change of this PR is to unify this behavior of _normal layout_ by using ~~CGSizeZero~~ `_minimumSize` as the input also for _inline layout_. ## Changelog: [IOS] [FIXED] - `setState` is not working properly for text inline image Pull Request resolved: facebook#41287 Test Plan: - Using **rn-tester** for basic verification - Complete plan: https://docs.google.com/spreadsheets/d/1QLuqNvqX0dM4K68ygRoHDR3S0wcK5umptmjoR7KtkaY/edit?usp=sharing Reviewed By: cipolleschi Differential Revision: D50967547 Pulled By: NickGerleman fbshipit-source-id: b3b6d6919fd9d3302977dc771a41c22f7b796ba5
Summary:
Closes #41236
setState
is not working properly for text inline imageFixed demo (please see the animation as in rendering pass rather than re-mounting pass)
Screen.Recording.2023-11-02.at.11.15.47.mov
How it works
Background
Inline views are not included in the Yoga node tree, rather, they are retained as attachments of
NSAttributedString
and are managed by the respective text fragment (RCTTextShadowView
) that includes them (Code snippet 1).Code snippet 1, output of YGNodePrint() in normal layout flow
The layout of such node is handled ad-hoc (inline layout) inside
RCTTextShadowView
(Code snippet 2)Code snippet 2, output of YGNodePrint() in inline layout flow
Problem description
The issue happens when the sizes given by
setState()
are smaller than those in the last roundsetState()
. Since themin-width
andmin-height
are already populated (Code snippet 3) with greater values, the new layout pass gives rather anoop
.Code snippet 3, output of YGNodePrint() in inline layout (issue) flow
Fix description
This biased
min-width
andmin-height
are given using the current frame size (i.e., sizes set in the last roundsetState()
) in the inline layout (inRCTTextShadowView
§ Background), whilst the same parameters are given asCGSizeZero_minimumSize
in normal layout (§ Background).The change of this PR is to unify this behavior of normal layout by using
CGSizeZero_minimumSize
as the input also for inline layout.Changelog:
[IOS] [FIXED] -
setState
is not working properly for text inline imageTest Plan: