Skip to content

Commit 0e65df9

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
move ViewTransition APIs not for react reconciler to its own TurboModule (#56257)
Summary: Pull Request resolved: #56257 ## 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 fbshipit-source-id: 191d0c8cc39fbe1cff87e12ad9a99d5e125b0250
1 parent 2bcb3e1 commit 0e65df9

File tree

14 files changed

+221
-48
lines changed

14 files changed

+221
-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/Package.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ let reactMutationObserverNativeModule = RNTarget(
351351
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactFabric, .reactTurboModuleBridging, .reactTurboModuleCore, .yoga]
352352
)
353353

354+
/// React-viewtransitionnativemodule.podspec
355+
let reactViewTransitionNativeModule = RNTarget(
356+
name: .reactViewTransitionNativeModule,
357+
path: "ReactCommon/react/nativemodule/viewtransition",
358+
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactFabric, .reactTurboModuleBridging, .reactTurboModuleCore, .yoga]
359+
)
360+
354361
/// React-featureflagnativemodule.podspec
355362
let reactFeatureflagsNativemodule = RNTarget(
356363
name: .reactFeatureflagsNativemodule,
@@ -701,6 +708,7 @@ let targets = [
701708
reactWebPerformanceNativeModule,
702709
reactIntersectionObserverNativeModule,
703710
reactMutationObserverNativeModule,
711+
reactViewTransitionNativeModule,
704712
reactFeatureflagsNativemodule,
705713
reactNativeModuleDom,
706714
reactAppDelegate,
@@ -890,6 +898,7 @@ extension String {
890898
static let reactWebPerformanceNativeModule = "React-webperformancenativemodule"
891899
static let reactIntersectionObserverNativeModule = "React-intersectionobservernativemodule"
892900
static let reactMutationObserverNativeModule = "React-mutationobservernativemodule"
901+
static let reactViewTransitionNativeModule = "React-viewtransitionnativemodule"
893902
static let reactFeatureflagsNativemodule = "React-featureflagsnativemodule"
894903
static let reactNativeModuleDom = "React-domnativemodule"
895904
static let reactAppDelegate = "React-RCTAppDelegate"

packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ add_react_common_subdir(react/nativemodule/microtasks)
131131
add_react_common_subdir(react/nativemodule/idlecallbacks)
132132
add_react_common_subdir(react/nativemodule/intersectionobserver)
133133
add_react_common_subdir(react/nativemodule/mutationobserver)
134+
add_react_common_subdir(react/nativemodule/viewtransition)
134135
add_react_common_subdir(react/nativemodule/webperformance)
135136
add_react_common_subdir(react/networking)
136137
add_react_common_subdir(jserrorhandler)
@@ -202,6 +203,7 @@ add_library(reactnative
202203
$<TARGET_OBJECTS:react_nativemodule_intersectionobserver>
203204
$<TARGET_OBJECTS:react_nativemodule_microtasks>
204205
$<TARGET_OBJECTS:react_nativemodule_mutationobserver>
206+
$<TARGET_OBJECTS:react_nativemodule_viewtransition>
205207
$<TARGET_OBJECTS:react_nativemodule_webperformance>
206208
$<TARGET_OBJECTS:react_networking>
207209
$<TARGET_OBJECTS:react_newarchdefaults>
@@ -301,6 +303,7 @@ target_include_directories(reactnative
301303
$<TARGET_PROPERTY:react_nativemodule_intersectionobserver,INTERFACE_INCLUDE_DIRECTORIES>
302304
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
303305
$<TARGET_PROPERTY:react_nativemodule_mutationobserver,INTERFACE_INCLUDE_DIRECTORIES>
306+
$<TARGET_PROPERTY:react_nativemodule_viewtransition,INTERFACE_INCLUDE_DIRECTORIES>
304307
$<TARGET_PROPERTY:react_nativemodule_webperformance,INTERFACE_INCLUDE_DIRECTORIES>
305308
$<TARGET_PROPERTY:react_networking,INTERFACE_INCLUDE_DIRECTORIES>
306309
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>

packages/react-native/ReactCommon/react/nativemodule/defaults/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_link_libraries(react_nativemodule_defaults
2323
react_nativemodule_idlecallbacks
2424
react_nativemodule_intersectionobserver
2525
react_nativemodule_mutationobserver
26+
react_nativemodule_viewtransition
2627
react_nativemodule_webperformance
2728
react_renderer_animated
2829
)

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) {

packages/react-native/ReactCommon/react/nativemodule/defaults/React-defaultsnativemodule.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Pod::Spec.new do |s|
5454
s.dependency "React-idlecallbacksnativemodule"
5555
s.dependency "React-intersectionobservernativemodule"
5656
s.dependency "React-mutationobservernativemodule"
57+
s.dependency "React-viewtransitionnativemodule"
5758
s.dependency "React-webperformancenativemodule"
5859
s.dependency "React-Fabric/animated"
5960
add_dependency(s, "React-RCTFBReactNativeSpec")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
10+
11+
file(GLOB react_nativemodule_viewtransition_SRC CONFIGURE_DEPENDS *.cpp)
12+
add_library(react_nativemodule_viewtransition OBJECT ${react_nativemodule_viewtransition_SRC})
13+
14+
target_include_directories(react_nativemodule_viewtransition PUBLIC ${REACT_COMMON_DIR})
15+
16+
target_link_libraries(react_nativemodule_viewtransition
17+
react_codegen_rncore
18+
react_cxxreact
19+
react_renderer_bridging
20+
react_renderer_core
21+
react_renderer_uimanager
22+
)
23+
target_compile_reactnative_options(react_nativemodule_viewtransition PRIVATE)
24+
target_compile_options(react_nativemodule_viewtransition PRIVATE -Wpedantic)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
NativeViewTransition::NativeViewTransition(
26+
std::shared_ptr<CallInvoker> jsInvoker)
27+
: NativeViewTransitionCxxSpec(std::move(jsInvoker)) {}
28+
29+
std::optional<jsi::Object> NativeViewTransition::getViewTransitionInstance(
30+
jsi::Runtime& rt,
31+
const std::string& name,
32+
const std::string& pseudo) {
33+
auto& uiManager = UIManagerBinding::getBinding(rt)->getUIManager();
34+
auto* viewTransitionDelegate = uiManager.getViewTransitionDelegate();
35+
if (viewTransitionDelegate == nullptr) {
36+
return std::nullopt;
37+
}
38+
39+
auto instance =
40+
viewTransitionDelegate->getViewTransitionInstance(name, pseudo);
41+
if (!instance) {
42+
return std::nullopt;
43+
}
44+
45+
auto result = jsi::Object(rt);
46+
result.setProperty(rt, "x", instance->x);
47+
result.setProperty(rt, "y", instance->y);
48+
result.setProperty(rt, "width", instance->width);
49+
result.setProperty(rt, "height", instance->height);
50+
result.setProperty(rt, "nativeTag", static_cast<double>(instance->nativeTag));
51+
return result;
52+
}
53+
54+
} // 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
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
require "json"
7+
8+
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "..", "package.json")))
9+
version = package['version']
10+
11+
source = { :git => 'https://github.com/facebook/react-native.git' }
12+
if version == '1000.0.0'
13+
# This is an unpublished version, use the latest commit hash of the react-native repo, which we're presumably in.
14+
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
15+
else
16+
source[:tag] = "v#{version}"
17+
end
18+
19+
header_search_paths = [
20+
"\"$(PODS_ROOT)/Headers/Private/Yoga\"",
21+
]
22+
23+
if ENV['USE_FRAMEWORKS']
24+
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the viewtransitionnativemodule to access its own files
25+
end
26+
27+
Pod::Spec.new do |s|
28+
s.name = "React-viewtransitionnativemodule"
29+
s.version = version
30+
s.summary = "React Native view transition native module"
31+
s.homepage = "https://reactnative.dev/"
32+
s.license = package["license"]
33+
s.author = "Meta Platforms, Inc. and its affiliates"
34+
s.platforms = min_supported_versions
35+
s.source = source
36+
s.source_files = podspec_sources("*.{cpp,h}", "*.h")
37+
s.header_dir = "react/nativemodule/viewtransition"
38+
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
39+
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
40+
"OTHER_CFLAGS" => "$(inherited)",
41+
"DEFINES_MODULE" => "YES" }
42+
43+
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: "React_viewtransitionnativemodule")
44+
45+
s.dependency "React-jsi"
46+
s.dependency "React-jsiexecutor"
47+
48+
depend_on_js_engine(s)
49+
add_rn_third_party_dependencies(s)
50+
add_rncore_dependency(s)
51+
52+
s.dependency "Yoga"
53+
s.dependency "ReactCommon/turbomodule/core"
54+
s.dependency "React-Fabric"
55+
s.dependency "React-Fabric/bridging"
56+
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])
57+
add_dependency(s, "React-RCTFBReactNativeSpec")
58+
end

0 commit comments

Comments
 (0)