react-native-windows 0.82.1 → 0.83.0-preview.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/.flowconfig +2 -7
  2. package/Libraries/Animated/components/AnimatedFlatList.js +5 -3
  3. package/Libraries/Animated/components/AnimatedImage.js +4 -3
  4. package/Libraries/Animated/components/AnimatedSectionList.js +2 -2
  5. package/Libraries/Animated/components/AnimatedText.js +7 -3
  6. package/Libraries/Animated/components/AnimatedView.js +3 -2
  7. package/Libraries/Animated/createAnimatedComponent.js +24 -12
  8. package/Libraries/Animated/nodes/AnimatedColor.js +26 -10
  9. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +43 -15
  10. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.windows.js +43 -15
  11. package/Libraries/Components/ActivityIndicator/ActivityIndicator.d.ts +2 -2
  12. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +2 -2
  13. package/Libraries/Components/Glyph/Glyph.js +4 -1
  14. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.d.ts +2 -2
  15. package/Libraries/Components/RefreshControl/RefreshControl.d.ts +3 -3
  16. package/Libraries/Components/SafeAreaView/SafeAreaView.d.ts +2 -2
  17. package/Libraries/Components/ScrollView/ScrollView.js +1 -0
  18. package/Libraries/Components/ScrollView/ScrollView.windows.js +1 -0
  19. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +6 -6
  20. package/Libraries/Components/Switch/Switch.d.ts +2 -2
  21. package/Libraries/Components/Switch/Switch.windows.js +1 -1
  22. package/Libraries/Components/TextInput/TextInput.d.ts +2 -5
  23. package/Libraries/Components/TextInput/TextInput.js +6 -0
  24. package/Libraries/Components/TextInput/TextInput.windows.js +6 -0
  25. package/Libraries/Components/Touchable/TouchableBounce.js +7 -7
  26. package/Libraries/Components/Touchable/TouchableBounce.windows.js +7 -7
  27. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +1 -1
  28. package/Libraries/Components/View/ReactNativeStyleAttributes.js +19 -1
  29. package/Libraries/Components/View/View.d.ts +2 -2
  30. package/Libraries/Components/View/View.windows.js +0 -1
  31. package/Libraries/Components/View/ViewNativeComponent.js +13 -1
  32. package/Libraries/Core/ReactNativeVersion.js +3 -3
  33. package/Libraries/Core/setUpPerformance.js +2 -0
  34. package/Libraries/Debugging/DebuggingOverlay.js +14 -14
  35. package/Libraries/Debugging/DebuggingOverlayRegistry.js +8 -2
  36. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +5 -2
  37. package/Libraries/Image/Image.d.ts +3 -3
  38. package/Libraries/Image/ImageInjection.js +3 -6
  39. package/Libraries/Image/ImageTypes.flow.js +3 -7
  40. package/Libraries/Lists/FlatList.js +8 -8
  41. package/Libraries/Lists/SectionList.d.ts +5 -1
  42. package/Libraries/Lists/ViewabilityHelper.js +1 -1
  43. package/Libraries/Lists/VirtualizedList.js +1 -0
  44. package/Libraries/LogBox/UI/AnsiHighlight.js +4 -1
  45. package/Libraries/NativeComponent/BaseViewConfig.android.js +11 -2
  46. package/Libraries/NativeComponent/NativeComponentRegistry.d.ts +98 -0
  47. package/Libraries/NativeComponent/NativeComponentRegistry.js +2 -0
  48. package/Libraries/NativeComponent/NativeComponentRegistryUnstable.js +3 -1
  49. package/Libraries/NativeComponent/ViewConfigIgnore.windows.js +45 -0
  50. package/Libraries/Network/RCTNetworking.android.js +3 -1
  51. package/Libraries/Network/RCTNetworking.ios.js +3 -0
  52. package/Libraries/Network/RCTNetworking.windows.js +3 -0
  53. package/Libraries/Network/XMLHttpRequest.js +1 -41
  54. package/Libraries/Pressability/usePressability.js +14 -3
  55. package/Libraries/ReactNative/PaperUIManager.windows.js +3 -3
  56. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +20 -82
  57. package/Libraries/ReactNative/getNativeComponentAttributes.js +12 -0
  58. package/Libraries/Renderer/implementations/ReactFabric-dev.js +6759 -4478
  59. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3169 -3119
  60. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4732 -3535
  61. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +6646 -4070
  62. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3136 -2825
  63. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4761 -3312
  64. package/Libraries/Renderer/shims/ReactNative.js +3 -1
  65. package/Libraries/Renderer/shims/ReactNativeTypes.js +2 -1
  66. package/Libraries/Renderer/shims/ReactNativeTypes.windows.js +2 -1
  67. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
  68. package/Libraries/StyleSheet/StyleSheetTypes.js +44 -0
  69. package/Libraries/StyleSheet/processBackgroundPosition.js +284 -0
  70. package/Libraries/StyleSheet/processBackgroundRepeat.js +105 -0
  71. package/Libraries/StyleSheet/processBackgroundSize.js +104 -0
  72. package/Libraries/Text/Text.d.ts +2 -2
  73. package/Libraries/Text/TextNativeComponent.js +10 -0
  74. package/Libraries/TurboModule/TurboModuleRegistry.js +3 -9
  75. package/Libraries/Utilities/DevLoadingView.js +14 -6
  76. package/Libraries/Utilities/HMRClient.js +13 -5
  77. package/Microsoft.ReactNative/Base/CxxReactIncludes.h +11 -0
  78. package/Microsoft.ReactNative/CompositionComponentView.idl +2 -0
  79. package/Microsoft.ReactNative/CompositionHwndHost.idl +1 -0
  80. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +1 -1
  81. package/Microsoft.ReactNative/Fabric/ComponentView.h +1 -1
  82. package/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp +10 -40
  83. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +3 -80
  84. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +45 -12
  85. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +8 -0
  86. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +61 -74
  87. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +4 -0
  88. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +1 -0
  89. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +4 -3
  90. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +2 -1
  91. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.cpp +245 -0
  92. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.h +80 -0
  93. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +20 -36
  94. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +70 -49
  95. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -1
  96. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +5 -0
  97. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/WindowsTextLayoutManager.cpp +7 -2
  98. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +1 -0
  99. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -1
  100. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -1
  101. package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +20 -94
  102. package/Microsoft.ReactNative/Modules/LogBoxModule.h +1 -3
  103. package/Microsoft.ReactNative/Pch/pch.h +2 -0
  104. package/Microsoft.ReactNative/ReactHost/CrashManager.cpp +5 -0
  105. package/Microsoft.ReactNative/ReactHost/ReactNativeHeaders.h +1 -0
  106. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +0 -41
  107. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +0 -11
  108. package/Microsoft.ReactNative/ReactNativeIsland.idl +2 -3
  109. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +31 -101
  110. package/Microsoft.ReactNative/ReactNativeWin32App.h +2 -13
  111. package/Microsoft.ReactNative/ReactNativeWindow.idl +44 -0
  112. package/Microsoft.ReactNative.Cxx/AutoDraw.h +9 -1
  113. package/Microsoft.ReactNative.Cxx/ReactCommon/CallInvoker.h +13 -16
  114. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModule.h +24 -36
  115. package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModuleUtils.h +5 -8
  116. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/AString.h +8 -6
  117. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Array.h +32 -49
  118. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Base.h +27 -76
  119. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Bool.h +4 -2
  120. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/CallbackWrapper.h +19 -18
  121. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Class.h +25 -48
  122. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Convert.h +38 -31
  123. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Error.h +11 -6
  124. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/EventEmitter.h +47 -45
  125. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Function.h +69 -89
  126. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/HighResTimeStamp.h +8 -8
  127. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/LongLivedObject.h +6 -6
  128. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Number.h +16 -8
  129. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Object.h +17 -24
  130. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Promise.h +17 -17
  131. package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Value.h +20 -29
  132. package/Microsoft.ReactNative.Cxx/ReactCommon/react/debug/react_native_assert.h +2 -7
  133. package/Microsoft.ReactNative.Cxx/ReactCommon/react/timing/primitives.h +127 -115
  134. package/PropertySheets/External/Microsoft.ReactNative.Composition.CppLib.props +10 -0
  135. package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +10 -0
  136. package/PropertySheets/Generated/PackageVersion.g.props +5 -5
  137. package/PropertySheets/Warnings.props +2 -1
  138. package/ReactCommon/ReactCommon.vcxproj +21 -12
  139. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/CxxNativeModule.cpp +2 -2
  140. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/Instance.cpp +381 -0
  141. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +49 -0
  142. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSIndexedRAMBundle.cpp +145 -0
  143. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/MethodCall.cpp +100 -0
  144. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ModuleRegistry.cpp +256 -0
  145. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +13 -4
  146. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/RAMBundleRegistry.cpp +93 -0
  147. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ReactMarker.cpp +149 -0
  148. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/TraceSection.h +25 -35
  149. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +86 -67
  150. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSIExecutor.cpp +629 -0
  151. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSINativeModules.cpp +123 -0
  152. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.cpp +84 -68
  153. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.h +31 -35
  154. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/Utf8.h +4 -5
  155. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/network/HttpUtils.cpp +2 -1
  156. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +24 -36
  157. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/dom/NativeDOM.h +28 -66
  158. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/webperformance/NativePerformance.cpp +414 -0
  159. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +3 -3
  160. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/image/conversions.h +8 -4
  161. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/ParagraphShadowNode.cpp +19 -16
  162. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h +8 -9
  163. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +25 -95
  164. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +85 -42
  165. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventDispatcher.cpp +81 -0
  166. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventQueueProcessor.cpp +140 -0
  167. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/primitives.h +25 -31
  168. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/UIManager.cpp +746 -0
  169. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +702 -0
  170. package/Scripts/Tfs/Layout-Desktop-Headers.ps1 +1 -15
  171. package/Scripts/creaternwapp.cmd +1 -1
  172. package/Scripts/perf/compare-results.js +357 -0
  173. package/Scripts/perf/create-perf-test.js +343 -0
  174. package/Scripts/perf/post-pr-comment.js +210 -0
  175. package/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +8 -0
  176. package/Shared/Hermes/HermesRuntimeTargetDelegate.h +3 -0
  177. package/Shared/Shared.vcxitems +24 -12
  178. package/Shared/Shared.vcxitems.filters +11 -3
  179. package/codegen/NativeIntersectionObserverSpec.g.h +2 -0
  180. package/codegen/NativeNetworkingIOSSpec.g.h +2 -0
  181. package/codegen/NativePerformanceSpec.g.h +6 -0
  182. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +229 -139
  183. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +2 -1
  184. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +42 -25
  185. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +2 -1
  186. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +2 -1
  187. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +11 -6
  188. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +11 -6
  189. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +1 -0
  190. package/codegen/react/components/rnwcore/InputAccessory.g.h +2 -1
  191. package/codegen/react/components/rnwcore/ModalHostView.g.h +40 -23
  192. package/codegen/react/components/rnwcore/Props.cpp +6 -1
  193. package/codegen/react/components/rnwcore/Props.h +1 -0
  194. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +11 -6
  195. package/codegen/react/components/rnwcore/SafeAreaView.g.h +1 -0
  196. package/codegen/react/components/rnwcore/Switch.g.h +11 -6
  197. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +2 -1
  198. package/codegen/react/components/rnwcore/VirtualView.g.h +41 -8
  199. package/codegen/react/components/rnwcore/VirtualViewExperimental.g.h +45 -8
  200. package/codegen/rnwcoreJSI.h +3973 -6059
  201. package/index.js +6 -0
  202. package/index.windows.js +6 -0
  203. package/jest/mockComponent.js +6 -6
  204. package/jest/setup.js +15 -10
  205. package/package.json +27 -27
  206. package/src/private/components/virtualview/VirtualView.js +22 -27
  207. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +6 -0
  208. package/src/private/featureflags/ReactNativeFeatureFlags.js +100 -19
  209. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +18 -3
  210. package/src/private/setup/setUpDefaultReactNativeEnvironment.js +6 -0
  211. package/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js +1 -1
  212. package/src/private/specs_DEPRECATED/modules/NativeNetworkingIOS.js +1 -0
  213. package/src/private/webapis/dom/nodes/ReactNativeElement.js +12 -2
  214. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +76 -15
  215. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +1 -0
  216. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
  217. package/src/private/webapis/performance/ResourceTiming.js +31 -4
  218. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +4 -1
  219. package/src/private/webapis/performance/specs/NativePerformance.js +3 -0
  220. package/stubs/double-conversion/double-conversion.h +5 -0
  221. package/templates/cpp-app/template.config.js +1 -1
  222. package/templates/cpp-app/windows/MyApp/MyApp.vcxproj +3 -1
  223. package/templates/cpp-lib/template.config.js +1 -1
  224. package/templates/cpp-lib/windows/MyLib/MyLib.vcxproj +1 -1
  225. package/types/index.d.ts +1 -0
  226. package/types/public/ReactNativeTypes.d.ts +115 -2
  227. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +0 -152
  228. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/conversions.h +0 -1574
  229. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/ShadowNode.cpp +0 -528
  230. package/Scripts/OpenSSL.nuspec +0 -39
  231. package/Scripts/OpenSSL.targets +0 -36
  232. package/codegen/rnwcoreJSI-generated.cpp +0 -3470
