zhongwuzw cbaff1c7aa Fabric: Fixes crash of dynamic color when light/dark mode changed (#48496)
Summary:
The reason is when light/dark mode changed, the `hash` value also changed because we used `color.getColor()`. leads to size balanced break.

```
Assertion failed: (index_.size() == lru_.size()), function size, file EvictingCacheMap.h, line 439.

(lldb) bt
* thread https://github.com/facebook/react-native/issues/1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001089a9108 libsystem_kernel.dylib`__pthread_kill + 8
    frame https://github.com/facebook/react-native/issues/1: 0x0000000105de3408 libsystem_pthread.dylib`pthread_kill + 256
    frame https://github.com/facebook/react-native/issues/2: 0x000000018016c4ec libsystem_c.dylib`abort + 104
    frame https://github.com/facebook/react-native/issues/3: 0x000000018016b934 libsystem_c.dylib`__assert_rtn + 268
  * frame https://github.com/facebook/react-native/issues/4: 0x00000001073e386c React_FabricComponents`folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::size(this=0x0000600003900348) const at EvictingCacheMap.h:439:5
    frame https://github.com/facebook/react-native/issues/5: 0x00000001073e34f4 React_FabricComponents`void folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::setImpl<facebook::react::AttributedString>(this=0x0000600003900348, key=0x000000016b9f20a8, value=nullptr, promote=true, pruneHook=folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void> >::PruneHookCall @ 0x000000016b9f1cc8) at EvictingCacheMap.h:674:27
    frame https://github.com/facebook/react-native/issues/6: 0x00000001073deb88 React_FabricComponents`folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void>>::set(this=0x0000600003900348, key=0x000000016b9f20a8, value=ptr = 0x60000024ae20 strong=2 weak=1, promote=true, pruneHook=folly::EvictingCacheMap<facebook::react::AttributedString, std::__1::shared_ptr<void>, folly::HeterogeneousAccessHash<facebook::react::AttributedString, void>, folly::HeterogeneousAccessEqualTo<facebook::react::AttributedString, void> >::PruneHookCall @ 0x000000016b9f1d98) at EvictingCacheMap.h:346:5
    frame https://github.com/facebook/react-native/issues/7: 0x00000001073d91dc React_FabricComponents`facebook::react::SimpleThreadSafeCache<facebook::react::AttributedString, std::__1::shared_ptr<void>, 256>::get(this=0x0000600003900348, key=0x000000016b9f20a8, generator= Lambda in File RCTTextLayoutManager.mm at Line 337) const at SimpleThreadSafeCache.h:40:12
    frame https://github.com/facebook/react-native/issues/8: 0x00000001073d9058 React_FabricComponents`-[RCTTextLayoutManager _nsAttributedStringFromAttributedString:](self=0x0000600003900340, _cmd="_nsAttributedStringFromAttributedString:", attributedString=AttributedString @ 0x000000016b9f20a8) at RCTTextLayoutManager.mm:337:42
    frame https://github.com/facebook/react-native/issues/9: 0x00000001073d6378 React_FabricComponents`-[RCTTextLayoutManager drawAttributedString:paragraphAttributes:frame:drawHighlightPath:](self=0x0000600003900340, _cmd="drawAttributedString:paragraphAttributes:frame:drawHighlightPath:", attributedString=AttributedString @ 0x000000016b9f23a8, paragraphAttributes=ParagraphAttributes @ 0x000000016b9f2378, frame=(origin = (x = 0, y = 0), size = (width = 92, height = 21.666748046875)), block=0x00000001061602d0) at RCTTextLayoutManager.mm:73:56
    frame https://github.com/facebook/react-native/issues/10: 0x000000010616020c RCTFabric`-[RCTParagraphTextView drawRect:](self=0x000000012beb9dc0, _cmd="drawRect:", rect=(origin = (x = 0, y = 0.000081380208335701809), size = (width = 92, height = 21.666666666666664))) at RCTParagraphComponentView.mm:346:3
    frame https://github.com/facebook/react-native/issues/11: 0x0000000186043e60 UIKitCore`-[UIView(CALayerDelegate) drawLayer:inContext:] + 584
    frame https://github.com/facebook/react-native/issues/12: 0x000000018af40080 QuartzCore`CABackingStoreUpdate_ + 244
    frame https://github.com/facebook/react-native/issues/13: 0x000000018b0bec88 QuartzCore`invocation function for block in CA::Layer::display_() + 108
    frame https://github.com/facebook/react-native/issues/14: 0x000000018b0b5524 QuartzCore`-[CALayer _display] + 1596
    frame https://github.com/facebook/react-native/issues/15: 0x000000018b0c7e74 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 392
    frame https://github.com/facebook/react-native/issues/16: 0x000000018affca50 QuartzCore`CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464
    frame https://github.com/facebook/react-native/issues/17: 0x000000018b02b260 QuartzCore`CA::Transaction::commit() + 652
    frame https://github.com/facebook/react-native/issues/18: 0x000000018b02c7b4 QuartzCore`CA::Transaction::flush_as_runloop_observer(bool) + 68
    frame https://github.com/facebook/react-native/issues/19: 0x0000000185ad6c1c UIKitCore`_UIApplicationFlushCATransaction + 48
    frame https://github.com/facebook/react-native/issues/20: 0x0000000185a07ccc UIKitCore`__setupUpdateSequence_block_invoke_2 + 352
    frame https://github.com/facebook/react-native/issues/21: 0x000000018505d28c UIKitCore`_UIUpdateSequenceRun + 76
    frame https://github.com/facebook/react-native/issues/22: 0x0000000185a07670 UIKitCore`schedulerStepScheduledMainSection + 168
    frame https://github.com/facebook/react-native/issues/23: 0x0000000185a06aa8 UIKitCore`runloopSourceCallback + 80
    frame https://github.com/facebook/react-native/issues/24: 0x000000018041b7c4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame https://github.com/facebook/react-native/issues/25: 0x000000018041b70c CoreFoundation`__CFRunLoopDoSource0 + 172
    frame https://github.com/facebook/react-native/issues/26: 0x000000018041ae70 CoreFoundation`__CFRunLoopDoSources0 + 232
    frame https://github.com/facebook/react-native/issues/27: 0x00000001804153b4 CoreFoundation`__CFRunLoopRun + 788
    frame https://github.com/facebook/react-native/issues/28: 0x0000000180414c24 CoreFoundation`CFRunLoopRunSpecific + 552
    frame https://github.com/facebook/react-native/issues/29: 0x000000019020ab10 GraphicsServices`GSEventRunModal + 160
    frame https://github.com/facebook/react-native/issues/30: 0x0000000185ad82fc UIKitCore`-[UIApplication _run] + 796
    frame https://github.com/facebook/react-native/issues/31: 0x0000000185adc4f4 UIKitCore`UIApplicationMain + 124
    frame https://github.com/facebook/react-native/issues/32: 0x0000000104521f68 RNTester.debug.dylib`main(argc=1, argv=0x000000016b9f5af8) at main.m:15:12
    frame https://github.com/facebook/react-native/issues/33: 0x00000001045b9410 dyld_sim`start_sim + 20
    frame https://github.com/facebook/react-native/issues/34: 0x0000000104796274 dyld`start + 2840
```

## Changelog:

[IOS] [FIXED] - Fabric: Fixes crash of dynamic color when light/dark mode changed

Pull Request resolved: https://github.com/facebook/react-native/pull/48496

Test Plan:
RNTester -> PlatformColor example -> changed the dark/light mode  in the system settings -> go back to App and pop and push the PlatformColor example, it would crash:

![Simulator Screen Recording - iPhone 16 - 2025-01-05 at 15 46 08](https://github.com/user-attachments/assets/f6faaf80-ad03-49c6-9a56-b1117bdc2659)

Reviewed By: sammy-SC

Differential Revision: D68157559

Pulled By: cipolleschi

fbshipit-source-id: 01959845b742ce748186d3877b2792f0f9132ff5
2025-01-28 11:20:18 -08:00
2024-07-23 06:40:08 -07:00
2025-01-09 03:10:02 -08:00
2025-01-16 16:29:30 -08:00
2025-01-27 09:37:04 -08:00
2025-01-27 06:52:35 -08:00
2023-09-12 09:21:08 -07:00
2025-01-09 03:10:02 -08:00
2024-09-06 09:28:13 -07:00
2024-07-15 13:44:09 -07:00
2025-01-28 08:36:10 -08:00

React Native

Learn once, write anywhere:
Build mobile apps with React.

React Native is released under the MIT license. Current CircleCI build status. Current npm package version. PRs welcome! Follow @reactnative

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

React Native apps may target iOS 15.1 and Android 7.0 (API 24) 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 repository, @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.

Languages
C++ 33%
Kotlin 20%
JavaScript 18.6%
Objective-C++ 11.5%
Objective-C 7.1%
Other 9.7%