[Android] Supporting UIManager in the New Architecture #201
Replies: 5 comments 4 replies
-
|
I'm using https://github.com/th3rdwave/react-native-safe-area-context and they use the UIManagerModule here. It uses 2 APIs which seem to be deprecated, specifically: Any idea how to replace these or suggestions on alternative solutions ? |
Beta Was this translation helpful? Give feedback.
-
|
Trying to patch a package for react-native@0.76 compativility, after doing the migration as you outlined Gradle says it cannot find symbol P. S. I was able to make it work using a pattern from |
Beta Was this translation helpful? Give feedback.
-
|
hi @arushikesarwani94, I'm the contributor of React Native Navigation. |
Beta Was this translation helpful? Give feedback.
-
|
Hi! Any suggestions, thanks in advance! :) |
Beta Was this translation helpful? Give feedback.
-
|
@arushikesarwani94 This works for Android, but how can I get and use UIManager on iOS? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Important
TL;DR -
UIManagerModuleis deprecated in favor ofUIManagerin the New Architecture. If you’ve been usingUIManagerModuleon Android in your apps/libraries, this post describes how to migrate to a New Architecture equivalent.Context
In React Native 0.74, we enabled Bridgeless by default when new architecture is enabled for the apps, emphasizing backwards compatibility to facilitate smooth migration to the new architecture.
Note
This discussion topic is intended for users of
UIManagerModule, and the APIs mentioned are specific to Android only. This is not a new change and it has been the case since 0.68. We're providing this explanation to help users better understand and simplify their migration process. We have done our best to make the APIs meaningfully backwards compatible and have already migrated the big ticket items. Now, we're only dealing with the long-tail of things. Please use this space to share any gaps in the APIs that need improvement since we are curious to understand your needs better and work together to resolve any issues.As some of you may have noticed in the new architecture,
UIManagerModuleis no longer implemented as a native module. This means the following returns null:This is problematic as many libraries and apps rely on this to access the
UIManagerModule. Since the new architecture’sUIManageris not a native module, we will be providing a different class, UIManagerHelper, to retrieve the UIManager abstraction.Similar to the New Renderer Interop Layer introduced for Fabric, we insist on transitioning to the UIManager interface over the UIManagerModule class. We introduced an interface,
UIManager, implemented by FabricUIManager to establish a more customizable pipeline for the critical rendering path. However, please noteUIManageris not designed to be a 1-1 replacement forUIManagerModule.You may have noticed in JavaScript land, UIManager.js defines an API for JavaScript interaction with the native UIManagers for both architectures. In the new architecture, there are some APIs in the
UIManagerModuleclass that are not supported in theUIManagerinterface, but are supported in UIManager.js. These are annotated with@ReactMethodinUIManagerModule.This redesign offers significant benefits since by utilizing an interface and polymorphism, there is a clearer separation making testing, mocking and extending easier, which ultimately enhances maintainability.
To summarize,
UIManagerreplacesUIManagerModule.UIManageris retrieved through the static methods inUIManagerHelper. Most legacy operations remain intact for backwards compatibility. The following steps describe how you use UIManagerHelper to retrieveUIManagerUIManagerHelperwithUIManagerthrough the public APIs provided byUIManagerHelperHow to Migrate
Review your code for all instances where UIManagerModule is called and replace them with references to UIManager
For backwards compatibility can be changed to:
Feel free to review the index below for the APIs beforehand. If you're currently utilizing a non-supported API, please comment on this post so we can discuss the next steps together.
Migration Examples:
expo/expo#29500
react-native-maps/react-native-maps#5061
gre/react-native-view-shot#516
API Index
Non-deprecated APIs
Specifically focusing on Android APIs, the following are the public non-deprecated APIs on
UIManagerModule, out of which some of them have their replacements for backwards compatibility. In most cases the method name will be the same.Annotation: In the new architecture, the bolded APIs are only available in JavaScript through UIManager.js. If your method is not available (marked with "-"), please comment below and let us know which method and your use-case and we can help.
@NullableReadableArray commandArgs)@NullableReadableArray commandArgs)@NullableWritableMap event)@NullableWritableMap event)@NullableWritableMap event)@NullableWritableMap event)Deprecated APIs
If you are using deprecated APIs, migrate those off to the ones supported in
UIManager, for example:Please comment below if you are using a deprecated API that does not have an alternative in the new architecture.
Thanks! If you have questions or encounter challenges, don’t hesitate to reach out.
Beta Was this translation helpful? Give feedback.
All reactions