diff --git a/packages/react-native/Libraries/ReactNative/FabricUIManager.js b/packages/react-native/Libraries/ReactNative/FabricUIManager.js index 13130d083106..40de0d069c75 100644 --- a/packages/react-native/Libraries/ReactNative/FabricUIManager.js +++ b/packages/react-native/Libraries/ReactNative/FabricUIManager.js @@ -97,16 +97,6 @@ export interface Spec { +unstable_ContinuousEventPriority: number; +unstable_IdleEventPriority: number; +unstable_getCurrentEventPriority: () => number; - +unstable_getViewTransitionInstance: ( - name: string, - pseudo: string, - ) => ?{ - x: number, - y: number, - width: number, - height: number, - nativeTag: number, - }; } let nativeFabricUIManagerProxy: ?Spec; @@ -139,7 +129,6 @@ const CACHED_PROPERTIES = [ 'unstable_ContinuousEventPriority', 'unstable_IdleEventPriority', 'unstable_getCurrentEventPriority', - 'unstable_getViewTransitionInstance', ]; // This is exposed as a getter because apps using the legacy renderer AND diff --git a/packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp b/packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp index fe36e1af6c74..192805b01122 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -57,6 +58,12 @@ namespace facebook::react { } } + if (ReactNativeFeatureFlags::viewTransitionEnabled()) { + if (name == NativeViewTransition::kModuleName) { + return std::make_shared(jsInvoker); + } + } + if (ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() && ReactNativeFeatureFlags::useSharedAnimatedBackend() && name == AnimatedModule::kModuleName) { diff --git a/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.cpp b/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.cpp new file mode 100644 index 000000000000..6fb69012df42 --- /dev/null +++ b/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.cpp @@ -0,0 +1,54 @@ +/* + * 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 "NativeViewTransition.h" + +#include + +#ifdef RN_DISABLE_OSS_PLUGIN_HEADER +#include "Plugins.h" +#endif + +std::shared_ptr +NativeViewTransitionModuleProvider( + std::shared_ptr jsInvoker) { + return std::make_shared( + std::move(jsInvoker)); +} + +namespace facebook::react { + +NativeViewTransition::NativeViewTransition( + std::shared_ptr jsInvoker) + : NativeViewTransitionCxxSpec(std::move(jsInvoker)) {} + +std::optional NativeViewTransition::getViewTransitionInstance( + jsi::Runtime& rt, + const std::string& name, + const std::string& pseudo) { + auto& uiManager = UIManagerBinding::getBinding(rt)->getUIManager(); + auto* viewTransitionDelegate = uiManager.getViewTransitionDelegate(); + if (viewTransitionDelegate == nullptr) { + return std::nullopt; + } + + auto instance = + viewTransitionDelegate->getViewTransitionInstance(name, pseudo); + if (!instance) { + return std::nullopt; + } + + auto result = jsi::Object(rt); + result.setProperty(rt, "x", instance->x); + result.setProperty(rt, "y", instance->y); + result.setProperty(rt, "width", instance->width); + result.setProperty(rt, "height", instance->height); + result.setProperty(rt, "nativeTag", static_cast(instance->nativeTag)); + return result; +} + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.h b/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.h new file mode 100644 index 000000000000..bd5cb3b424f2 --- /dev/null +++ b/packages/react-native/ReactCommon/react/nativemodule/viewtransition/NativeViewTransition.h @@ -0,0 +1,31 @@ +/* + * 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 +#include + +#if __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple +#include "FBReactNativeSpecJSI.h" +#else +#include +#endif + +#include + +namespace facebook::react { + +class NativeViewTransition : public NativeViewTransitionCxxSpec { + public: + explicit NativeViewTransition(std::shared_ptr jsInvoker); + + std::optional + getViewTransitionInstance(jsi::Runtime &rt, const std::string &name, const std::string &pseudo); +}; + +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index 0abcbc18affd..c9d08a9d80bc 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -1147,43 +1147,6 @@ jsi::Value UIManagerBinding::get( }); } - if (methodName == "unstable_getViewTransitionInstance") { - auto paramCount = 2; - return jsi::Function::createFromHostFunction( - runtime, - name, - paramCount, - [uiManager, methodName, paramCount]( - jsi::Runtime& runtime, - const jsi::Value& /*thisValue*/, - const jsi::Value* arguments, - size_t count) -> jsi::Value { - validateArgumentCount(runtime, methodName, paramCount, count); - - auto nameStr = arguments[0].asString(runtime).utf8(runtime); - auto pseudoStr = arguments[1].asString(runtime).utf8(runtime); - - auto* viewTransitionDelegate = uiManager->getViewTransitionDelegate(); - if (viewTransitionDelegate == nullptr) { - return jsi::Value::undefined(); - } - - auto instance = viewTransitionDelegate->getViewTransitionInstance( - nameStr, pseudoStr); - if (!instance) { - return jsi::Value::undefined(); - } - auto result = jsi::Object(runtime); - result.setProperty(runtime, "x", instance->x); - result.setProperty(runtime, "y", instance->y); - result.setProperty(runtime, "width", instance->width); - result.setProperty(runtime, "height", instance->height); - result.setProperty( - runtime, "nativeTag", static_cast(instance->nativeTag)); - return result; - }); - } - return jsi::Value::undefined(); } diff --git a/packages/react-native/src/private/viewtransition/specs/NativeViewTransition.js b/packages/react-native/src/private/viewtransition/specs/NativeViewTransition.js new file mode 100644 index 000000000000..3f229fa9160b --- /dev/null +++ b/packages/react-native/src/private/viewtransition/specs/NativeViewTransition.js @@ -0,0 +1,30 @@ +/** + * 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. + * + * @flow strict-local + * @format + */ + +import type {TurboModule} from '../../../../Libraries/TurboModule/RCTExport'; + +import * as TurboModuleRegistry from '../../../../Libraries/TurboModule/TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +getViewTransitionInstance: ( + name: string, + pseudo: string, + ) => ?{ + x: number, + y: number, + width: number, + height: number, + nativeTag: number, + }; +} + +export default (TurboModuleRegistry.get( + 'NativeViewTransitionCxx', +): ?Spec);