setState is not working properly for text inline image #41236 (#41287)
Summary: Closes https://github.com/facebook/react-native/issues/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: https://github.com/facebook/react-native/pull/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
sdks dir to testPathIgnorePatterns to prevent hermes specific tests to run (#40734)
React Native
Learn once, write anywhere:
Build mobile apps with React.
Getting Started · Learn the Basics · Showcase · Contribute · Community · Support
React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.
- Declarative. React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
- Component-Based. Build encapsulated components that manage their state, then compose them to make complex UIs.
- Developer Velocity. See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
- Portability. Reuse code across iOS, Android, and other platforms.
React Native is developed and supported by many companies and individual core contributors. Find out more in our ecosystem overview.
Contents
- Requirements
- Building your first React Native app
- Documentation
- Upgrading
- How to Contribute
- Code of Conduct
- License
📋 Requirements
React Native apps may target iOS 13.4 and Android 5.0 (API 21) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like Expo can be used to work around this.
🎉 Building your first React Native app
Follow the Getting Started guide. The recommended way to install React Native depends on your project. Here you can find short guides for the most common scenarios:
📖 Documentation
The full documentation for React Native can be found on our website.
The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the React documentation.
The source for the React Native documentation and website is hosted on a separate repo, @facebook/react-native-website.
🚀 Upgrading
Upgrading to new versions of React Native may give you access to more APIs, views, developer tools, and other goodies. See the Upgrading Guide for instructions.
React Native releases are discussed in this discussion repo.
👏 How to Contribute
The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving React Native.
Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.
Contributing Guide
Read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native.
Open Source Roadmap
You can learn more about our vision for React Native in the Roadmap.
Good First Issues
We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.
Discussions
Larger discussions and proposals are discussed in @react-native-community/discussions-and-proposals.
📄 License
React Native is MIT licensed, as found in the LICENSE file.
React Native documentation is Creative Commons licensed, as found in the LICENSE-docs file.