@office-iss/react-native-win32 0.72.8 → 0.73.0-preview.2

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 (277) hide show
  1. package/.flowconfig +15 -5
  2. package/CHANGELOG.json +530 -101
  3. package/CHANGELOG.md +213 -56
  4. package/IntegrationTests/PromiseTest.js +1 -0
  5. package/IntegrationTests/websocket_integration_test_server.js +1 -1
  6. package/Libraries/Animated/Animated.js +1 -1
  7. package/Libraries/Animated/AnimatedImplementation.js +1 -1
  8. package/Libraries/Animated/NativeAnimatedHelper.js +14 -10
  9. package/Libraries/Animated/NativeAnimatedHelper.win32.js +16 -12
  10. package/Libraries/Animated/NativeAnimatedModule.js +6 -2
  11. package/Libraries/Animated/NativeAnimatedTurboModule.js +7 -4
  12. package/Libraries/Animated/animations/Animation.js +57 -3
  13. package/Libraries/Animated/animations/DecayAnimation.js +9 -0
  14. package/Libraries/Animated/animations/SpringAnimation.js +8 -0
  15. package/Libraries/Animated/animations/TimingAnimation.js +8 -0
  16. package/Libraries/Animated/components/AnimatedFlatList.js +2 -1
  17. package/Libraries/Animated/components/AnimatedScrollView.js +2 -0
  18. package/Libraries/Animated/components/AnimatedSectionList.js +2 -1
  19. package/Libraries/Animated/createAnimatedComponent.js +1 -0
  20. package/Libraries/Animated/nodes/AnimatedColor.js +1 -1
  21. package/Libraries/Animated/nodes/AnimatedObject.js +146 -0
  22. package/Libraries/Animated/nodes/AnimatedProps.js +19 -7
  23. package/Libraries/Animated/nodes/AnimatedStyle.js +29 -55
  24. package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -17
  25. package/Libraries/Animated/shouldUseTurboAnimatedModule.js +17 -0
  26. package/Libraries/Animated/useAnimatedProps.js +9 -10
  27. package/Libraries/AppState/AppState.d.ts +1 -1
  28. package/Libraries/AppState/NativeAppState.js +8 -4
  29. package/Libraries/BatchedBridge/MessageQueue.js +45 -36
  30. package/Libraries/Blob/Blob.js +6 -2
  31. package/Libraries/Blob/BlobManager.js +9 -10
  32. package/Libraries/Blob/BlobRegistry.js +14 -9
  33. package/Libraries/Blob/File.js +1 -1
  34. package/Libraries/Blob/FileReader.js +1 -2
  35. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +1 -5
  36. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +7 -48
  37. package/Libraries/Components/Button/ButtonWin32.Props.d.ts +1 -1
  38. package/Libraries/Components/Button/ButtonWin32.Props.js.map +1 -1
  39. package/Libraries/Components/Button/ButtonWin32.d.ts +1 -1
  40. package/Libraries/Components/Button/ButtonWin32.js +1 -4
  41. package/Libraries/Components/Button/ButtonWin32.js.map +1 -1
  42. package/Libraries/Components/Clipboard/Clipboard.d.ts +4 -4
  43. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +3 -1
  44. package/Libraries/Components/EnterString.win32.d.ts +1 -1
  45. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +26 -6
  46. package/Libraries/Components/Pressable/Pressable.js +3 -2
  47. package/Libraries/Components/Pressable/Pressable.win32.js +4 -3
  48. package/Libraries/Components/Pressable/useAndroidRippleForView.js +1 -1
  49. package/Libraries/Components/SafeAreaView/SafeAreaView.js +7 -7
  50. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +7 -8
  51. package/Libraries/Components/ScrollView/ScrollView.js +3 -1
  52. package/Libraries/Components/ScrollView/ScrollView.win32.js +3 -1
  53. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +39 -46
  54. package/Libraries/Components/Switch/Switch.js +1 -0
  55. package/Libraries/Components/Text/TextWin32.d.ts +1 -1
  56. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  57. package/Libraries/Components/TextInput/TextInput.d.ts +49 -7
  58. package/Libraries/Components/TextInput/TextInput.flow.js +43 -10
  59. package/Libraries/Components/TextInput/TextInput.js +62 -10
  60. package/Libraries/Components/TextInput/TextInput.win32.js +953 -206
  61. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +23 -0
  62. package/Libraries/Components/ToastAndroid/{ToastAndroid.ios.js → ToastAndroid.js} +9 -1
  63. package/Libraries/Components/ToastAndroid/ToastAndroid.win32.js +9 -1
  64. package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js +2 -2
  65. package/Libraries/Components/Touchable/Tests/TouchableWin32Test.js.map +1 -1
  66. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  67. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  68. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  69. package/Libraries/Components/Touchable/TouchableOpacity.js +4 -1
  70. package/Libraries/Components/Touchable/TouchableWin32.d.ts +1 -1
  71. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  72. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +1 -0
  73. package/Libraries/Components/TraceUpdateOverlay/TraceUpdateOverlay.js +16 -6
  74. package/Libraries/Components/View/ReactNativeStyleAttributes.js +9 -0
  75. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  76. package/Libraries/Components/View/ReactNativeViewAttributes.win32.js +1 -0
  77. package/Libraries/Components/View/View.js +46 -32
  78. package/Libraries/Components/View/View.win32.js +37 -6
  79. package/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
  80. package/Libraries/Components/View/ViewNativeComponent.js +1 -0
  81. package/Libraries/Components/View/ViewPropTypes.js +18 -3
  82. package/Libraries/Components/View/ViewPropTypes.win32.js +30 -4
  83. package/Libraries/Components/View/ViewWin32.js +3 -2
  84. package/Libraries/Core/Devtools/loadBundleFromServer.js +152 -0
  85. package/Libraries/Core/Devtools/symbolicateStackTrace.js +2 -1
  86. package/Libraries/Core/ExceptionsManager.js +16 -7
  87. package/Libraries/Core/ExtendedError.js +12 -0
  88. package/Libraries/Core/ReactNativeVersion.js +3 -3
  89. package/Libraries/Core/ReactNativeVersionCheck.js +0 -2
  90. package/Libraries/Core/ReactNativeVersionCheck.win32.js +0 -2
  91. package/Libraries/Core/__mocks__/NativeExceptionsManager.js +20 -0
  92. package/Libraries/Core/setUpDeveloperTools.js +5 -1
  93. package/Libraries/Core/setUpIntersectionObserver.js +16 -0
  94. package/Libraries/{Components/ProgressBarAndroid/ProgressBarAndroid.ios.js → Core/setUpMutationObserver.js} +6 -2
  95. package/Libraries/Core/setUpPerformance.js +6 -13
  96. package/Libraries/Core/setUpPerformanceObserver.js +16 -0
  97. package/Libraries/Core/setUpRegeneratorRuntime.js +4 -2
  98. package/Libraries/DOM/Nodes/ReactNativeElement.js +135 -18
  99. package/Libraries/DOM/Nodes/ReadOnlyCharacterData.js +72 -0
  100. package/Libraries/DOM/Nodes/ReadOnlyElement.js +209 -21
  101. package/Libraries/DOM/Nodes/ReadOnlyNode.js +206 -17
  102. package/Libraries/DOM/Nodes/ReadOnlyText.js +30 -0
  103. package/Libraries/DOM/Nodes/Utilities/Traversal.js +54 -0
  104. package/Libraries/EventEmitter/NativeEventEmitter.d.ts +0 -6
  105. package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +15 -4
  106. package/Libraries/Image/Image.android.js +8 -2
  107. package/Libraries/Image/Image.d.ts +1 -1
  108. package/Libraries/Image/Image.ios.js +4 -1
  109. package/Libraries/Image/Image.win32.js +6 -3
  110. package/Libraries/Image/ImageBackground.js +3 -0
  111. package/Libraries/Image/resolveAssetSource.win32.js +1 -1
  112. package/Libraries/Inspector/DevtoolsOverlay.js +6 -3
  113. package/Libraries/Inspector/NetworkOverlay.js +2 -2
  114. package/Libraries/Interaction/JSEventLoopWatchdog.js +1 -5
  115. package/Libraries/Interaction/PanResponder.js +1 -4
  116. package/Libraries/IntersectionObserver/IntersectionObserver.js +252 -0
  117. package/Libraries/IntersectionObserver/IntersectionObserverEntry.js +140 -0
  118. package/Libraries/IntersectionObserver/IntersectionObserverManager.js +221 -0
  119. package/Libraries/IntersectionObserver/NativeIntersectionObserver.js +41 -0
  120. package/Libraries/IntersectionObserver/__mocks__/NativeIntersectionObserver.js +162 -0
  121. package/Libraries/LayoutAnimation/LayoutAnimation.js +1 -1
  122. package/Libraries/Lists/FlatList.d.ts +2 -1
  123. package/Libraries/Lists/FlatList.js +15 -5
  124. package/Libraries/Lists/SectionList.js +4 -0
  125. package/Libraries/LogBox/Data/LogBoxData.js +2 -1
  126. package/Libraries/LogBox/Data/LogBoxLog.js +4 -1
  127. package/Libraries/LogBox/Data/LogBoxSymbolication.js +5 -2
  128. package/Libraries/LogBox/Data/parseLogBoxLog.js +57 -20
  129. package/Libraries/LogBox/UI/AnsiHighlight.js +1 -1
  130. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +24 -31
  131. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +1 -1
  132. package/Libraries/LogBox/UI/LogBoxMessage.js +4 -7
  133. package/Libraries/MutationObserver/MutationObserver.js +184 -0
  134. package/Libraries/MutationObserver/MutationObserverManager.js +218 -0
  135. package/Libraries/MutationObserver/MutationRecord.js +82 -0
  136. package/Libraries/MutationObserver/NativeMutationObserver.js +58 -0
  137. package/Libraries/MutationObserver/__mocks__/NativeMutationObserver.js +327 -0
  138. package/Libraries/NativeComponent/BaseViewConfig.android.js +18 -3
  139. package/Libraries/NativeComponent/BaseViewConfig.ios.js +33 -0
  140. package/Libraries/NativeComponent/BaseViewConfig.win32.js +33 -0
  141. package/Libraries/NativeComponent/NativeComponentRegistry.js +13 -9
  142. package/Libraries/NativeModules/specs/NativeSourceCode.js +6 -6
  143. package/Libraries/Network/RCTNetworking.android.js +2 -1
  144. package/Libraries/Network/XMLHttpRequest.js +1 -1
  145. package/Libraries/NewAppScreen/components/DebugInstructions.js +4 -4
  146. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +9 -2
  147. package/Libraries/Performance/QuickPerformanceLogger.js +1 -1
  148. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
  149. package/Libraries/PermissionsAndroid/PermissionsAndroid.d.ts +1 -0
  150. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -1
  151. package/Libraries/Pressability/Pressability.js +28 -3
  152. package/Libraries/Pressability/Pressability.win32.js +30 -5
  153. package/Libraries/ReactNative/AppContainer.js +2 -3
  154. package/Libraries/ReactNative/AppRegistry.d.ts +0 -5
  155. package/Libraries/ReactNative/AppRegistry.js +66 -53
  156. package/Libraries/ReactNative/BridgelessUIManager.js +38 -9
  157. package/Libraries/ReactNative/FabricUIManager.js +143 -34
  158. package/Libraries/ReactNative/I18nManager.js +5 -11
  159. package/Libraries/ReactNative/NativeI18nManager.js +7 -5
  160. package/Libraries/ReactNative/PaperUIManager.win32.js +2 -2
  161. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +151 -0
  162. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +81 -0
  163. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload.js +492 -0
  164. package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +32 -0
  165. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +19 -3
  166. package/Libraries/ReactNative/UIManager.js +8 -0
  167. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +648 -0
  168. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +38 -2
  169. package/Libraries/Renderer/implementations/ReactFabric-dev.js +27 -27
  170. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3 -3
  171. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3 -3
  172. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +27 -27
  173. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3 -3
  174. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3 -3
  175. package/Libraries/Renderer/shims/ReactFabric.js +5 -6
  176. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -3
  177. package/Libraries/Renderer/shims/ReactNative.js +2 -3
  178. package/Libraries/Renderer/shims/ReactNativeTypes.js +35 -17
  179. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -3
  180. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -3
  181. package/Libraries/Settings/{Settings.android.js → Settings.js} +4 -4
  182. package/Libraries/Share/Share.d.ts +3 -9
  183. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +9 -4
  184. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +28 -13
  185. package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +14 -4
  186. package/Libraries/StyleSheet/PlatformColorValueTypesIOS.ios.js +1 -1
  187. package/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
  188. package/Libraries/StyleSheet/StyleSheet.d.ts +10 -1
  189. package/Libraries/StyleSheet/StyleSheet.js +3 -0
  190. package/Libraries/StyleSheet/StyleSheet.win32.js +3 -0
  191. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +31 -17
  192. package/Libraries/StyleSheet/StyleSheetTypes.js +90 -6
  193. package/Libraries/StyleSheet/flattenStyle.js +4 -0
  194. package/Libraries/StyleSheet/private/_TransformStyle.js +16 -2
  195. package/Libraries/StyleSheet/processColor.js +1 -2
  196. package/Libraries/StyleSheet/processTransformOrigin.js +136 -0
  197. package/Libraries/StyleSheet/splitLayoutProps.js +1 -0
  198. package/Libraries/Text/Text.d.ts +5 -5
  199. package/Libraries/Text/Text.js +17 -10
  200. package/Libraries/Text/Text.win32.js +354 -0
  201. package/Libraries/Text/TextProps.win32.js +281 -0
  202. package/Libraries/TurboModule/TurboModuleRegistry.js +47 -7
  203. package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +6 -0
  204. package/Libraries/Types/CoreEventTypes.d.ts +5 -2
  205. package/Libraries/Utilities/GlobalPerformanceLogger.js +2 -12
  206. package/Libraries/Utilities/NativeDeviceInfo.js +8 -9
  207. package/Libraries/Utilities/NativePlatformConstantsAndroid.js +23 -18
  208. package/Libraries/Utilities/NativePlatformConstantsIOS.js +16 -13
  209. package/Libraries/Utilities/NativePlatformConstantsWin.js +13 -10
  210. package/Libraries/Utilities/PerformanceLoggerContext.js +1 -1
  211. package/Libraries/Utilities/Platform.android.js +12 -8
  212. package/Libraries/Utilities/Platform.d.ts +1 -0
  213. package/Libraries/Utilities/Platform.flow.js +84 -0
  214. package/Libraries/Utilities/Platform.flow.win32.js +111 -0
  215. package/Libraries/Utilities/Platform.ios.js +12 -8
  216. package/Libraries/Utilities/Platform.win32.js +12 -8
  217. package/Libraries/Utilities/PolyfillFunctions.js +1 -1
  218. package/Libraries/Utilities/ReactNativeTestTools.js +1 -2
  219. package/Libraries/Utilities/SceneTracker.js +1 -1
  220. package/Libraries/Utilities/createPerformanceLogger.js +63 -32
  221. package/Libraries/Utilities/useColorScheme.js +7 -8
  222. package/Libraries/WebPerformance/MemoryInfo.js +1 -1
  223. package/Libraries/WebPerformance/NativePerformance.js +3 -8
  224. package/Libraries/WebPerformance/NativePerformanceObserver.js +4 -0
  225. package/Libraries/WebPerformance/Performance.js +42 -15
  226. package/Libraries/WebPerformance/PerformanceEntry.js +14 -6
  227. package/Libraries/WebPerformance/PerformanceEventTiming.js +18 -1
  228. package/Libraries/WebPerformance/ReactNativeStartupTiming.js +40 -14
  229. package/Libraries/WebPerformance/__mocks__/NativePerformance.js +4 -2
  230. package/Libraries/WebPerformance/__mocks__/NativePerformanceObserver.js +21 -3
  231. package/Libraries/promiseRejectionTrackingOptions.js +21 -9
  232. package/Libraries/vendor/emitter/EventEmitter.js +17 -17
  233. package/flow/global.js +1 -3
  234. package/flow/jest.js +5 -1
  235. package/{Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.ios.js → jest/ReactNativeInternalFeatureFlagsMock.js} +2 -1
  236. package/jest/__tests__/setup-test.js +18 -0
  237. package/jest/mockModal.js +6 -4
  238. package/jest/setup.js +61 -30
  239. package/jest.config.js +1 -1
  240. package/just-task.js +1 -0
  241. package/overrides.json +54 -60
  242. package/package.json +35 -33
  243. package/src/Libraries/Components/Button/ButtonWin32.Props.ts +1 -1
  244. package/src/Libraries/Components/Button/ButtonWin32.tsx +0 -2
  245. package/src/Libraries/Components/Touchable/Tests/TouchableWin32Test.tsx +2 -2
  246. package/src/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  247. package/src/Libraries/Components/View/ViewAccessibility.d.ts +8 -2
  248. package/src/Libraries/StyleSheet/PlatformColorValueTypesWin32.d.ts +1 -1
  249. package/types/experimental.d.ts +44 -0
  250. package/types/index.d.ts +2 -1
  251. package/types/modules/Devtools.d.ts +1 -0
  252. package/types/modules/globals.d.ts +16 -1
  253. package/IntegrationTests/BUCK +0 -32
  254. package/IntegrationTests/PropertiesUpdateTest.js +0 -29
  255. package/IntegrationTests/RCTRootViewIntegrationTestApp.js +0 -86
  256. package/IntegrationTests/ReactContentSizeUpdateTest.js +0 -89
  257. package/IntegrationTests/SizeFlexibilityUpdateTest.js +0 -106
  258. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfoWin32.js +0 -37
  259. package/Libraries/Components/TextInput/TextInput.Types.win32.d.ts +0 -51
  260. package/Libraries/Components/TextInput/TextInput.Types.win32.js +0 -3
  261. package/Libraries/Components/TextInput/TextInput.Types.win32.js.map +0 -1
  262. package/Libraries/Utilities/AcessibilityMapping.js +0 -154
  263. package/Libraries/Utilities/AcessibilityMapping.win32.js +0 -156
  264. package/Libraries/Utilities/NativeDevSplitBundleLoader.js +0 -19
  265. package/Libraries/Utilities/useColorScheme.win32.js +0 -26
  266. package/flow/use-sync-external-store.js +0 -20
  267. package/flow-typed/npm/base64-js_v1.x.x.js +0 -12
  268. package/flow-typed/npm/glob_v7.x.x.js +0 -79
  269. package/flow-typed/npm/pretty-format_v26.x.x.js +0 -49
  270. package/flow-typed/npm/promise_v8.x.x.js +0 -30
  271. package/flow-typed/npm/react-dom_v17.x.x.js +0 -139
  272. package/flow-typed/npm/react-test-renderer_v16.x.x.js +0 -79
  273. package/flow-typed/npm/stacktrace-parser_v0.1.x.js +0 -17
  274. package/flow-typed/npm/yargs_v17.x.x.js +0 -341
  275. package/src/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +0 -161
  276. package/src/Libraries/Components/TextInput/TextInput.Types.win32.ts +0 -68
  277. /package/Libraries/{Renderer/public → ReactNative/ReactFabricPublicInstance}/ReactFabricPublicInstanceUtils.js +0 -0