@@ -0,0 +1,746 @@
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
+
9
+ #if _MSC_VER
10
+ #pragma warning(push)
11
+ #pragma warning(disable : 4996) // deprecated APIs
12
+ #endif
13
+ #include "UIManager.h"
14
+
15
+ #include <cxxreact/JSExecutor.h>
16
+ #include <cxxreact/TraceSection.h>
17
+ #include <react/debug/react_native_assert.h>
18
+ #include <react/featureflags/ReactNativeFeatureFlags.h>
19
+ #include <react/renderer/core/DynamicPropsUtilities.h>
20
+ #include <react/renderer/core/PropsParserContext.h>
21
+ #include <react/renderer/core/ShadowNodeFragment.h>
22
+ #include <react/renderer/uimanager/AppRegistryBinding.h>
23
+ #include <react/renderer/uimanager/UIManagerBinding.h>
24
+ #include <react/renderer/uimanager/UIManagerCommitHook.h>
25
+ #include <react/renderer/uimanager/UIManagerMountHook.h>
26
+
27
+ #include <glog/logging.h>
28
+
29
+ #include <utility>
30
+
31
+ namespace {
32
+ std::unique_ptr<facebook::react::LeakChecker> constructLeakCheckerIfNeeded(
33
+ const facebook::react::RuntimeExecutor& runtimeExecutor) {
34
+ #ifdef REACT_NATIVE_DEBUG
35
+ return std::make_unique<facebook::react::LeakChecker>(runtimeExecutor);
36
+ #else
37
+ return {};
38
+ #endif
39
+ }
40
+ } // namespace
41
+
42
+ namespace facebook::react {
43
+
44
+ // Explicitly define destructors here, as they have to exist in order to act as
45
+ // a "key function" for the ShadowNodeWrapper class -- this allows for RTTI to
46
+ // work properly across dynamic library boundaries (i.e. dynamic_cast that is
47
+ // used by getNativeState method)
48
+ ShadowNodeListWrapper::~ShadowNodeListWrapper() = default;
49
+
50
+ UIManager::UIManager(
51
+ const RuntimeExecutor& runtimeExecutor,
52
+ std::shared_ptr<const ContextContainer> contextContainer)
53
+ : runtimeExecutor_(runtimeExecutor),
54
+ shadowTreeRegistry_(),
55
+ contextContainer_(std::move(contextContainer)),
56
+ leakChecker_(constructLeakCheckerIfNeeded(runtimeExecutor)),
57
+ lazyShadowTreeRevisionConsistencyManager_(
58
+ std::make_unique<LazyShadowTreeRevisionConsistencyManager>(
59
+ shadowTreeRegistry_)) {}
60
+
61
+ UIManager::~UIManager() {
62
+ LOG(WARNING) << "UIManager::~UIManager() was called (address: " << this
63
+ << ").";
64
+ }
65
+
66
+ std::shared_ptr<ShadowNode> UIManager::createNode(
67
+ Tag tag,
68
+ const std::string& name,
69
+ SurfaceId surfaceId,
70
+ RawProps rawProps,
71
+ InstanceHandle::Shared instanceHandle) const {
72
+ TraceSection s("UIManager::createNode", "componentName", name);
73
+
74
+ auto& componentDescriptor = componentDescriptorRegistry_->at(name);
75
+ auto fallbackDescriptor =
76
+ componentDescriptorRegistry_->getFallbackComponentDescriptor();
77
+
78
+ PropsParserContext propsParserContext{surfaceId, *contextContainer_};
79
+
80
+ auto family = componentDescriptor.createFamily(
81
+ {.tag = tag,
82
+ .surfaceId = surfaceId,
83
+ .instanceHandle = std::move(instanceHandle)});
84
+ const auto props = componentDescriptor.cloneProps(
85
+ propsParserContext, nullptr, std::move(rawProps));
86
+ const auto state = componentDescriptor.createInitialState(props, family);
87
+
88
+ auto shadowNode = componentDescriptor.createShadowNode(
89
+ ShadowNodeFragment{
90
+ .props = fallbackDescriptor != nullptr &&
91
+ fallbackDescriptor->getComponentHandle() ==
92
+ componentDescriptor.getComponentHandle()
93
+ ? componentDescriptor.cloneProps(
94
+ propsParserContext,
95
+ props,
96
+ RawProps(folly::dynamic::object("name", name)))
97
+ : props,
98
+ .children = ShadowNodeFragment::childrenPlaceholder(),
99
+ .state = state,
100
+ },
101
+ family);
102
+
103
+ if (delegate_ != nullptr) {
104
+ delegate_->uiManagerDidCreateShadowNode(*shadowNode);
105
+ }
106
+ if (leakChecker_) {
107
+ leakChecker_->uiManagerDidCreateShadowNodeFamily(family);
108
+ }
109
+
110
+ return shadowNode;
111
+ }
112
+
113
+ std::shared_ptr<ShadowNode> UIManager::cloneNode(
114
+ const ShadowNode& shadowNode,
115
+ const ShadowNode::SharedListOfShared& children,
116
+ RawProps rawProps) const {
117
+ TraceSection s(
118
+ "UIManager::cloneNode", "componentName", shadowNode.getComponentName());
119
+
120
+ PropsParserContext propsParserContext{
121
+ shadowNode.getFamily().getSurfaceId(), *contextContainer_};
122
+
123
+ auto& componentDescriptor = shadowNode.getComponentDescriptor();
124
+ auto& family = shadowNode.getFamily();
125
+ auto props = ShadowNodeFragment::propsPlaceholder();
126
+
127
+ if (!rawProps.isEmpty()) {
128
+ if (family.nativeProps_DEPRECATED != nullptr) {
129
+ // 1. update the nativeProps_DEPRECATED props.
130
+ //
131
+ // In this step, we want the most recent value for the props
132
+ // managed by setNativeProps.
133
+ // Values in `rawProps` patch (take precedence over)
134
+ // `nativeProps_DEPRECATED`. For example, if both
135
+ // `nativeProps_DEPRECATED` and `rawProps` contain key 'A'.
136
+ // Value from `rawProps` overrides what was previously in
137
+ // `nativeProps_DEPRECATED`. Notice that the `nativeProps_DEPRECATED`
138
+ // patch will not get more props from `rawProps`: if the key is not
139
+ // present in `nativeProps_DEPRECATED`, it will not be added.
140
+ //
141
+ // The result of this operation is the new `nativeProps_DEPRECATED`.
142
+ family.nativeProps_DEPRECATED =
143
+ std::make_unique<folly::dynamic>(mergeDynamicProps(
144
+ *family.nativeProps_DEPRECATED, // source
145
+ (folly::dynamic)rawProps, // patch
146
+ NullValueStrategy::Ignore));
147
+
148
+ // 2. Compute the final set of props.
149
+ //
150
+ // This step takes the new props handled by `setNativeProps` and
151
+ // merges them in the `rawProps` managed by React.
152
+ // The new props handled by `nativeProps` now takes precedence
153
+ // on the props handled by React, as we want to make sure that
154
+ // all the props are applied to the component.
155
+ // We use these finalProps as source of truth for the component.
156
+ auto finalProps = mergeDynamicProps(
157
+ (folly::dynamic)rawProps, // source
158
+ *family.nativeProps_DEPRECATED, // patch
159
+ NullValueStrategy::Override);
160
+
161
+ // 3. Clone the props by using finalProps.
162
+ props = componentDescriptor.cloneProps(
163
+ propsParserContext, shadowNode.getProps(), RawProps(finalProps));
164
+ } else {
165
+ props = componentDescriptor.cloneProps(
166
+ propsParserContext, shadowNode.getProps(), std::move(rawProps));
167
+ }
168
+ }
169
+
170
+ auto clonedShadowNode = componentDescriptor.cloneShadowNode(
171
+ shadowNode,
172
+ {
173
+ .props = props,
174
+ .children = children,
175
+ .runtimeShadowNodeReference = false,
176
+ });
177
+
178
+ return clonedShadowNode;
179
+ }
180
+
181
+ void UIManager::appendChild(
182
+ const std::shared_ptr<const ShadowNode>& parentShadowNode,
183
+ const std::shared_ptr<const ShadowNode>& childShadowNode) const {
184
+ TraceSection s("UIManager::appendChild");
185
+
186
+ auto& componentDescriptor = parentShadowNode->getComponentDescriptor();
187
+ componentDescriptor.appendChild(parentShadowNode, childShadowNode);
188
+ }
189
+
190
+ void UIManager::completeSurface(
191
+ SurfaceId surfaceId,
192
+ const ShadowNode::UnsharedListOfShared& rootChildren,
193
+ ShadowTree::CommitOptions commitOptions) {
194
+ TraceSection s("UIManager::completeSurface", "surfaceId", surfaceId);
195
+
196
+ shadowTreeRegistry_.visit(surfaceId, [&](const ShadowTree& shadowTree) {
197
+ auto result = shadowTree.commit(
198
+ [&](const RootShadowNode& oldRootShadowNode) {
199
+ return std::make_shared<RootShadowNode>(
200
+ oldRootShadowNode,
201
+ ShadowNodeFragment{
202
+ .props = ShadowNodeFragment::propsPlaceholder(),
203
+ .children = rootChildren,
204
+ });
205
+ },
206
+ commitOptions);
207
+
208
+ if (result == ShadowTree::CommitStatus::Succeeded) {
209
+ // It's safe to update the visible revision of the shadow tree immediately
210
+ // after we commit a specific one.
211
+ lazyShadowTreeRevisionConsistencyManager_->updateCurrentRevision(
212
+ surfaceId, shadowTree.getCurrentRevision().rootShadowNode);
213
+ }
214
+ });
215
+ }
216
+
217
+ void UIManager::setIsJSResponder(
218
+ const std::shared_ptr<const ShadowNode>& shadowNode,
219
+ bool isJSResponder,
220
+ bool blockNativeResponder) const {
221
+ if (delegate_ != nullptr) {
222
+ delegate_->uiManagerDidSetIsJSResponder(
223
+ shadowNode, isJSResponder, blockNativeResponder);
224
+ }
225
+ }
226
+
227
+ void UIManager::startSurface(
228
+ ShadowTree::Unique&& shadowTree,
229
+ const std::string& moduleName,
230
+ const folly::dynamic& props,
231
+ DisplayMode displayMode) const noexcept {
232
+ TraceSection s("UIManager::startSurface");
233
+
234
+ auto surfaceId = shadowTree->getSurfaceId();
235
+ shadowTreeRegistry_.add(std::move(shadowTree));
236
+
237
+ shadowTreeRegistry_.visit(
238
+ surfaceId, [delegate = delegate_](const ShadowTree& shadowTree) {
239
+ if (delegate != nullptr) {
240
+ delegate->uiManagerDidStartSurface(shadowTree);
241
+ }
242
+ });
243
+
244
+ runtimeExecutor_([=](jsi::Runtime& runtime) {
245
+ TraceSection s("UIManager::startSurface::onRuntime");
246
+ AppRegistryBinding::startSurface(
247
+ runtime, surfaceId, moduleName, props, displayMode);
248
+ });
249
+ }
250
+
251
+ void UIManager::startEmptySurface(
252
+ ShadowTree::Unique&& shadowTree) const noexcept {
253
+ TraceSection s("UIManager::startEmptySurface");
254
+ shadowTreeRegistry_.add(std::move(shadowTree));
255
+ }
256
+
257
+ void UIManager::setSurfaceProps(
258
+ SurfaceId surfaceId,
259
+ const std::string& moduleName,
260
+ const folly::dynamic& props,
261
+ DisplayMode displayMode) const noexcept {
262
+ TraceSection s("UIManager::setSurfaceProps");
263
+
264
+ runtimeExecutor_([=](jsi::Runtime& runtime) {
265
+ AppRegistryBinding::setSurfaceProps(
266
+ runtime, surfaceId, moduleName, props, displayMode);
267
+ });
268
+ }
269
+
270
+ ShadowTree::Unique UIManager::stopSurface(SurfaceId surfaceId) const {
271
+ TraceSection s("UIManager::stopSurface");
272
+
273
+ // Stop any ongoing animations.
274
+ stopSurfaceForAnimationDelegate(surfaceId);
275
+
276
+ // Waiting for all concurrent commits to be finished and unregistering the
277
+ // `ShadowTree`.
278
+ auto shadowTree = getShadowTreeRegistry().remove(surfaceId);
279
+ if (shadowTree) {
280
+ // We execute JavaScript/React part of the process at the very end to
281
+ // minimize any visible side-effects of stopping the Surface. Any possible
282
+ // commits from the JavaScript side will not be able to reference a
283
+ // `ShadowTree` and will fail silently.
284
+ runtimeExecutor_([=](jsi::Runtime& runtime) {
285
+ AppRegistryBinding::stopSurface(runtime, surfaceId);
286
+ });
287
+
288
+ if (leakChecker_) {
289
+ leakChecker_->stopSurface(surfaceId);
290
+ }
291
+ }
292
+ return shadowTree;
293
+ }
294
+
295
+ std::shared_ptr<const ShadowNode> UIManager::getNewestCloneOfShadowNode(
296
+ const ShadowNode& shadowNode) const {
297
+ auto ancestorShadowNode = std::shared_ptr<const ShadowNode>{};
298
+ shadowTreeRegistry_.visit(
299
+ shadowNode.getSurfaceId(), [&](const ShadowTree& shadowTree) {
300
+ ancestorShadowNode = shadowTree.getCurrentRevision().rootShadowNode;
301
+ });
302
+ return getShadowNodeInSubtree(shadowNode, ancestorShadowNode);
303
+ }
304
+
305
+ std::shared_ptr<const ShadowNode> UIManager::getShadowNodeInSubtree(
306
+ const ShadowNode& shadowNode,
307
+ const std::shared_ptr<const ShadowNode>& ancestorShadowNode) const {
308
+ if (!ancestorShadowNode) {
309
+ return nullptr;
310
+ }
311
+
312
+ // If the given shadow node is of the same family as the root shadow node,
313
+ // return the latest root shadow node
314
+ if (ShadowNode::sameFamily(*ancestorShadowNode, shadowNode)) {
315
+ return ancestorShadowNode;
316
+ }
317
+
318
+ auto ancestors = shadowNode.getFamily().getAncestors(*ancestorShadowNode);
319
+
320
+ if (ancestors.empty()) {
321
+ return nullptr;
322
+ }
323
+
324
+ auto pair = ancestors.rbegin();
325
+ return pair->first.get().getChildren().at(pair->second);
326
+ }
327
+
328
+ ShadowTreeRevisionConsistencyManager*
329
+ UIManager::getShadowTreeRevisionConsistencyManager() {
330
+ return lazyShadowTreeRevisionConsistencyManager_.get();
331
+ }
332
+
333
+ ShadowTreeRevisionProvider* UIManager::getShadowTreeRevisionProvider() {
334
+ return lazyShadowTreeRevisionConsistencyManager_.get();
335
+ }
336
+
337
+ std::shared_ptr<const ShadowNode> UIManager::findNodeAtPoint(
338
+ const std::shared_ptr<const ShadowNode>& node,
339
+ Point point) const {
340
+ return LayoutableShadowNode::findNodeAtPoint(
341
+ getNewestCloneOfShadowNode(*node), point);
342
+ }
343
+
344
+ LayoutMetrics UIManager::getRelativeLayoutMetrics(
345
+ const ShadowNode& shadowNode,
346
+ const ShadowNode* ancestorShadowNode,
347
+ LayoutableShadowNode::LayoutInspectingPolicy policy) const {
348
+ TraceSection s("UIManager::getRelativeLayoutMetrics");
349
+
350
+ // We might store here an owning pointer to `ancestorShadowNode` to ensure
351
+ // that the node is not deallocated during method execution lifetime.
352
+ auto owningAncestorShadowNode = std::shared_ptr<const ShadowNode>{};
353
+
354
+ if (ancestorShadowNode == nullptr) {
355
+ shadowTreeRegistry_.visit(
356
+ shadowNode.getSurfaceId(), [&](const ShadowTree& shadowTree) {
357
+ owningAncestorShadowNode =
358
+ shadowTree.getCurrentRevision().rootShadowNode;
359
+ ancestorShadowNode = owningAncestorShadowNode.get();
360
+ });
361
+ } else {
362
+ // It is possible for JavaScript (or other callers) to have a reference
363
+ // to a previous version of ShadowNodes, but we enforce that
364
+ // metrics are only calculated on most recently committed versions.
365
+ owningAncestorShadowNode = getNewestCloneOfShadowNode(*ancestorShadowNode);
366
+ ancestorShadowNode = owningAncestorShadowNode.get();
367
+ }
368
+
369
+ auto layoutableAncestorShadowNode =
370
+ dynamic_cast<const LayoutableShadowNode*>(ancestorShadowNode);
371
+
372
+ if (layoutableAncestorShadowNode == nullptr) {
373
+ return EmptyLayoutMetrics;
374
+ }
375
+
376
+ return LayoutableShadowNode::computeRelativeLayoutMetrics(
377
+ shadowNode.getFamily(), *layoutableAncestorShadowNode, policy);
378
+ }
379
+
380
+ void UIManager::updateState(const StateUpdate& stateUpdate) const {
381
+ TraceSection s(
382
+ "UIManager::updateState",
383
+ "componentName",
384
+ stateUpdate.family->getComponentName());
385
+ auto& callback = stateUpdate.callback;
386
+ auto& family = stateUpdate.family;
387
+ auto& componentDescriptor = family->getComponentDescriptor();
388
+
389
+ shadowTreeRegistry_.visit(
390
+ family->getSurfaceId(), [&](const ShadowTree& shadowTree) {
391
+ shadowTree.commit(
392
+ [&](const RootShadowNode& oldRootShadowNode) {
393
+ auto isValid = true;
394
+
395
+ auto rootNode = oldRootShadowNode.cloneTree(
396
+ *family, [&](const ShadowNode& oldShadowNode) {
397
+ auto newData =
398
+ callback(oldShadowNode.getState()->getDataPointer());
399
+
400
+ if (!newData) {
401
+ isValid = false;
402
+ // Just return something, we will discard it anyway.
403
+ return oldShadowNode.clone({});
404
+ }
405
+
406
+ auto newState =
407
+ componentDescriptor.createState(*family, newData);
408
+
409
+ return oldShadowNode.clone(
410
+ {.props = ShadowNodeFragment::propsPlaceholder(),
411
+ .children = ShadowNodeFragment::childrenPlaceholder(),
412
+ .state = newState});
413
+ });
414
+
415
+ return isValid
416
+ ? std::static_pointer_cast<RootShadowNode>(rootNode)
417
+ : nullptr;
418
+ },
419
+ {/* default commit options */});
420
+ });
421
+ }
422
+
423
+ void UIManager::dispatchCommand(
424
+ const std::shared_ptr<const ShadowNode>& shadowNode,
425
+ const std::string& commandName,
426
+ const folly::dynamic& args) const {
427
+ if (delegate_ != nullptr) {
428
+ delegate_->uiManagerDidDispatchCommand(shadowNode, commandName, args);
429
+ }
430
+ }
431
+
432
+ void UIManager::setNativeProps_DEPRECATED(
433
+ const std::shared_ptr<const ShadowNode>& shadowNode,
434
+ RawProps rawProps) const {
435
+ auto& family = shadowNode->getFamily();
436
+ if (family.nativeProps_DEPRECATED) {
437
+ // Values in `rawProps` patch (take precedence over)
438
+ // `nativeProps_DEPRECATED`. For example, if both `nativeProps_DEPRECATED`
439
+ // and `rawProps` contain key 'A'. Value from `rawProps` overrides what was
440
+ // previously in `nativeProps_DEPRECATED`.
441
+ family.nativeProps_DEPRECATED =
442
+ std::make_unique<folly::dynamic>(mergeDynamicProps(
443
+ *family.nativeProps_DEPRECATED,
444
+ (folly::dynamic)rawProps,
445
+ NullValueStrategy::Override));
446
+ } else {
447
+ family.nativeProps_DEPRECATED =
448
+ std::make_unique<folly::dynamic>((folly::dynamic)rawProps);
449
+ }
450
+
451
+ shadowTreeRegistry_.visit(
452
+ family.getSurfaceId(), [&](const ShadowTree& shadowTree) {
453
+ // The lambda passed to `commit` may be executed multiple times.
454
+ // We need to create fresh copy of the `RawProps` object each time.
455
+ auto ancestorShadowNode =
456
+ shadowTree.getCurrentRevision().rootShadowNode;
457
+ shadowTree.commit(
458
+ [&](const RootShadowNode& oldRootShadowNode) {
459
+ auto rootNode = oldRootShadowNode.cloneTree(
460
+ family, [&](const ShadowNode& oldShadowNode) {
461
+ auto& componentDescriptor =
462
+ componentDescriptorRegistry_->at(
463
+ shadowNode->getComponentHandle());
464
+ PropsParserContext propsParserContext{
465
+ family.getSurfaceId(), *contextContainer_};
466
+ auto props = componentDescriptor.cloneProps(
467
+ propsParserContext,
468
+ getShadowNodeInSubtree(*shadowNode, ancestorShadowNode)
469
+ ->getProps(),
470
+ RawProps(rawProps));
471
+
472
+ return oldShadowNode.clone({/* .props = */ .props = props});
473
+ });
474
+
475
+ return std::static_pointer_cast<RootShadowNode>(rootNode);
476
+ },
477
+ {/* default commit options */});
478
+ });
479
+ }
480
+
481
+ void UIManager::sendAccessibilityEvent(
482
+ const std::shared_ptr<const ShadowNode>& shadowNode,
483
+ const std::string& eventType) {
484
+ if (delegate_ != nullptr) {
485
+ delegate_->uiManagerDidSendAccessibilityEvent(shadowNode, eventType);
486
+ }
487
+ }
488
+
489
+ void UIManager::configureNextLayoutAnimation(
490
+ jsi::Runtime& runtime,
491
+ const RawValue& config,
492
+ const jsi::Value& successCallback,
493
+ const jsi::Value& failureCallback) const {
494
+ if (animationDelegate_ != nullptr) {
495
+ animationDelegate_->uiManagerDidConfigureNextLayoutAnimation(
496
+ runtime,
497
+ config,
498
+ std::move(successCallback),
499
+ std::move(failureCallback));
500
+ }
501
+ }
502
+
503
+ static std::shared_ptr<const ShadowNode> findShadowNodeByTagRecursively(
504
+ std::shared_ptr<const ShadowNode> parentShadowNode,
505
+ Tag tag) {
506
+ if (parentShadowNode->getTag() == tag) {
507
+ return parentShadowNode;
508
+ }
509
+
510
+ for (const std::shared_ptr<const ShadowNode>& shadowNode :
511
+ parentShadowNode->getChildren()) {
512
+ auto result = findShadowNodeByTagRecursively(shadowNode, tag);
513
+ if (result) {
514
+ return result;
515
+ }
516
+ }
517
+
518
+ return nullptr;
519
+ }
520
+
521
+ std::shared_ptr<const ShadowNode> UIManager::findShadowNodeByTag_DEPRECATED(
522
+ Tag tag) const {
523
+ auto shadowNode = std::shared_ptr<const ShadowNode>{};
524
+
525
+ shadowTreeRegistry_.enumerate([&](const ShadowTree& shadowTree, bool& stop) {
526
+ const RootShadowNode* rootShadowNode = nullptr;
527
+ // The public interface of `ShadowTree` discourages accessing a stored
528
+ // pointer to a root node because of the possible data race.
529
+ // To work around this, we ask for a commit and immediately cancel it
530
+ // returning `nullptr` instead of a new shadow tree.
531
+ // We don't want to add a way to access a stored pointer to a root node
532
+ // because this `findShadowNodeByTag` is deprecated. It is only added
533
+ // to make migration to the new architecture easier.
534
+ shadowTree.tryCommit(
535
+ [&](const RootShadowNode& oldRootShadowNode) {
536
+ rootShadowNode = &oldRootShadowNode;
537
+ return nullptr;
538
+ },
539
+ {/* default commit options */});
540
+
541
+ if (rootShadowNode != nullptr) {
542
+ const auto& children = rootShadowNode->getChildren();
543
+ if (!children.empty()) {
544
+ const auto& child = children.front();
545
+ shadowNode = findShadowNodeByTagRecursively(child, tag);
546
+ if (shadowNode) {
547
+ stop = true;
548
+ }
549
+ }
550
+ }
551
+ });
552
+
553
+ return shadowNode;
554
+ }
555
+
556
+ void UIManager::setComponentDescriptorRegistry(
557
+ const SharedComponentDescriptorRegistry& componentDescriptorRegistry) {
558
+ componentDescriptorRegistry_ = componentDescriptorRegistry;
559
+ }
560
+
561
+ void UIManager::setDelegate(UIManagerDelegate* delegate) {
562
+ delegate_ = delegate;
563
+ }
564
+
565
+ UIManagerDelegate* UIManager::getDelegate() {
566
+ return delegate_;
567
+ }
568
+
569
+ void UIManager::visitBinding(
570
+ const std::function<void(const UIManagerBinding& uiManagerBinding)>&
571
+ callback,
572
+ jsi::Runtime& runtime) const {
573
+ auto uiManagerBinding = UIManagerBinding::getBinding(runtime);
574
+ if (uiManagerBinding) {
575
+ callback(*uiManagerBinding);
576
+ }
577
+ }
578
+
579
+ const ShadowTreeRegistry& UIManager::getShadowTreeRegistry() const {
580
+ return shadowTreeRegistry_;
581
+ }
582
+
583
+ void UIManager::registerCommitHook(UIManagerCommitHook& commitHook) {
584
+ std::unique_lock lock(commitHookMutex_);
585
+ react_native_assert(
586
+ std::find(commitHooks_.begin(), commitHooks_.end(), &commitHook) ==
587
+ commitHooks_.end());
588
+ commitHook.commitHookWasRegistered(*this);
589
+ commitHooks_.push_back(&commitHook);
590
+ }
591
+
592
+ void UIManager::unregisterCommitHook(UIManagerCommitHook& commitHook) {
593
+ std::unique_lock lock(commitHookMutex_);
594
+ auto iterator =
595
+ std::find(commitHooks_.begin(), commitHooks_.end(), &commitHook);
596
+ react_native_assert(iterator != commitHooks_.end());
597
+ commitHooks_.erase(iterator);
598
+ commitHook.commitHookWasUnregistered(*this);
599
+ }
600
+
601
+ void UIManager::registerMountHook(UIManagerMountHook& mountHook) {
602
+ std::unique_lock lock(mountHookMutex_);
603
+ react_native_assert(
604
+ std::find(mountHooks_.begin(), mountHooks_.end(), &mountHook) ==
605
+ mountHooks_.end());
606
+ mountHooks_.push_back(&mountHook);
607
+ }
608
+
609
+ void UIManager::unregisterMountHook(UIManagerMountHook& mountHook) {
610
+ std::unique_lock lock(mountHookMutex_);
611
+ auto iterator = std::find(mountHooks_.begin(), mountHooks_.end(), &mountHook);
612
+ react_native_assert(iterator != mountHooks_.end());
613
+ mountHooks_.erase(iterator);
614
+ }
615
+
616
+ #pragma mark - ShadowTreeDelegate
617
+
618
+ RootShadowNode::Unshared UIManager::shadowTreeWillCommit(
619
+ const ShadowTree& shadowTree,
620
+ const RootShadowNode::Shared& oldRootShadowNode,
621
+ const RootShadowNode::Unshared& newRootShadowNode,
622
+ const ShadowTree::CommitOptions& commitOptions) const {
623
+ TraceSection s("UIManager::shadowTreeWillCommit");
624
+
625
+ std::shared_lock lock(commitHookMutex_);
626
+
627
+ auto resultRootShadowNode = newRootShadowNode;
628
+ for (auto* commitHook : commitHooks_) {
629
+ resultRootShadowNode = commitHook->shadowTreeWillCommit(
630
+ shadowTree, oldRootShadowNode, resultRootShadowNode, commitOptions);
631
+ }
632
+
633
+ return resultRootShadowNode;
634
+ }
635
+
636
+ void UIManager::shadowTreeDidFinishTransaction(
637
+ std::shared_ptr<const MountingCoordinator> mountingCoordinator,
638
+ bool mountSynchronously) const {
639
+ TraceSection s("UIManager::shadowTreeDidFinishTransaction");
640
+
641
+ if (delegate_ != nullptr) {
642
+ delegate_->uiManagerDidFinishTransaction(
643
+ std::move(mountingCoordinator), mountSynchronously);
644
+ }
645
+ }
646
+
647
+ void UIManager::reportMount(SurfaceId surfaceId) const {
648
+ TraceSection s("UIManager::reportMount");
649
+
650
+ auto time = HighResTimeStamp::now();
651
+
652
+ auto rootShadowNode = RootShadowNode::Shared{};
653
+ shadowTreeRegistry_.visit(surfaceId, [&](const ShadowTree& shadowTree) {
654
+ rootShadowNode =
655
+ shadowTree.getMountingCoordinator()->getBaseRevision().rootShadowNode;
656
+ });
657
+
658
+ {
659
+ std::shared_lock lock(mountHookMutex_);
660
+
661
+ for (auto* mountHook : mountHooks_) {
662
+ if (rootShadowNode) {
663
+ mountHook->shadowTreeDidMount(rootShadowNode, time);
664
+ } else {
665
+ mountHook->shadowTreeDidUnmount(surfaceId, time);
666
+ }
667
+ }
668
+ }
669
+ }
670
+
671
+ #pragma mark - UIManagerAnimationDelegate
672
+
673
+ void UIManager::setAnimationDelegate(UIManagerAnimationDelegate* delegate) {
674
+ animationDelegate_ = delegate;
675
+ }
676
+
677
+ void UIManager::stopSurfaceForAnimationDelegate(SurfaceId surfaceId) const {
678
+ if (animationDelegate_ != nullptr) {
679
+ animationDelegate_->stopSurface(surfaceId);
680
+ }
681
+ }
682
+
683
+ void UIManager::setNativeAnimatedDelegate(
684
+ std::weak_ptr<UIManagerNativeAnimatedDelegate> delegate) {
685
+ nativeAnimatedDelegate_ = delegate;
686
+ }
687
+
688
+ void UIManager::unstable_setAnimationBackend(
689
+ std::weak_ptr<UIManagerAnimationBackend> animationBackend) {
690
+ animationBackend_ = animationBackend;
691
+ }
692
+
693
+ std::weak_ptr<UIManagerAnimationBackend>
694
+ UIManager::unstable_getAnimationBackend() {
695
+ return animationBackend_;
696
+ }
697
+
698
+ void UIManager::animationTick() const {
699
+ if (animationDelegate_ != nullptr &&
700
+ animationDelegate_->shouldAnimateFrame()) {
701
+ shadowTreeRegistry_.enumerate([](const ShadowTree& shadowTree, bool&) {
702
+ shadowTree.notifyDelegatesOfUpdates();
703
+ });
704
+ }
705
+
706
+ if (auto nativeAnimatedDelegate = nativeAnimatedDelegate_.lock()) {
707
+ nativeAnimatedDelegate->runAnimationFrame();
708
+ }
709
+ }
710
+
711
+ void UIManager::synchronouslyUpdateViewOnUIThread(
712
+ Tag tag,
713
+ const folly::dynamic& props) {
714
+ if (delegate_ != nullptr) {
715
+ delegate_->uiManagerShouldSynchronouslyUpdateViewOnUIThread(tag, props);
716
+ }
717
+ }
718
+
719
+ #pragma mark - Add & Remove event listener
720
+
721
+ void UIManager::addEventListener(
722
+ std::shared_ptr<const EventListener> listener) {
723
+ if (delegate_ != nullptr) {
724
+ delegate_->uiManagerShouldAddEventListener(listener);
725
+ }
726
+ }
727
+
728
+ void UIManager::removeEventListener(
729
+ const std::shared_ptr<const EventListener>& listener) {
730
+ if (delegate_ != nullptr) {
731
+ delegate_->uiManagerShouldRemoveEventListener(listener);
732
+ }
733
+ }
734
+
735
+ void UIManager::setOnSurfaceStartCallback(
736
+ UIManagerDelegate::OnSurfaceStartCallback&& callback) {
737
+ if (delegate_ != nullptr) {
738
+ delegate_->uiManagerShouldSetOnSurfaceStartCallback(std::move(callback));
739
+ }
740
+ }
741
+
742
+ } // namespace facebook::react
743
+
744
+ #if _MSC_VER
745
+ #pragma warning(pop)
746
+ #endif