Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions packages/react-native/Libraries/ReactNative/FabricUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <react/nativemodule/intersectionobserver/NativeIntersectionObserver.h>
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
#include <react/nativemodule/mutationobserver/NativeMutationObserver.h>
#include <react/nativemodule/viewtransition/NativeViewTransition.h>
#include <react/nativemodule/webperformance/NativePerformance.h>
#include <react/renderer/animated/AnimatedModule.h>

Expand Down Expand Up @@ -57,6 +58,12 @@ namespace facebook::react {
}
}

if (ReactNativeFeatureFlags::viewTransitionEnabled()) {
if (name == NativeViewTransition::kModuleName) {
return std::make_shared<NativeViewTransition>(jsInvoker);
}
}

if (ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() &&
ReactNativeFeatureFlags::useSharedAnimatedBackend() &&
name == AnimatedModule::kModuleName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <react/renderer/uimanager/UIManagerBinding.h>

#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
#include "Plugins.h"
#endif

std::shared_ptr<facebook::react::TurboModule>
NativeViewTransitionModuleProvider(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativeViewTransition>(
std::move(jsInvoker));
}

namespace facebook::react {

NativeViewTransition::NativeViewTransition(
std::shared_ptr<CallInvoker> jsInvoker)
: NativeViewTransitionCxxSpec(std::move(jsInvoker)) {}

std::optional<jsi::Object> 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<double>(instance->nativeTag));
return result;
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -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 <optional>
#include <string>

#if __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple
#include "FBReactNativeSpecJSI.h"
#else
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
#endif

#include <react/renderer/bridging/bridging.h>

namespace facebook::react {

class NativeViewTransition : public NativeViewTransitionCxxSpec<NativeViewTransition> {
public:
explicit NativeViewTransition(std::shared_ptr<CallInvoker> jsInvoker);

std::optional<jsi::Object>
getViewTransitionInstance(jsi::Runtime &rt, const std::string &name, const std::string &pseudo);
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(instance->nativeTag));
return result;
});
}

return jsi::Value::undefined();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Spec>(
'NativeViewTransitionCxx',
): ?Spec);
Loading