mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor preComputeConstantsForViewManager to avoid loading UIManagerModule in Fabric
Summary: This method refactors the preComputeConstantsForViewManager to avoid loading UIManagerModule when using Fabric + Static View configs changelog: [internal] internal Reviewed By: shergin Differential Revision: D25468182 fbshipit-source-id: e95b0e7d013e832792fb77fc0b6e5705d7f04868
This commit is contained in:
committed by
Facebook GitHub Bot
parent
4c734d1e8d
commit
b3defc8872
@@ -14,6 +14,7 @@ import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import com.facebook.infer.annotation.ThreadConfined;
|
||||
import java.util.List;
|
||||
|
||||
public interface UIManager extends JSIModule, PerformanceCounter {
|
||||
|
||||
@@ -129,4 +130,15 @@ public interface UIManager extends JSIModule, PerformanceCounter {
|
||||
@Deprecated
|
||||
@Nullable
|
||||
String resolveCustomDirectEventName(@Nullable String eventName);
|
||||
|
||||
/**
|
||||
* Helper method to pre-initialize view managers. When using Native ViewConfigs this method will
|
||||
* also pre-compute the constants for a view manager. The purpose is to ensure that we don't block
|
||||
* for getting the constants for view managers during initial rendering of a surface.
|
||||
*
|
||||
* @deprecated this method will be removed in the future
|
||||
* @param viewManagerNames {@link List <String>} names of ViewManagers
|
||||
*/
|
||||
@Deprecated
|
||||
void preInitializeViewManagers(List<String> viewManagerNames);
|
||||
}
|
||||
|
||||
@@ -229,6 +229,13 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
return rootTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInitializeViewManagers(List<String> viewManagerNames) {
|
||||
for (String viewManagerName : viewManagerNames) {
|
||||
mMountingManager.initializeViewManager(viewManagerName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@AnyThread
|
||||
@ThreadConfined(ANY)
|
||||
|
||||
@@ -782,6 +782,10 @@ public class MountingManager {
|
||||
return viewState == null ? null : viewState.mEventEmitter;
|
||||
}
|
||||
|
||||
public void initializeViewManager(String componentName) {
|
||||
mViewManagerRegistry.get(componentName);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class holds view state for react tags. Objects of this class are stored into the {@link
|
||||
* #mTagToViewState}, and they should be updated in the same thread.
|
||||
|
||||
@@ -294,14 +294,16 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
* Helper method to pre-compute the constants for a view manager. This method ensures that we
|
||||
* don't block for getting the constants for view managers during TTI
|
||||
*
|
||||
* @deprecated this method will not be available in FabricUIManager class.
|
||||
* @deprecated this method will be removed in the future
|
||||
* @param viewManagerNames {@link List<String>} names of ViewManagers
|
||||
*/
|
||||
@Deprecated
|
||||
public void preComputeConstantsForViewManager(List<String> viewManagerNames) {
|
||||
// TODO T81145457 - Implement pre-initialization of ViewManagers in Fabric Android
|
||||
@Override
|
||||
public void preInitializeViewManagers(List<String> viewManagerNames) {
|
||||
if (ReactFeatureFlags.enableExperimentalStaticViewConfigs) {
|
||||
preInitializeViewManagers(viewManagerNames);
|
||||
for (String viewManagerName : viewManagerNames) {
|
||||
mUIImplementation.resolveViewManager(viewManagerName);
|
||||
}
|
||||
// When Static view configs are enabled it is not necessary to pre-compute the constants for
|
||||
// viewManagers, although the pre-initialization of viewManager objects is still necessary
|
||||
// for performance reasons.
|
||||
@@ -326,12 +328,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
mViewManagerConstantsCache = Collections.unmodifiableMap(constantsMap);
|
||||
}
|
||||
|
||||
private void preInitializeViewManagers(List<String> viewManagerNames) {
|
||||
for (String viewManagerName : viewManagerNames) {
|
||||
mUIImplementation.resolveViewManager(viewManagerName);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public @Nullable WritableMap getConstantsForViewManager(@Nullable String viewManagerName) {
|
||||
if (mViewManagerConstantsCache != null
|
||||
|
||||
Reference in New Issue
Block a user