Skip to content

Commit 87bf812

Browse files
zeyapfacebook-github-bot
authored andcommitted
move ViewTransition APIs not for react reconciler to its own TurboModule
Summary: ## Changelog: [General] [Changed] - move ViewTransition APIs not for react reconciler to its own TurboModule Move `unstable_getViewTransitionInstance` which is not consumed by react reconciler out of UIManagerBinding into a standalone NativeViewTransition CxxTurboModule, following the NativeDOM pattern. This avoids bloating UIManager with ViewTransition-specific APIs. Reviewed By: christophpurrer Differential Revision: D98360009
1 parent 91e3f77 commit 87bf812

File tree

6 files changed

+128
-48
lines changed

6 files changed

+128
-48
lines changed

packages/react-native/Libraries/ReactNative/FabricUIManager.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,6 @@ export interface Spec {
9797
+unstable_ContinuousEventPriority: number;
9898
+unstable_IdleEventPriority: number;
9999
+unstable_getCurrentEventPriority: () => number;
100-
+unstable_getViewTransitionInstance: (
101-
name: string,
102-
pseudo: string,
103-
) => ?{
104-
x: number,
105-
y: number,
106-
width: number,
107-
height: number,
108-
nativeTag: number,
109-
};
110100
}
111101

112102
let nativeFabricUIManagerProxy: ?Spec;
@@ -139,7 +129,6 @@ const CACHED_PROPERTIES = [
139129
'unstable_ContinuousEventPriority',
140130
'unstable_IdleEventPriority',
141131
'unstable_getCurrentEventPriority',
142-
'unstable_getViewTransitionInstance',
143132
];
144133

145134
// This is exposed as a getter because apps using the legacy renderer AND

packages/react-native/ReactCommon/react/nativemodule/defaults/DefaultTurboModules.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <react/nativemodule/intersectionobserver/NativeIntersectionObserver.h>
1414
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
1515
#include <react/nativemodule/mutationobserver/NativeMutationObserver.h>
16+
#include <react/nativemodule/viewtransition/NativeViewTransition.h>
1617
#include <react/nativemodule/webperformance/NativePerformance.h>
1718
#include <react/renderer/animated/AnimatedModule.h>
1819

@@ -57,6 +58,12 @@ namespace facebook::react {
5758
}
5859
}
5960

61+
if (ReactNativeFeatureFlags::viewTransitionEnabled()) {
62+
if (name == NativeViewTransition::kModuleName) {
63+
return std::make_shared<NativeViewTransition>(jsInvoker);
64+
}
65+
}
66+
6067
if (ReactNativeFeatureFlags::cxxNativeAnimatedEnabled() &&
6168
ReactNativeFeatureFlags::useSharedAnimatedBackend() &&
6269
name == AnimatedModule::kModuleName) {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "NativeViewTransition.h"
9+
10+
#include <react/renderer/uimanager/UIManagerBinding.h>
11+
12+
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
13+
#include "Plugins.h"
14+
#endif
15+
16+
std::shared_ptr<facebook::react::TurboModule>
17+
NativeViewTransitionModuleProvider(
18+
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
19+
return std::make_shared<facebook::react::NativeViewTransition>(
20+
std::move(jsInvoker));
21+
}
22+
23+
namespace facebook::react {
24+
25+
namespace {
26+
UIManager& getUIManagerFromRuntime(jsi::Runtime& runtime) {
27+
return UIManagerBinding::getBinding(runtime)->getUIManager();
28+
}
29+
} // namespace
30+
31+
NativeViewTransition::NativeViewTransition(
32+
std::shared_ptr<CallInvoker> jsInvoker)
33+
: NativeViewTransitionCxxSpec(std::move(jsInvoker)) {}
34+
35+
std::optional<jsi::Object> NativeViewTransition::getViewTransitionInstance(
36+
jsi::Runtime& rt,
37+
const std::string& name,
38+
const std::string& pseudo) {
39+
auto& uiManager = getUIManagerFromRuntime(rt);
40+
auto* viewTransitionDelegate = uiManager.getViewTransitionDelegate();
41+
if (viewTransitionDelegate == nullptr) {
42+
return std::nullopt;
43+
}
44+
45+
auto instance =
46+
viewTransitionDelegate->getViewTransitionInstance(name, pseudo);
47+
if (!instance) {
48+
return std::nullopt;
49+
}
50+
51+
auto result = jsi::Object(rt);
52+
result.setProperty(rt, "x", instance->x);
53+
result.setProperty(rt, "y", instance->y);
54+
result.setProperty(rt, "width", instance->width);
55+
result.setProperty(rt, "height", instance->height);
56+
result.setProperty(rt, "nativeTag", static_cast<double>(instance->nativeTag));
57+
return result;
58+
}
59+
60+
} // namespace facebook::react
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <optional>
11+
#include <string>
12+
13+
#if __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple
14+
#include "FBReactNativeSpecJSI.h"
15+
#else
16+
#include <FBReactNativeSpec/FBReactNativeSpecJSI.h>
17+
#endif
18+
19+
#include <react/renderer/bridging/bridging.h>
20+
21+
namespace facebook::react {
22+
23+
class NativeViewTransition : public NativeViewTransitionCxxSpec<NativeViewTransition> {
24+
public:
25+
explicit NativeViewTransition(std::shared_ptr<CallInvoker> jsInvoker);
26+
27+
std::optional<jsi::Object>
28+
getViewTransitionInstance(jsi::Runtime &rt, const std::string &name, const std::string &pseudo);
29+
};
30+
31+
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,43 +1147,6 @@ jsi::Value UIManagerBinding::get(
11471147
});
11481148
}
11491149