@@ -0,0 +1,648 @@
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
+ * @oncall react_native
10
+ */
11
+
12
+ import type {
13
+ InternalInstanceHandle,
14
+ LayoutAnimationConfig,
15
+ MeasureInWindowOnSuccessCallback,
16
+ MeasureLayoutOnSuccessCallback,
17
+ MeasureOnSuccessCallback,
18
+ Node,
19
+ } from '../../Renderer/shims/ReactNativeTypes';
20
+ import type {RootTag} from '../../Types/RootTagTypes';
21
+ import type {
22
+ NodeProps,
23
+ NodeSet,
24
+ Spec as FabricUIManager,
25
+ } from '../FabricUIManager';
26
+
27
+ export type NodeMock = {
28
+ children: NodeSet,
29
+ instanceHandle: InternalInstanceHandle,
30
+ props: NodeProps,
31
+ reactTag: number,
32
+ rootTag: RootTag,
33
+ viewName: string,
34
+ };
35
+
36
+ export function fromNode(node: Node): NodeMock {
37
+ // $FlowExpectedError[incompatible-return]
38
+ return node;
39
+ }
40
+
41
+ export function toNode(node: NodeMock): Node {
42
+ // $FlowExpectedError[incompatible-return]
43
+ return node;
44
+ }
45
+
46
+ // Mock of the Native Hooks
47
+
48
+ const roots: Map<RootTag, NodeSet> = new Map();
49
+ const allocatedTags: Set<number> = new Set();
50
+
51
+ function ensureHostNode(node: Node): void {
52
+ if (node == null || typeof node !== 'object') {
53
+ throw new Error(
54
+ `Expected node to be an object. Got ${
55
+ node === null ? 'null' : typeof node
56
+ } value`,
57
+ );
58
+ }
59
+
60
+ if (typeof node.viewName !== 'string') {
61
+ throw new Error(
62
+ `Expected node to be a host node. Got object with ${
63
+ node.viewName === null ? 'null' : typeof node.viewName
64
+ } viewName`,
65
+ );
66
+ }
67
+ }
68
+
69
+ function getAncestorsInChildSet(
70
+ node: Node,
71
+ childSet: NodeSet,
72
+ ): ?$ReadOnlyArray<[Node, number]> {
73
+ const rootNode = toNode({
74
+ reactTag: 0,
75
+ rootTag: fromNode(node).rootTag,
76
+ viewName: 'RootNode',
77
+ // $FlowExpectedError
78
+ instanceHandle: null,
79
+ props: {},
80
+ children: childSet,
81
+ });
82
+
83
+ let position = 0;
84
+ for (const child of childSet) {
85
+ const ancestors = getAncestors(child, node);
86
+ if (ancestors) {
87
+ return [[rootNode, position]].concat(ancestors);
88
+ }
89
+ position++;
90
+ }
91
+
92
+ return null;
93
+ }
94
+
95
+ function getAncestorsInCurrentTree(
96
+ node: Node,
97
+ ): ?$ReadOnlyArray<[Node, number]> {
98
+ const childSet = roots.get(fromNode(node).rootTag);
99
+ if (childSet == null) {
100
+ return null;
101
+ }
102
+
103
+ return getAncestorsInChildSet(node, childSet);
104
+ }
105
+
106
+ function getAncestors(root: Node, node: Node): ?$ReadOnlyArray<[Node, number]> {
107
+ if (fromNode(root).reactTag === fromNode(node).reactTag) {
108
+ return [];
109
+ }
110
+
111
+ let position = 0;
112
+ for (const child of fromNode(root).children) {
113
+ const ancestors = getAncestors(child, node);
114
+ if (ancestors != null) {
115
+ return [[root, position]].concat(ancestors);
116
+ }
117
+ position++;
118
+ }
119
+
120
+ return null;
121
+ }
122
+
123
+ export function getNodeInChildSet(node: Node, childSet: NodeSet): ?Node {
124
+ const ancestors = getAncestorsInChildSet(node, childSet);
125
+ if (ancestors == null) {
126
+ return null;
127
+ }
128
+
129
+ const [parent, position] = ancestors[ancestors.length - 1];
130
+ const nodeInCurrentTree = fromNode(parent).children[position];
131
+ return nodeInCurrentTree;
132
+ }
133
+
134
+ function getNodeInCurrentTree(node: Node): ?Node {
135
+ const childSet = roots.get(fromNode(node).rootTag);
136
+ if (childSet == null) {
137
+ return null;
138
+ }
139
+
140
+ return getNodeInChildSet(node, childSet);
141
+ }
142
+
143
+ function* dfs(node: ?Node): Iterator<Node> {
144
+ if (node == null) {
145
+ return;
146
+ }
147
+
148
+ yield node;
149
+
150
+ for (const child of fromNode(node).children) {
151
+ yield* dfs(child);
152
+ }
153
+ }
154
+
155
+ function hasDisplayNone(node: Node): boolean {
156
+ const props = fromNode(node).props;
157
+ // Style is flattened when passed to native, so there's no style object.
158
+ // $FlowFixMe[prop-missing]
159
+ return props != null && props.display === 'none';
160
+ }
161
+
162
+ interface IFabricUIManagerMock extends FabricUIManager {
163
+ __getInstanceHandleFromNode(node: Node): InternalInstanceHandle;
164
+ __addCommitHook(commitHook: UIManagerCommitHook): void;
165
+ __removeCommitHook(commitHook: UIManagerCommitHook): void;
166
+ }
167
+
168
+ export interface UIManagerCommitHook {
169
+ shadowTreeWillCommit: (
170
+ rootTag: RootTag,
171
+ oldChildSet: ?NodeSet,
172
+ newChildSet: NodeSet,
173
+ ) => void;
174
+ }
175
+
176
+ const commitHooks: Set<UIManagerCommitHook> = new Set();
177
+
178
+ const FabricUIManagerMock: IFabricUIManagerMock = {
179
+ createNode: jest.fn(
180
+ (
181
+ reactTag: number,
182
+ viewName: string,
183
+ rootTag: RootTag,
184
+ props: NodeProps,
185
+ instanceHandle: InternalInstanceHandle,
186
+ ): Node => {
187
+ if (allocatedTags.has(reactTag)) {
188
+ throw new Error(`Created two native views with tag ${reactTag}`);
189
+ }
190
+
191
+ allocatedTags.add(reactTag);
192
+ return toNode({
193
+ reactTag,
194
+ rootTag,
195
+ viewName,
196
+ instanceHandle,
197
+ props: props,
198
+ children: [],
199
+ });
200
+ },
201
+ ),
202
+
203
+ cloneNode: jest.fn((node: Node): Node => {
204
+ return toNode({...fromNode(node)});
205
+ }),
206
+
207
+ cloneNodeWithNewChildren: jest.fn((node: Node): Node => {
208
+ return toNode({...fromNode(node), children: []});
209
+ }),
210
+
211
+ cloneNodeWithNewProps: jest.fn((node: Node, newProps: NodeProps): Node => {
212
+ return toNode({
213
+ ...fromNode(node),
214
+ props: {
215
+ ...fromNode(node).props,
216
+ ...newProps,
217
+ },
218
+ });
219
+ }),
220
+
221
+ cloneNodeWithNewChildrenAndProps: jest.fn(
222
+ (node: Node, newProps: NodeProps): Node => {
223
+ return toNode({
224
+ ...fromNode(node),
225
+ children: [],
226
+ props: {
227
+ ...fromNode(node).props,
228
+ ...newProps,
229
+ },
230
+ });
231
+ },
232
+ ),
233
+
234
+ createChildSet: jest.fn((rootTag: RootTag): NodeSet => {
235
+ return [];
236
+ }),
237
+
238
+ appendChild: jest.fn((parentNode: Node, child: Node): Node => {
239
+ // Although the signature returns a Node, React expects this to be mutating.
240
+ fromNode(parentNode).children.push(child);
241
+ return parentNode;
242
+ }),
243
+
244
+ appendChildToSet: jest.fn((childSet: NodeSet, child: Node): void => {
245
+ childSet.push(child);
246
+ }),
247
+
248
+ completeRoot: jest.fn((rootTag: RootTag, childSet: NodeSet): void => {
249
+ commitHooks.forEach(hook =>
250
+ hook.shadowTreeWillCommit(rootTag, roots.get(rootTag), childSet),
251
+ );
252
+ roots.set(rootTag, childSet);
253
+ }),
254
+
255
+ measure: jest.fn((node: Node, callback: MeasureOnSuccessCallback): void => {
256
+ ensureHostNode(node);
257
+
258
+ callback(10, 10, 100, 100, 0, 0);
259
+ }),
260
+
261
+ measureInWindow: jest.fn(
262
+ (node: Node, callback: MeasureInWindowOnSuccessCallback): void => {
263
+ ensureHostNode(node);
264
+
265
+ callback(10, 10, 100, 100);
266
+ },
267
+ ),
268
+
269
+ measureLayout: jest.fn(
270
+ (
271
+ node: Node,
272
+ relativeNode: Node,
273
+ onFail: () => void,
274
+ onSuccess: MeasureLayoutOnSuccessCallback,
275
+ ): void => {
276
+ ensureHostNode(node);
277
+ ensureHostNode(relativeNode);
278
+
279
+ onSuccess(1, 1, 100, 100);
280
+ },
281
+ ),
282
+
283
+ configureNextLayoutAnimation: jest.fn(
284
+ (
285
+ config: LayoutAnimationConfig,
286
+ callback: () => void, // check what is returned here
287
+ errorCallback: () => void,
288
+ ): void => {},
289
+ ),
290
+
291
+ sendAccessibilityEvent: jest.fn((node: Node, eventType: string): void => {}),
292
+
293
+ findShadowNodeByTag_DEPRECATED: jest.fn((reactTag: number): ?Node => {}),
294
+
295
+ getBoundingClientRect: jest.fn(
296
+ (
297
+ node: Node,
298
+ includeTransform: boolean,
299
+ ): ?[
300
+ /* x:*/ number,
301
+ /* y:*/ number,
302
+ /* width:*/ number,
303
+ /* height:*/ number,
304
+ ] => {
305
+ ensureHostNode(node);
306
+
307
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
308
+ const currentProps =
309
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
310
+ if (currentProps == null) {
311
+ return null;
312
+ }
313
+
314
+ const boundingClientRectForTests: ?{
315
+ x: number,
316
+ y: number,
317
+ width: number,
318
+ height: number,
319
+ } =
320
+ // $FlowExpectedError[prop-missing]
321
+ currentProps.__boundingClientRectForTests;
322
+
323
+ if (boundingClientRectForTests == null) {
324
+ return null;
325
+ }
326
+
327
+ const {x, y, width, height} = boundingClientRectForTests;
328
+ return [x, y, width, height];
329
+ },
330
+ ),
331
+
332
+ hasPointerCapture: jest.fn((node: Node, pointerId: number): boolean => false),
333
+
334
+ setPointerCapture: jest.fn((node: Node, pointerId: number): void => {}),
335
+
336
+ releasePointerCapture: jest.fn((node: Node, pointerId: number): void => {}),
337
+
338
+ setNativeProps: jest.fn((node: Node, newProps: NodeProps): void => {}),
339
+
340
+ dispatchCommand: jest.fn(
341
+ (node: Node, commandName: string, args: Array<mixed>): void => {},
342
+ ),
343
+
344
+ getParentNode: jest.fn((node: Node): ?InternalInstanceHandle => {
345
+ const ancestors = getAncestorsInCurrentTree(node);
346
+ if (ancestors == null || ancestors.length - 2 < 0) {
347
+ return null;
348
+ }
349
+
350
+ const [parentOfParent, position] = ancestors[ancestors.length - 2];
351
+ const parentInCurrentTree = fromNode(parentOfParent).children[position];
352
+ return fromNode(parentInCurrentTree).instanceHandle;
353
+ }),
354
+
355
+ getChildNodes: jest.fn(
356
+ (node: Node): $ReadOnlyArray<InternalInstanceHandle> => {
357
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
358
+
359
+ if (nodeInCurrentTree == null) {
360
+ return [];
361
+ }
362
+
363
+ return fromNode(nodeInCurrentTree).children.map(
364
+ child => fromNode(child).instanceHandle,
365
+ );
366
+ },
367
+ ),
368
+
369
+ isConnected: jest.fn((node: Node): boolean => {
370
+ return getNodeInCurrentTree(node) != null;
371
+ }),
372
+
373
+ getTextContent: jest.fn((node: Node): string => {
374
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
375
+
376
+ let result = '';
377
+
378
+ if (nodeInCurrentTree == null) {
379
+ return result;
380
+ }
381
+
382
+ for (const childNode of dfs(nodeInCurrentTree)) {
383
+ if (fromNode(childNode).viewName === 'RCTRawText') {
384
+ const props = fromNode(childNode).props;
385
+ // $FlowExpectedError[prop-missing]
386
+ const maybeString: ?string = props.text;
387
+ if (typeof maybeString === 'string') {
388
+ result += maybeString;
389
+ }
390
+ }
391
+ }
392
+ return result;
393
+ }),
394
+
395
+ compareDocumentPosition: jest.fn((node: Node, otherNode: Node): number => {
396
+ /* eslint-disable no-bitwise */
397
+ const ReadOnlyNode = require('../../DOM/Nodes/ReadOnlyNode').default;
398
+
399
+ // Quick check for node vs. itself
400
+ if (fromNode(node).reactTag === fromNode(otherNode).reactTag) {
401
+ return 0;
402
+ }
403
+
404
+ if (fromNode(node).rootTag !== fromNode(otherNode).rootTag) {
405
+ return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
406
+ }
407
+
408
+ const ancestors = getAncestorsInCurrentTree(node);
409
+ if (ancestors == null) {
410
+ return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
411
+ }
412
+
413
+ const otherAncestors = getAncestorsInCurrentTree(otherNode);
414
+ if (otherAncestors == null) {
415
+ return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
416
+ }
417
+
418
+ // Consume all common ancestors
419
+ let i = 0;
420
+ while (
421
+ i < ancestors.length &&
422
+ i < otherAncestors.length &&
423
+ ancestors[i][1] === otherAncestors[i][1]
424
+ ) {
425
+ i++;
426
+ }
427
+
428
+ if (i === ancestors.length) {
429
+ return (
430
+ ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
431
+ ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING
432
+ );
433
+ }
434
+
435
+ if (i === otherAncestors.length) {
436
+ return (
437
+ ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
438
+ ReadOnlyNode.DOCUMENT_POSITION_PRECEDING
439
+ );
440
+ }
441
+
442
+ if (ancestors[i][1] > otherAncestors[i][1]) {
443
+ return ReadOnlyNode.DOCUMENT_POSITION_PRECEDING;
444
+ }
445
+
446
+ return ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING;
447
+ }),
448
+
449
+ getOffset: jest.fn(
450
+ (
451
+ node: Node,
452
+ ): ?[
453
+ /* offsetParent: */ InternalInstanceHandle,
454
+ /* offsetTop: */ number,
455
+ /* offsetLeft: */ number,
456
+ ] => {
457
+ const ancestors = getAncestorsInCurrentTree(node);
458
+ if (ancestors == null) {
459
+ return null;
460
+ }
461
+
462
+ const [parent, position] = ancestors[ancestors.length - 1];
463
+ const nodeInCurrentTree = fromNode(parent).children[position];
464
+
465
+ const currentProps =
466
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
467
+ if (currentProps == null || hasDisplayNone(nodeInCurrentTree)) {
468
+ return null;
469
+ }
470
+
471
+ const offsetForTests: ?{
472
+ top: number,
473
+ left: number,
474
+ } =
475
+ // $FlowExpectedError[prop-missing]
476
+ currentProps.__offsetForTests;
477
+
478
+ if (offsetForTests == null) {
479
+ return null;
480
+ }
481
+
482
+ let currentIndex = ancestors.length - 1;
483
+ while (currentIndex >= 0 && !hasDisplayNone(ancestors[currentIndex][0])) {
484
+ currentIndex--;
485
+ }
486
+
487
+ if (currentIndex >= 0) {
488
+ // The node or one of its ancestors have display: none
489
+ return null;
490
+ }
491
+
492
+ return [
493
+ fromNode(parent).instanceHandle,
494
+ offsetForTests.top,
495
+ offsetForTests.left,
496
+ ];
497
+ },
498
+ ),
499
+
500
+ getScrollPosition: jest.fn(
501
+ (node: Node): ?[/* scrollLeft: */ number, /* scrollTop: */ number] => {
502
+ ensureHostNode(node);
503
+
504
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
505
+ const currentProps =
506
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
507
+ if (currentProps == null) {
508
+ return null;
509
+ }
510
+
511
+ const scrollForTests: ?{
512
+ scrollLeft: number,
513
+ scrollTop: number,
514
+ ...
515
+ } =
516
+ // $FlowExpectedError[prop-missing]
517
+ currentProps.__scrollForTests;
518
+
519
+ if (scrollForTests == null) {
520
+ return null;
521
+ }
522
+
523
+ const {scrollLeft, scrollTop} = scrollForTests;
524
+ return [scrollLeft, scrollTop];
525
+ },
526
+ ),
527
+
528
+ getScrollSize: jest.fn(
529
+ (node: Node): ?[/* scrollLeft: */ number, /* scrollTop: */ number] => {
530
+ ensureHostNode(node);
531
+
532
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
533
+ const currentProps =
534
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
535
+ if (currentProps == null) {
536
+ return null;
537
+ }
538
+
539
+ const scrollForTests: ?{
540
+ scrollWidth: number,
541
+ scrollHeight: number,
542
+ ...
543
+ } =
544
+ // $FlowExpectedError[prop-missing]
545
+ currentProps.__scrollForTests;
546
+
547
+ if (scrollForTests == null) {
548
+ return null;
549
+ }
550
+
551
+ const {scrollWidth, scrollHeight} = scrollForTests;
552
+ return [scrollWidth, scrollHeight];
553
+ },
554
+ ),
555
+
556
+ getInnerSize: jest.fn(
557
+ (node: Node): ?[/* width: */ number, /* height: */ number] => {
558
+ ensureHostNode(node);
559
+
560
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
561
+ const currentProps =
562
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
563
+ if (currentProps == null) {
564
+ return null;
565
+ }
566
+
567
+ const innerSizeForTests: ?{
568
+ width: number,
569
+ height: number,
570
+ ...
571
+ } =
572
+ // $FlowExpectedError[prop-missing]
573
+ currentProps.__innerSizeForTests;
574
+
575
+ if (innerSizeForTests == null) {
576
+ return null;
577
+ }
578
+
579
+ const {width, height} = innerSizeForTests;
580
+ return [width, height];
581
+ },
582
+ ),
583
+
584
+ getBorderSize: jest.fn(
585
+ (
586
+ node: Node,
587
+ ): ?[
588
+ /* topWidth: */ number,
589
+ /* rightWidth: */ number,
590
+ /* bottomWidth: */ number,
591
+ /* leftWidth: */ number,
592
+ ] => {
593
+ ensureHostNode(node);
594
+
595
+ const nodeInCurrentTree = getNodeInCurrentTree(node);
596
+ const currentProps =
597
+ nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
598
+ if (currentProps == null) {
599
+ return null;
600
+ }
601
+
602
+ const borderSizeForTests: ?{
603
+ topWidth?: number,
604
+ rightWidth?: number,
605
+ bottomWidth?: number,
606
+ leftWidth?: number,
607
+ ...
608
+ } =
609
+ // $FlowExpectedError[prop-missing]
610
+ currentProps.__borderSizeForTests;
611
+
612
+ if (borderSizeForTests == null) {
613
+ return null;
614
+ }
615
+
616
+ const {
617
+ topWidth = 0,
618
+ rightWidth = 0,
619
+ bottomWidth = 0,
620
+ leftWidth = 0,
621
+ } = borderSizeForTests;
622
+ return [topWidth, rightWidth, bottomWidth, leftWidth];
623
+ },
624
+ ),
625
+
626
+ getTagName: jest.fn((node: Node): string => {
627
+ ensureHostNode(node);
628
+ return 'RN:' + fromNode(node).viewName;
629
+ }),
630
+
631
+ __getInstanceHandleFromNode(node: Node): InternalInstanceHandle {
632
+ return fromNode(node).instanceHandle;
633
+ },
634
+
635
+ __addCommitHook(commitHook: UIManagerCommitHook): void {
636
+ commitHooks.add(commitHook);
637
+ },
638
+
639
+ __removeCommitHook(commitHook: UIManagerCommitHook): void {
640
+ commitHooks.delete(commitHook);
641
+ },
642
+ };
643
+
644
+ global.nativeFabricUIManager = FabricUIManagerMock;
645
+
646
+ export function getFabricUIManager(): ?IFabricUIManagerMock {
647
+ return FabricUIManagerMock;
648
+ }
@@ -16,15 +16,24 @@ import typeof RawEventEmitter from '../Core/RawEventEmitter';
16
16
  import typeof ReactFiberErrorDialog from '../Core/ReactFiberErrorDialog';
