mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fabric Automatic Interop for Android (#42294)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42294 This changes enables the Fabric Intrerop Layer automatically for all the users. Practically I'm removing the fallback `ComponentDescriptor` inside the `ComponentDescriptorRegistry` so that if a component hasn't been automatically registered by a user, instead of showing the UnimplementedView, it loads a `UnstableLegacyViewManagerAutomaticComponentDescriptor`. This ComponentDescriptor is built starting from the legacy component name, and responds with correct `ComponentName` and `ComponentHandle` (similarly to the `UnstableLegacyViewManagerInteropComponentDescriptor` but without using C++ templates). Changelog: [Internal] [Changed] - Fabric Automatic Interop for Android Reviewed By: sammy-SC Differential Revision: D52663244 fbshipit-source-id: f466486c638bb1362ef59128cd69bb9731bb9739
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5e8ce6ca5e
commit
748d674dd5
@@ -13,6 +13,9 @@ bool EmptyReactNativeConfig::getBool(const std::string& param) const {
|
||||
if (param == "react_fabric:enabled_layout_animations_ios") {
|
||||
return true;
|
||||
}
|
||||
if (param == "react_fabric:enabled_automatic_interop_android") {
|
||||
return true;
|
||||
}
|
||||
if (param == "react_native_devx:enable_modern_cdp_registry") {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ target_link_libraries(react_render_componentregistry
|
||||
folly_runtime
|
||||
glog_init
|
||||
jsi
|
||||
react_config
|
||||
react_debug
|
||||
react_render_core
|
||||
react_render_debug
|
||||
react_utils
|
||||
rrc_legacyviewmanagerinterop
|
||||
)
|
||||
|
||||
+16
-3
@@ -9,11 +9,13 @@
|
||||
|
||||
#include "componentNameByReactViewName.h"
|
||||
|
||||
#include <react/config/ReactNativeConfig.h>
|
||||
#include <react/debug/react_native_assert.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticComponentDescriptor.h>
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticShadowNode.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/ShadowNodeFragment.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace facebook::react {
|
||||
@@ -82,12 +84,23 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
|
||||
}
|
||||
|
||||
if (it == _registryByName.end()) {
|
||||
if (_fallbackComponentDescriptor == nullptr) {
|
||||
auto reactNativeConfig_ =
|
||||
contextContainer_->at<std::shared_ptr<const ReactNativeConfig>>(
|
||||
"ReactNativeConfig");
|
||||
if (reactNativeConfig_->getBool(
|
||||
"react_fabric:enabled_automatic_interop_android")) {
|
||||
auto componentDescriptor = std::make_shared<
|
||||
const UnstableLegacyViewManagerAutomaticComponentDescriptor>(
|
||||
parameters_, unifiedComponentName);
|
||||
registerComponentDescriptor(componentDescriptor);
|
||||
return *_registryByName.find(unifiedComponentName)->second;
|
||||
} else if (_fallbackComponentDescriptor == nullptr) {
|
||||
throw std::invalid_argument(
|
||||
("Unable to find componentDescriptor for " + unifiedComponentName)
|
||||
.c_str());
|
||||
} else {
|
||||
return *_fallbackComponentDescriptor.get();
|
||||
}
|
||||
return *_fallbackComponentDescriptor.get();
|
||||
}
|
||||
|
||||
return *it->second;
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "UnstableLegacyViewManagerAutomaticComponentDescriptor.h"
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticShadowNode.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
#include <react/renderer/core/ReactPrimitives.h>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
ComponentName
|
||||
UnstableLegacyViewManagerAutomaticComponentDescriptor::getComponentName()
|
||||
const {
|
||||
return legacyComponentName_.c_str();
|
||||
}
|
||||
|
||||
ComponentHandle
|
||||
UnstableLegacyViewManagerAutomaticComponentDescriptor::getComponentHandle()
|
||||
const {
|
||||
return reinterpret_cast<ComponentHandle>(getComponentName());
|
||||
}
|
||||
} // namespace facebook::react
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerAutomaticShadowNode.h>
|
||||
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
||||
#include <react/renderer/core/ReactPrimitives.h>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class UnstableLegacyViewManagerAutomaticComponentDescriptor final
|
||||
: public ConcreteComponentDescriptor<
|
||||
LegacyViewManagerAndroidInteropShadowNode> {
|
||||
public:
|
||||
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
||||
|
||||
UnstableLegacyViewManagerAutomaticComponentDescriptor(
|
||||
const ComponentDescriptorParameters& parameters,
|
||||
std::string legacyComponentName)
|
||||
: ConcreteComponentDescriptor(parameters),
|
||||
legacyComponentName_(std::move(legacyComponentName)) {}
|
||||
|
||||
ComponentHandle getComponentHandle() const override;
|
||||
ComponentName getComponentName() const override;
|
||||
|
||||
private:
|
||||
std::string legacyComponentName_;
|
||||
};
|
||||
} // namespace facebook::react
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char LegacyViewManagerAndroidInteropComponentName[] =
|
||||
"LegacyViewManagerInterop";
|
||||
|
||||
} // namespace facebook::react
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewEventEmitter.h>
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
|
||||
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
extern const char LegacyViewManagerAndroidInteropComponentName[];
|
||||
|
||||
using LegacyViewManagerAndroidInteropShadowNode = ConcreteViewShadowNode<
|
||||
LegacyViewManagerAndroidInteropComponentName,
|
||||
LegacyViewManagerInteropViewProps>;
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
||||
#include <react/renderer/components/AppSpecs/ComponentDescriptors.h>
|
||||
#include <react/renderer/components/legacyviewmanagerinterop/UnstableLegacyViewManagerInteropComponentDescriptor.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -24,9 +23,6 @@ void registerComponents(
|
||||
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
|
||||
registry->add(concreteComponentDescriptorProvider<
|
||||
RNTMyNativeViewComponentDescriptor>());
|
||||
registry->add(concreteComponentDescriptorProvider<
|
||||
UnstableLegacyViewManagerInteropComponentDescriptor<
|
||||
RNTMyNativeViewName>>());
|
||||
}
|
||||
|
||||
std::shared_ptr<TurboModule> cxxModuleProvider(
|
||||
|
||||
Reference in New Issue
Block a user