1150-
if (methodName == "unstable_getViewTransitionInstance") {
1151-
auto paramCount = 2;
1152-
return jsi::Function::createFromHostFunction(
1153-
runtime,
1154-
name,
1155-
paramCount,
1156-
[uiManager, methodName, paramCount](
1157-
jsi::Runtime& runtime,
1158-
const jsi::Value& /*thisValue*/,
1159-
const jsi::Value* arguments,
1160-
size_t count) -> jsi::Value {
1161-
validateArgumentCount(runtime, methodName, paramCount, count);
1162-
1163-
auto nameStr = arguments[0].asString(runtime).utf8(runtime);
1164-
auto pseudoStr = arguments[1].asString(runtime).utf8(runtime);
1165-
1166-
auto* viewTransitionDelegate = uiManager->getViewTransitionDelegate();
1167-
if (viewTransitionDelegate == nullptr) {
1168-
return jsi::Value::undefined();
1169-
}
1170-
1171-
auto instance = viewTransitionDelegate->getViewTransitionInstance(
1172-
nameStr, pseudoStr);
1173-
if (!instance) {
1174-
return jsi::Value::undefined();
1175-
}
1176-
auto result = jsi::Object(runtime);
1177-
result.setProperty(runtime, "x", instance->x);
1178-
result.setProperty(runtime, "y", instance->y);
1179-
result.setProperty(runtime, "width", instance->width);
1180-
result.setProperty(runtime, "height", instance->height);
1181-
result.setProperty(
1182-
runtime, "nativeTag", static_cast<double>(instance->nativeTag));
1183-
return result;
1184-
});
1185-
}
1186-
11871150
return jsi::Value::undefined();
11881151
}
11891152

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import type {TurboModule} from '../../../../../Libraries/TurboModule/RCTExport';
12+
13+
import * as TurboModuleRegistry from '../../../../../Libraries/TurboModule/TurboModuleRegistry';
14+
15+
export interface Spec extends TurboModule {
16+
+getViewTransitionInstance: (
17+
name: string,
18+
pseudo: string,
19+
) => ?{
20+
x: number,
21+
y: number,
22+
width: number,
23+
height: number,
24+
nativeTag: number,
25+
};
26+
}
27+
28+
export default (TurboModuleRegistry.get<Spec>(
29+
'NativeViewTransitionCxx',
30+
): ?Spec);

0 commit comments

Comments
 (0)