|
10 | 10 | import android.content.ComponentCallbacks2;
|
11 | 11 | import android.content.res.Configuration;
|
12 | 12 | import androidx.annotation.Nullable;
|
| 13 | +import com.facebook.common.logging.FLog; |
13 | 14 | import com.facebook.infer.annotation.Nullsafe;
|
| 15 | +import com.facebook.react.bridge.ReactSoftExceptionLogger; |
14 | 16 | import com.facebook.react.bridge.UiThreadUtil;
|
15 | 17 | import com.facebook.react.common.MapBuilder;
|
| 18 | +import com.facebook.react.common.build.ReactBuildConfig; |
| 19 | +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags; |
16 | 20 | import java.util.ArrayList;
|
17 | 21 | import java.util.List;
|
18 | 22 | import java.util.Map;
|
|
24 | 28 | @Nullsafe(Nullsafe.Mode.LOCAL)
|
25 | 29 | public final class ViewManagerRegistry implements ComponentCallbacks2 {
|
26 | 30 |
|
| 31 | + public static final String TAG = "ViewManagerRegistry"; |
27 | 32 | private final Map<String, ViewManager> mViewManagers;
|
28 | 33 | private final @Nullable ViewManagerResolver mViewManagerResolver;
|
29 | 34 |
|
@@ -76,14 +81,33 @@ public synchronized ViewManager get(String className) {
|
76 | 81 | viewManager = getViewManagerFromResolver(rctViewManagerName);
|
77 | 82 | if (viewManager != null) return viewManager;
|
78 | 83 |
|
79 |
| - throw new IllegalViewOperationException( |
| 84 | + String errorMessage = |
80 | 85 | "Can't find ViewManager '"
|
81 | 86 | + className
|
82 | 87 | + "' nor '"
|
83 | 88 | + rctViewManagerName
|
84 | 89 | + "' in ViewManagerRegistry"
|
85 | 90 | + ", existing names are: "
|
86 |
| - + mViewManagerResolver.getViewManagerNames()); |
| 91 | + + mViewManagerResolver.getViewManagerNames(); |
| 92 | + // In release mode we don't want to crash the app if the view manager is not found. |
| 93 | + // Instead we return a dummy view manager that will render an empty view (including children) |
| 94 | + // and log an error. |
| 95 | + if (!ReactBuildConfig.DEBUG |
| 96 | + && ReactNativeFeatureFlags.enableGracefulUnregisteredComponentFailureAndroid()) { |
| 97 | + // 1. Log the error |
| 98 | + FLog.e(TAG, errorMessage); |
| 99 | + ReactSoftExceptionLogger.logSoftException( |
| 100 | + ReactSoftExceptionLogger.Categories.SOFT_ASSERTIONS, |
| 101 | + new IllegalStateException(errorMessage)); |
| 102 | + |
| 103 | + // 2. Render UnimplementedNativeView if found. |
| 104 | + viewManager = getViewManagerFromResolver("UnimplementedNativeView"); |
| 105 | + if (viewManager != null) { |
| 106 | + return viewManager; |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + throw new IllegalViewOperationException(errorMessage); |
87 | 111 | }
|
88 | 112 | throw new IllegalViewOperationException("No ViewManager found for class " + className);
|
89 | 113 | }
|
|
0 commit comments