React NativeMainActivity.javacreateApplicationDelegate()如何合并两个必要的方法

sg2wtvxw  于 2023-03-24  发布在  React
关注(0)|答案(1)|浏览(72)

在最近的一次react native 0.71.3的升级中,升级的一部分是添加了一个方法:

@Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
        this,
        getMainComponentName(),
        // If you opted-in for the New Architecture, we enable the Fabric Renderer.
        DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled
        // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
        DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled
        );
  }

指令是将其添加到MainActivity.java。这一切都很好,但有一个问题:
我们的代码已经有了这个方法,但形式完全不同,它使用了完全不同的机制

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
  return new InitialPropsReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }

我需要合并功能,并返回一个ReactActivityDelegate与我们需要的一切。有没有人有经验,如何正确地做到这一点?它让我为难。

3pvhb19x

3pvhb19x1#

我觉得这个就够了

@Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
        this,
        getMainComponentName(),
        // If you opted-in for the New Architecture, we enable the Fabric Renderer.
        DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled
        // If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
        DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled
    ) {
      @Override
      protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
      };
    };
  }

相关问题