Search code examples
androidreact-nativeandroid-activityreact-native-fast-image

Disable Fabric in React Native


I'm using React Native 0.71.x in my project and have react-native-fast-image which does not support the latest Fabric architecture. So I'd like to disable it if possible. How do I go about doing this? I haven't set up anything specifically for fabric so I guess it is enabled by default.


Solution

  • Follow what is said in React Native's documentation to enable it, and do the opposite.

    Assuming that you're coding an app for Android:

    MyApplication.java

    public class MyApplication extends Application implements ReactApplication {
    
      private final ReactNativeHost mReactNativeHost =
        new ReactNativeHost(this) {
    
          // Remove those lines:
          @Nullable
          @Override
          protected JSIModulePackage getJSIModulePackage() {
            return new JSIModulePackage() {
              @Override
              public List<JSIModuleSpec> getJSIModules(
                  final ReactApplicationContext reactApplicationContext,
                  final JavaScriptContextHolder jsContext) {
                final List<JSIModuleSpec> specs = new ArrayList<>();
                specs.add(new JSIModuleSpec() {
                  @Override
                  public JSIModuleType getJSIModuleType() {
                    return JSIModuleType.UIManager;
                  }
    
                  @Override
                  public JSIModuleProvider<UIManager> getJSIModuleProvider() {
                    final ComponentFactory componentFactory = new ComponentFactory();
                    CoreComponentsRegistry.register(componentFactory);
                    final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
    
                    ViewManagerRegistry viewManagerRegistry =
                        new ViewManagerRegistry(
                            reactInstanceManager.getOrCreateViewManagers(
                                reactApplicationContext));
    
                    return new FabricJSIModuleProvider(
                        reactApplicationContext,
                        componentFactory,
                        new EmptyReactNativeConfig(),
                        viewManagerRegistry);
                  }
                });
                return specs;
              }
            };
          }
        };
    }
    

    gradle.properties

    # Set this line to false
    newArchEnabled=true