[Android] Supporting UIManager in the New Architecture #201
arushikesarwani94
started this conversation in
Libraries
Replies: 1 comment 1 reply
-
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.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Important
TL;DR -
UIManagerModule
is deprecated in favor ofUIManager
in the New Architecture. If you’ve been usingUIManagerModule
on 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,
UIManagerModule
is 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’sUIManager
is 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 noteUIManager
is 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
UIManagerModule
class that are not supported in theUIManager
interface, but are supported in UIManager.js. These are annotated with@ReactMethod
inUIManagerModule
.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,
UIManager
replacesUIManagerModule
.UIManager
is retrieved through the static methods inUIManagerHelper
. Most legacy operations remain intact for backwards compatibility. The following steps describe how you use UIManagerHelper to retrieveUIManager
UIManagerHelper
withUIManager
through the public APIs provided byUIManagerHelper
How 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.
@Nullable
ReadableArray commandArgs)@Nullable
ReadableArray commandArgs)@Nullable
WritableMap event)@Nullable
WritableMap event)@Nullable
WritableMap event)@Nullable
WritableMap 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