17
17
  import typeof RCTEventEmitter from '../EventEmitter/RCTEventEmitter';
18
18
  import typeof CustomEvent from '../Events/CustomEvent';
19
+ import typeof {
20
+ createPublicInstance,
21
+ createPublicTextInstance,
22
+ getNativeTagFromPublicInstance,
23
+ getNodeFromPublicInstance,
24
+ } from '../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance';
25
+ import typeof {
26
+ create as createAttributePayload,
27
+ diff as diffAttributePayloads,
28
+ } from '../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload';
19
29
  import typeof UIManager from '../ReactNative/UIManager';
20
30
  import typeof ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
21
31
  import typeof flattenStyle from '../StyleSheet/flattenStyle';
32
+ import type {DangerouslyImpreciseStyleProp} from '../StyleSheet/StyleSheet';
22
33
  import typeof deepFreezeAndThrowOnMutationInDev from '../Utilities/deepFreezeAndThrowOnMutationInDev';
23
34
  import typeof deepDiffer from '../Utilities/differ/deepDiffer';
24
35
  import typeof Platform from '../Utilities/Platform';
25
36
 
26
- import {type DangerouslyImpreciseStyleProp} from '../StyleSheet/StyleSheet';
27
-
28
37
  // flowlint unsafe-getters-setters:off
29
38
  module.exports = {
30
39
  get BatchedBridge(): BatchedBridge {
@@ -48,6 +57,7 @@ module.exports = {
48
57
  get UIManager(): UIManager {
49
58
  return require('../ReactNative/UIManager');
50
59
  },
60
+ // TODO: Remove when React has migrated to `createAttributePayload` and `diffAttributePayloads`
51
61
  get deepDiffer(): deepDiffer {
52
62
  return require('../Utilities/differ/deepDiffer');
53
63
  },
@@ -56,8 +66,10 @@ module.exports = {
56
66
  > {
57
67
  return require('../Utilities/deepFreezeAndThrowOnMutationInDev');
58
68
  },
69
+ // TODO: Remove when React has migrated to `createAttributePayload` and `diffAttributePayloads`
59
70
  get flattenStyle(): flattenStyle<DangerouslyImpreciseStyleProp> {
60
71
  // $FlowFixMe[underconstrained-implicit-instantiation]
72
+ // $FlowFixMe[incompatible-return]
61
73
  return require('../StyleSheet/flattenStyle');
62
74
  },
63
75
  get ReactFiberErrorDialog(): ReactFiberErrorDialog {
@@ -72,4 +84,28 @@ module.exports = {
72
84
  get CustomEvent(): CustomEvent {
73
85
  return require('../Events/CustomEvent').default;
74
86
  },
87
+ get createAttributePayload(): createAttributePayload {
88
+ return require('../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload')
89
+ .create;
90
+ },
91
+ get diffAttributePayloads(): diffAttributePayloads {
92
+ return require('../ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload')
93
+ .diff;
94
+ },
95
+ get createPublicInstance(): createPublicInstance {
96
+ return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
97
+ .createPublicInstance;
98
+ },
99
+ get createPublicTextInstance(): createPublicTextInstance {
100
+ return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
101
+ .createPublicTextInstance;
102
+ },
103
+ get getNativeTagFromPublicInstance(): getNativeTagFromPublicInstance {
104
+ return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
105
+ .getNativeTagFromPublicInstance;
106
+ },
107
+ get getNodeFromPublicInstance(): getNodeFromPublicInstance {
108
+ return require('../ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance')
109
+ .getNodeFromPublicInstance;
110
+ },
75
111
  };