react-native-windows 0.77.0 → 0.78.0-preview.1

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 (233) hide show
  1. package/.flowconfig +1 -1
  2. package/Chakra/ChakraTracing.cpp +1 -1
  3. package/Libraries/Animated/animations/Animation.js +22 -1
  4. package/Libraries/Animated/animations/DecayAnimation.js +1 -0
  5. package/Libraries/Animated/animations/SpringAnimation.js +1 -0
  6. package/Libraries/Animated/animations/TimingAnimation.js +1 -0
  7. package/Libraries/Animated/nodes/AnimatedAddition.js +9 -2
  8. package/Libraries/Animated/nodes/AnimatedColor.js +4 -1
  9. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +10 -2
  10. package/Libraries/Animated/nodes/AnimatedDivision.js +9 -2
  11. package/Libraries/Animated/nodes/AnimatedInterpolation.js +5 -1
  12. package/Libraries/Animated/nodes/AnimatedModulo.js +5 -2
  13. package/Libraries/Animated/nodes/AnimatedMultiplication.js +9 -2
  14. package/Libraries/Animated/nodes/AnimatedNode.js +25 -46
  15. package/Libraries/Animated/nodes/AnimatedObject.js +9 -2
  16. package/Libraries/Animated/nodes/AnimatedProps.js +5 -1
  17. package/Libraries/Animated/nodes/AnimatedStyle.js +5 -1
  18. package/Libraries/Animated/nodes/AnimatedSubtraction.js +9 -2
  19. package/Libraries/Animated/nodes/AnimatedTracking.js +5 -1
  20. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -1
  21. package/Libraries/Animated/nodes/AnimatedValue.js +49 -4
  22. package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -1
  23. package/Libraries/Animated/useAnimatedProps.js +0 -43
  24. package/Libraries/Components/Button.windows.js +3 -0
  25. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +1 -1
  26. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +3 -1
  27. package/Libraries/Components/LayoutConformance/LayoutConformance.d.ts +21 -0
  28. package/Libraries/Components/LayoutConformance/LayoutConformance.js +59 -0
  29. package/Libraries/Components/LayoutConformance/LayoutConformanceNativeComponent.js +29 -0
  30. package/Libraries/Components/Pressable/Pressable.windows.js +3 -0
  31. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  32. package/Libraries/Components/TextInput/TextInput.d.ts +5 -0
  33. package/Libraries/Components/TextInput/TextInput.flow.js +6 -0
  34. package/Libraries/Components/TextInput/TextInput.js +6 -0
  35. package/Libraries/Components/TextInput/TextInput.windows.js +9 -0
  36. package/Libraries/Components/Touchable/TouchableBounce.windows.js +2 -0
  37. package/Libraries/Components/Touchable/TouchableNativeFeedback.windows.js +2 -0
  38. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +2 -0
  39. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +2 -0
  40. package/Libraries/Components/View/View.windows.js +3 -0
  41. package/Libraries/Components/View/ViewAccessibility.d.ts +7 -2
  42. package/Libraries/Components/View/ViewAccessibility.windows.js +1 -0
  43. package/Libraries/Components/View/ViewPropTypes.d.ts +0 -7
  44. package/Libraries/Components/View/ViewPropTypes.js +0 -9
  45. package/Libraries/Components/View/ViewPropTypes.windows.js +1 -9
  46. package/Libraries/Core/ReactNativeVersion.js +2 -2
  47. package/Libraries/Core/setUpBatchedBridge.js +1 -16
  48. package/Libraries/EventEmitter/RCTEventEmitter.js +2 -6
  49. package/Libraries/Image/AssetSourceResolver.js +11 -0
  50. package/Libraries/Image/AssetSourceResolver.windows.js +11 -0
  51. package/Libraries/Image/Image.windows.js +2 -0
  52. package/Libraries/Inspector/BorderBox.js +26 -14
  53. package/Libraries/Inspector/BoxInspector.js +60 -42
  54. package/Libraries/Inspector/ElementBox.js +55 -48
  55. package/Libraries/Inspector/StyleInspector.js +36 -30
  56. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -2
  57. package/Libraries/Lists/FlatList.d.ts +1 -1
  58. package/Libraries/Modal/Modal.js +2 -0
  59. package/Libraries/Modal/Modal.windows.js +2 -0
  60. package/Libraries/NativeComponent/BaseViewConfig.android.js +0 -2
  61. package/Libraries/NativeComponent/BaseViewConfig.ios.js +0 -2
  62. package/Libraries/NativeComponent/BaseViewConfig.windows.js +0 -2
  63. package/Libraries/Network/RCTNetworking.android.js +24 -16
  64. package/Libraries/Network/RCTNetworking.ios.js +1 -46
  65. package/Libraries/Network/RCTNetworking.windows.js +1 -46
  66. package/Libraries/Network/RCTNetworkingEventDefinitions.flow.js +57 -0
  67. package/Libraries/ReactNative/UIManagerProperties.js +3 -1
  68. package/Libraries/Renderer/implementations/ReactFabric-dev.js +15828 -26461
  69. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3907 -2560
  70. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4399 -2878
  71. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +16102 -26908
  72. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +4034 -2695
  73. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4535 -3045
  74. package/Libraries/Renderer/shims/ReactNativeTypes.js +5 -6
  75. package/Libraries/StyleSheet/processTransform.js +6 -0
  76. package/Libraries/Text/Text.d.ts +6 -1
  77. package/Libraries/Text/Text.windows.js +4 -0
  78. package/Libraries/Text/TextProps.js +2 -2
  79. package/Libraries/Text/TextProps.windows.js +3 -2
  80. package/Libraries/Utilities/BackHandler.android.js +5 -4
  81. package/Libraries/Utilities/BackHandler.ios.js +4 -5
  82. package/Libraries/Utilities/BackHandler.windows.js +5 -4
  83. package/Microsoft.ReactNative/CompositionComponentView.idl +13 -1
  84. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +0 -1
  85. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +0 -5
  86. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +92 -17
  87. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +9 -0
  88. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +13 -33
  89. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -3
  90. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +43 -5
  91. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.h +2 -1
  92. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +12 -10
  93. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +11 -9
  94. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +1 -1
  95. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +191 -329
  96. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +3 -61
  97. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.cpp +66 -0
  98. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.h +52 -0
  99. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +21 -0
  100. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +7 -4
  101. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +79 -19
  102. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +12 -6
  103. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +71 -17
  104. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +16 -0
  105. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +5 -10
  106. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +4 -4
  107. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +138 -110
  108. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.h +27 -27
  109. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +1 -1
  110. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +38 -33
  111. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +0 -2
  112. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +5 -16
  113. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +0 -3
  114. package/Microsoft.ReactNative/Fabric/ImageManager.cpp +9 -0
  115. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +0 -2
  116. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorUtils.cpp +1 -1
  117. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +5 -0
  118. package/Microsoft.ReactNative/IReactContext.cpp +2 -2
  119. package/Microsoft.ReactNative/IReactContext.h +1 -1
  120. package/Microsoft.ReactNative/IReactContext.idl +2 -2
  121. package/Microsoft.ReactNative/IReactPackageBuilder.idl +3 -3
  122. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +97 -87
  123. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +4 -0
  124. package/Microsoft.ReactNative/Modules/AlertModule.cpp +9 -4
  125. package/Microsoft.ReactNative/Modules/Animated/NativeAnimatedNodeManager.cpp +1 -1
  126. package/Microsoft.ReactNative/Modules/Animated/PropsAnimatedNode.cpp +32 -35
  127. package/Microsoft.ReactNative/Modules/Animated/PropsAnimatedNode.h +7 -4
  128. package/Microsoft.ReactNative/Modules/AppStateModule.cpp +1 -1
  129. package/Microsoft.ReactNative/Modules/AppThemeModuleUwp.cpp +2 -2
  130. package/Microsoft.ReactNative/Modules/AppearanceModule.cpp +2 -2
  131. package/Microsoft.ReactNative/Modules/DeviceInfoModule.cpp +3 -3
  132. package/Microsoft.ReactNative/Modules/I18nManagerModule.cpp +1 -1
  133. package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +7 -5
  134. package/Microsoft.ReactNative/Modules/LogBoxModule.h +2 -1
  135. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +10 -10
  136. package/Microsoft.ReactNative/Modules/PaperUIManagerModule.cpp +24 -24
  137. package/Microsoft.ReactNative/Modules/Timing.cpp +2 -2
  138. package/Microsoft.ReactNative/ReactHost/IReactInstance.h +5 -0
  139. package/Microsoft.ReactNative/ReactHost/React.h +0 -3
  140. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +39 -16
  141. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +4 -2
  142. package/Microsoft.ReactNative/ReactNativeHost.cpp +9 -4
  143. package/Microsoft.ReactNative/ReactNativeIsland.idl +5 -1
  144. package/Microsoft.ReactNative/ReactPackageBuilder.cpp +3 -3
  145. package/Microsoft.ReactNative/ReactPackageBuilder.h +4 -4
  146. package/Microsoft.ReactNative/Utils/Helpers.cpp +0 -2
  147. package/Microsoft.ReactNative/Views/DevMenu.cpp +6 -6
  148. package/Microsoft.ReactNative/Views/DevMenu.h +1 -1
  149. package/Microsoft.ReactNative/Views/ViewManagerBase.cpp +2 -2
  150. package/Microsoft.ReactNative/Views/ViewPanel.cpp +1 -1
  151. package/Microsoft.ReactNative/Views/ViewViewManager.cpp +2 -2
  152. package/Microsoft.ReactNative/XamlUIService.cpp +13 -7
  153. package/Microsoft.ReactNative/XamlUIService.h +4 -1
  154. package/Microsoft.ReactNative/XamlUIService.idl +2 -0
  155. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.h +6 -2
  156. package/Microsoft.ReactNative.Cxx/ReactContext.h +1 -1
  157. package/Microsoft.ReactNative.Cxx/XamlUtils.h +12 -0
  158. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  159. package/PropertySheets/React.Cpp.props +3 -0
  160. package/PropertySheets/WebView2.props +1 -1
  161. package/PropertySheets/WinUI.props +5 -4
  162. package/ReactCommon/ReactCommon.vcxproj +5 -1
  163. package/ReactCommon/ReactCommon.vcxproj.filters +1 -1
  164. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +3 -3
  165. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +3 -3
  166. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +91 -0
  167. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +1 -12
  168. package/{Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.h → ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/textinput/TextInputState.h} +37 -35
  169. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +1 -0
  170. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +4 -0
  171. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/ImageRequestParams.h +30 -0
  172. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/runtimescheduler/SchedulerPriorityUtils.h +4 -3
  173. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/primitives.h +179 -0
  174. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +43 -57
  175. package/Shared/HermesRuntimeHolder.cpp +2 -2
  176. package/Shared/Shared.vcxitems +8 -14
  177. package/Shared/Shared.vcxitems.filters +4 -16
  178. package/Shared/Threading/BatchingQueueThread.cpp +3 -3
  179. package/codegen/NativeCPUTimeSpec.g.h +41 -0
  180. package/codegen/NativeFantomSpec.g.h +78 -0
  181. package/codegen/NativePerformanceSpec.g.h +31 -43
  182. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +84 -84
  183. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +212 -0
  184. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +295 -0
  185. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +200 -0
  186. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +224 -0
  187. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +250 -0
  188. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +267 -0
  189. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +234 -0
  190. package/codegen/react/components/rnwcore/InputAccessory.g.h +200 -0
  191. package/codegen/react/components/rnwcore/ModalHostView.g.h +283 -0
  192. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +246 -0
  193. package/codegen/react/components/rnwcore/SafeAreaView.g.h +197 -0
  194. package/codegen/react/components/rnwcore/Switch.g.h +263 -0
  195. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +200 -0
  196. package/codegen/rnwcoreJSI-generated.cpp +90 -57
  197. package/codegen/rnwcoreJSI.h +241 -104
  198. package/index.js +5 -0
  199. package/index.windows.js +5 -0
  200. package/just-task.js +1 -1
  201. package/package.json +25 -26
  202. package/src/private/animated/NativeAnimatedValidation.js +1 -1
  203. package/src/private/featureflags/ReactNativeFeatureFlags.js +33 -27
  204. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +5 -5
  205. package/src/private/renderer/errorhandling/ErrorHandlers.js +12 -55
  206. package/src/private/specs/modules/{NativeJSCSamplingProfiler.js → NativeCPUTime.js} +7 -2
  207. package/src/private/specs/modules/NativeFantom.js +37 -0
  208. package/src/private/utilities/ensureInstance.js +21 -0
  209. package/src/private/webapis/dom/nodes/ReactNativeElement.js +49 -6
  210. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +17 -9
  211. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +11 -11
  212. package/src/private/webapis/intersectionobserver/IntersectionObserverEntry.js +1 -1
  213. package/src/private/webapis/intersectionobserver/IntersectionObserverManager.js +1 -1
  214. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
  215. package/src/private/webapis/performance/Performance.js +0 -12
  216. package/src/private/webapis/performance/specs/NativePerformance.js +0 -11
  217. package/types/index.d.ts +1 -0
  218. package/Libraries/HeapCapture/HeapCapture.js +0 -29
  219. package/Libraries/HeapCapture/NativeJSCHeapCapture.js +0 -13
  220. package/Libraries/Performance/NativeJSCSamplingProfiler.js +0 -13
  221. package/Libraries/Performance/SamplingProfiler.js +0 -39
  222. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +0 -334
  223. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentDescriptor.h +0 -39
  224. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.cpp +0 -18
  225. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.h +0 -39
  226. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.cpp +0 -34
  227. package/Microsoft.ReactNative/Fabric/ReactNativeConfigProperties.cpp +0 -53
  228. package/Microsoft.ReactNative/Fabric/ReactNativeConfigProperties.h +0 -26
  229. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/LayoutableShadowNode.cpp +0 -363
  230. package/codegen/NativeJSCSamplingProfilerSpec.g.h +0 -35
  231. package/src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock.js +0 -413
  232. package/src/private/webapis/intersectionobserver/specs/__mocks__/NativeIntersectionObserver.js +0 -181
  233. package/src/private/webapis/mutationobserver/specs/__mocks__/NativeMutationObserver.js +0 -327
@@ -1,413 +0,0 @@
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
- Node,
15
- } from '../../../../../../../Libraries/Renderer/shims/ReactNativeTypes';
16
- import type {
17
- MeasureInWindowOnSuccessCallback,
18
- MeasureLayoutOnSuccessCallback,
19
- MeasureOnSuccessCallback,
20
- } from '../NativeDOM';
21
- import typeof NativeDOM from '../NativeDOM';
22
-
23
- import {
24
- ensureHostNode,
25
- fromNode,
26
- getAncestorsInCurrentTree,
27
- getNodeInCurrentTree,
28
- } from '../../../../../../../Libraries/ReactNative/__mocks__/FabricUIManager';
29
-
30
- function* dfs(node: ?Node): Iterator<Node> {
31
- if (node == null) {
32
- return;
33
- }
34
-
35
- yield node;
36
-
37
- for (const child of fromNode(node).children) {
38
- yield* dfs(child);
39
- }
40
- }
41
-
42
- function hasDisplayNone(node: Node): boolean {
43
- const props = fromNode(node).props;
44
- // Style is flattened when passed to native, so there's no style object.
45
- // $FlowFixMe[prop-missing]
46
- return props != null && props.display === 'none';
47
- }
48
-
49
- const NativeDOMMock: NativeDOM = {
50
- getBoundingClientRect: jest.fn(
51
- (
52
- node: Node,
53
- includeTransform: boolean,
54
- ): [
55
- /* x:*/ number,
56
- /* y:*/ number,
57
- /* width:*/ number,
58
- /* height:*/ number,
59
- ] => {
60
- ensureHostNode(node);
61
-
62
- const nodeInCurrentTree = getNodeInCurrentTree(node);
63
- const currentProps =
64
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
65
- if (currentProps == null) {
66
- return [0, 0, 0, 0];
67
- }
68
-
69
- const boundingClientRectForTests: ?{
70
- x: number,
71
- y: number,
72
- width: number,
73
- height: number,
74
- } =
75
- // $FlowExpectedError[prop-missing]
76
- currentProps.__boundingClientRectForTests;
77
-
78
- if (boundingClientRectForTests == null) {
79
- return [0, 0, 0, 0];
80
- }
81
-
82
- const {x, y, width, height} = boundingClientRectForTests;
83
- return [x, y, width, height];
84
- },
85
- ),
86
-
87
- hasPointerCapture: jest.fn((node: Node, pointerId: number): boolean => false),
88
-
89
- setPointerCapture: jest.fn((node: Node, pointerId: number): void => {}),
90
-
91
- releasePointerCapture: jest.fn((node: Node, pointerId: number): void => {}),
92
-
93
- getParentNode: jest.fn((node: Node): ?InternalInstanceHandle => {
94
- const ancestors = getAncestorsInCurrentTree(node);
95
- if (ancestors == null || ancestors.length - 2 < 0) {
96
- return null;
97
- }
98
-
99
- const [parentOfParent, position] = ancestors[ancestors.length - 2];
100
- const parentInCurrentTree = fromNode(parentOfParent).children[position];
101
- return fromNode(parentInCurrentTree).instanceHandle;
102
- }),
103
-
104
- getChildNodes: jest.fn(
105
- (node: Node): $ReadOnlyArray<InternalInstanceHandle> => {
106
- const nodeInCurrentTree = getNodeInCurrentTree(node);
107
-
108
- if (nodeInCurrentTree == null) {
109
- return [];
110
- }
111
-
112
- return fromNode(nodeInCurrentTree).children.map(
113
- child => fromNode(child).instanceHandle,
114
- );
115
- },
116
- ),
117
-
118
- isConnected: jest.fn((node: Node): boolean => {
119
- return getNodeInCurrentTree(node) != null;
120
- }),
121
-
122
- getTextContent: jest.fn((node: Node): string => {
123
- const nodeInCurrentTree = getNodeInCurrentTree(node);
124
-
125
- let result = '';
126
-
127
- if (nodeInCurrentTree == null) {
128
- return result;
129
- }
130
-
131
- for (const childNode of dfs(nodeInCurrentTree)) {
132
- if (fromNode(childNode).viewName === 'RCTRawText') {
133
- const props = fromNode(childNode).props;
134
- // $FlowExpectedError[prop-missing]
135
- const maybeString: ?string = props.text;
136
- if (typeof maybeString === 'string') {
137
- result += maybeString;
138
- }
139
- }
140
- }
141
- return result;
142
- }),
143
-
144
- compareDocumentPosition: jest.fn((node: Node, otherNode: Node): number => {
145
- /* eslint-disable no-bitwise */
146
- const ReadOnlyNode = require('../../ReadOnlyNode').default;
147
-
148
- // Quick check for node vs. itself
149
- if (fromNode(node).reactTag === fromNode(otherNode).reactTag) {
150
- return 0;
151
- }
152
-
153
- if (fromNode(node).rootTag !== fromNode(otherNode).rootTag) {
154
- return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
155
- }
156
-
157
- const ancestors = getAncestorsInCurrentTree(node);
158
- if (ancestors == null) {
159
- return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
160
- }
161
-
162
- const otherAncestors = getAncestorsInCurrentTree(otherNode);
163
- if (otherAncestors == null) {
164
- return ReadOnlyNode.DOCUMENT_POSITION_DISCONNECTED;
165
- }
166
-
167
- // Consume all common ancestors
168
- let i = 0;
169
- while (
170
- i < ancestors.length &&
171
- i < otherAncestors.length &&
172
- ancestors[i][1] === otherAncestors[i][1]
173
- ) {
174
- i++;
175
- }
176
-
177
- if (i === ancestors.length) {
178
- return (
179
- ReadOnlyNode.DOCUMENT_POSITION_CONTAINED_BY |
180
- ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING
181
- );
182
- }
183
-
184
- if (i === otherAncestors.length) {
185
- return (
186
- ReadOnlyNode.DOCUMENT_POSITION_CONTAINS |
187
- ReadOnlyNode.DOCUMENT_POSITION_PRECEDING
188
- );
189
- }
190
-
191
- if (ancestors[i][1] > otherAncestors[i][1]) {
192
- return ReadOnlyNode.DOCUMENT_POSITION_PRECEDING;
193
- }
194
-
195
- return ReadOnlyNode.DOCUMENT_POSITION_FOLLOWING;
196
- }),
197
-
198
- getOffset: jest.fn(
199
- (
200
- node: Node,
201
- ): [
202
- /* offsetParent: */ ?InternalInstanceHandle,
203
- /* offsetTop: */ number,
204
- /* offsetLeft: */ number,
205
- ] => {
206
- const ancestors = getAncestorsInCurrentTree(node);
207
- if (ancestors == null) {
208
- return [null, 0, 0];
209
- }
210
-
211
- const [parent, position] = ancestors[ancestors.length - 1];
212
- const nodeInCurrentTree = fromNode(parent).children[position];
213
-
214
- const currentProps =
215
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
216
- if (currentProps == null || hasDisplayNone(nodeInCurrentTree)) {
217
- return [null, 0, 0];
218
- }
219
-
220
- const offsetForTests: ?{
221
- top: number,
222
- left: number,
223
- } =
224
- // $FlowExpectedError[prop-missing]
225
- currentProps.__offsetForTests;
226
-
227
- if (offsetForTests == null) {
228
- return [null, 0, 0];
229
- }
230
-
231
- let currentIndex = ancestors.length - 1;
232
- while (currentIndex >= 0 && !hasDisplayNone(ancestors[currentIndex][0])) {
233
- currentIndex--;
234
- }
235
-
236
- if (currentIndex >= 0) {
237
- // The node or one of its ancestors have display: none
238
- return [null, 0, 0];
239
- }
240
-
241
- return [
242
- fromNode(parent).instanceHandle,
243
- offsetForTests.top,
244
- offsetForTests.left,
245
- ];
246
- },
247
- ),
248
-
249
- getScrollPosition: jest.fn(
250
- (node: Node): [/* scrollLeft: */ number, /* scrollTop: */ number] => {
251
- ensureHostNode(node);
252
-
253
- const nodeInCurrentTree = getNodeInCurrentTree(node);
254
- const currentProps =
255
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
256
- if (currentProps == null) {
257
- return [0, 0];
258
- }
259
-
260
- const scrollForTests: ?{
261
- scrollLeft: number,
262
- scrollTop: number,
263
- ...
264
- } =
265
- // $FlowExpectedError[prop-missing]
266
- currentProps.__scrollForTests;
267
-
268
- if (scrollForTests == null) {
269
- return [0, 0];
270
- }
271
-
272
- const {scrollLeft, scrollTop} = scrollForTests;
273
- return [scrollLeft, scrollTop];
274
- },
275
- ),
276
-
277
- getScrollSize: jest.fn(
278
- (node: Node): [/* scrollLeft: */ number, /* scrollTop: */ number] => {
279
- ensureHostNode(node);
280
-
281
- const nodeInCurrentTree = getNodeInCurrentTree(node);
282
- const currentProps =
283
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
284
- if (currentProps == null) {
285
- return [0, 0];
286
- }
287
-
288
- const scrollForTests: ?{
289
- scrollWidth: number,
290
- scrollHeight: number,
291
- ...
292
- } =
293
- // $FlowExpectedError[prop-missing]
294
- currentProps.__scrollForTests;
295
-
296
- if (scrollForTests == null) {
297
- return [0, 0];
298
- }
299
-
300
- const {scrollWidth, scrollHeight} = scrollForTests;
301
- return [scrollWidth, scrollHeight];
302
- },
303
- ),
304
-
305
- getInnerSize: jest.fn(
306
- (node: Node): [/* width: */ number, /* height: */ number] => {
307
- ensureHostNode(node);
308
-
309
- const nodeInCurrentTree = getNodeInCurrentTree(node);
310
- const currentProps =
311
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
312
- if (currentProps == null) {
313
- return [0, 0];
314
- }
315
-
316
- const innerSizeForTests: ?{
317
- width: number,
318
- height: number,
319
- ...
320
- } =
321
- // $FlowExpectedError[prop-missing]
322
- currentProps.__innerSizeForTests;
323
-
324
- if (innerSizeForTests == null) {
325
- return [0, 0];
326
- }
327
-
328
- const {width, height} = innerSizeForTests;
329
- return [width, height];
330
- },
331
- ),
332
-
333
- getBorderWidth: jest.fn(
334
- (
335
- node: Node,
336
- ): [
337
- /* topWidth: */ number,
338
- /* rightWidth: */ number,
339
- /* bottomWidth: */ number,
340
- /* leftWidth: */ number,
341
- ] => {
342
- ensureHostNode(node);
343
-
344
- const nodeInCurrentTree = getNodeInCurrentTree(node);
345
- const currentProps =
346
- nodeInCurrentTree != null ? fromNode(nodeInCurrentTree).props : null;
347
- if (currentProps == null) {
348
- return [0, 0, 0, 0];
349
- }
350
-
351
- const borderSizeForTests: ?{
352
- topWidth?: number,
353
- rightWidth?: number,
354
- bottomWidth?: number,
355
- leftWidth?: number,
356
- ...
357
- } =
358
- // $FlowExpectedError[prop-missing]
359
- currentProps.__borderSizeForTests;
360
-
361
- if (borderSizeForTests == null) {
362
- return [0, 0, 0, 0];
363
- }
364
-
365
- const {
366
- topWidth = 0,
367
- rightWidth = 0,
368
- bottomWidth = 0,
369
- leftWidth = 0,
370
- } = borderSizeForTests;
371
- return [topWidth, rightWidth, bottomWidth, leftWidth];
372
- },
373
- ),
374
-
375
- getTagName: jest.fn((node: Node): string => {
376
- ensureHostNode(node);
377
- return 'RN:' + fromNode(node).viewName;
378
- }),
379
-
380
- /**
381
- * Legacy layout APIs
382
- */
383
-
384
- measure: jest.fn((node: Node, callback: MeasureOnSuccessCallback): void => {
385
- ensureHostNode(node);
386
-
387
- callback(10, 10, 100, 100, 0, 0);
388
- }),
389
-
390
- measureInWindow: jest.fn(
391
- (node: Node, callback: MeasureInWindowOnSuccessCallback): void => {
392
- ensureHostNode(node);
393
-
394
- callback(10, 10, 100, 100);
395
- },
396
- ),
397
-
398
- measureLayout: jest.fn(
399
- (
400
- node: Node,
401
- relativeNode: Node,
402
- onFail: () => void,
403
- onSuccess: MeasureLayoutOnSuccessCallback,
404
- ): void => {
405
- ensureHostNode(node);
406
- ensureHostNode(relativeNode);
407
-
408
- onSuccess(1, 1, 100, 100);
409
- },
410
- ),
411
- };
412
-
413
- export default NativeDOMMock;
@@ -1,181 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict-local
8
- * @format
9
- */
10
-
11
- import type ReactNativeElement from '../../../dom/nodes/ReactNativeElement';
12
- import type IntersectionObserver from '../../IntersectionObserver';
13
- import type {
14
- NativeIntersectionObserverEntry,
15
- NativeIntersectionObserverObserveOptions,
16
- Spec,
17
- } from '../NativeIntersectionObserver';
18
-
19
- import {getFabricUIManager} from '../../../../../../Libraries/ReactNative/__mocks__/FabricUIManager';
20
- import {getShadowNode} from '../../../dom/nodes/ReadOnlyNode';
21
- import invariant from 'invariant';
22
- import nullthrows from 'nullthrows';
23
-
24
- type ObserverState = {
25
- thresholds: $ReadOnlyArray<number>,
26
- rootThresholds?: ?$ReadOnlyArray<number>,
27
- intersecting: boolean,
28
- currentThreshold: ?number,
29
- currentRootThreshold: ?number,
30
- };
31
-
32
- type Observation = {
33
- ...NativeIntersectionObserverObserveOptions,
34
- state: ObserverState,
35
- };
36
-
37
- let pendingRecords: Array<NativeIntersectionObserverEntry> = [];
38
- let callback: ?() => void;
39
- let observations: Array<Observation> = [];
40
-
41
- const FabricUIManagerMock = nullthrows(getFabricUIManager());
42
-
43
- function createRecordFromObservation(
44
- observation: Observation,
45
- ): NativeIntersectionObserverEntry {
46
- return {
47
- intersectionObserverId: observation.intersectionObserverId,
48
- targetInstanceHandle: FabricUIManagerMock.__getInstanceHandleFromNode(
49
- // $FlowExpectedError[incompatible-call]
50
- observation.targetShadowNode,
51
- ),
52
- targetRect: observation.state.intersecting ? [0, 0, 1, 1] : [20, 20, 1, 1],
53
- rootRect: [0, 0, 10, 10],
54
- intersectionRect: observation.state.intersecting ? [0, 0, 1, 1] : null,
55
- isIntersectingAboveThresholds: observation.state.intersecting,
56
- time: performance.now(),
57
- };
58
- }
59
-
60
- function notifyIntersectionObservers(): void {
61
- callback?.();
62
- }
63
-
64
- const NativeIntersectionObserverMock = {
65
- observe: (options: NativeIntersectionObserverObserveOptions): void => {
66
- invariant(
67
- observations.find(
68
- observation =>
69
- observation.intersectionObserverId ===
70
- options.intersectionObserverId &&
71
- observation.targetShadowNode === options.targetShadowNode,
72
- ) == null,
73
- 'unexpected duplicate call to observe',
74
- );
75
- const observation = {
76
- ...options,
77
- state: {
78
- thresholds: options.thresholds,
79
- rootThresholds: options.rootThresholds,
80
- intersecting: false,
81
- currentThreshold: null,
82
- currentRootThreshold: null,
83
- },
84
- };
85
- observations.push(observation);
86
- pendingRecords.push(createRecordFromObservation(observation));
87
- setImmediate(notifyIntersectionObservers);
88
- },
89
- unobserve: (
90
- intersectionObserverId: number,
91
- targetShadowNode: mixed,
92
- ): void => {
93
- const observationIndex = observations.findIndex(
94
- observation =>
95
- observation.intersectionObserverId === intersectionObserverId &&
96
- observation.targetShadowNode === targetShadowNode,
97
- );
98
- invariant(
99
- observationIndex !== -1,
100
- 'unexpected duplicate call to unobserve',
101
- );
102
- observations.splice(observationIndex, 1);
103
-
104
- pendingRecords = pendingRecords.filter(
105
- record =>
106
- record.intersectionObserverId !== intersectionObserverId ||
107
- record.targetInstanceHandle !==
108
- FabricUIManagerMock.__getInstanceHandleFromNode(
109
- // $FlowExpectedError[incompatible-call]
110
- targetShadowNode,
111
- ),
112
- );
113
- },
114
- connect: (notifyIntersectionObserversCallback: () => void): void => {
115
- invariant(callback == null, 'unexpected call to connect');
116
- invariant(
117
- notifyIntersectionObserversCallback != null,
118
- 'unexpected null notify intersection observers callback',
119
- );
120
- callback = notifyIntersectionObserversCallback;
121
- },
122
- disconnect: (): void => {
123
- invariant(callback != null, 'unexpected call to disconnect');
124
- callback = null;
125
- },
126
- takeRecords: (): $ReadOnlyArray<NativeIntersectionObserverEntry> => {
127
- const currentRecords = pendingRecords;
128
- pendingRecords = [];
129
- return currentRecords;
130
- },
131
- __forceTransitionForTests: (
132
- observer: IntersectionObserver,
133
- target: ReactNativeElement,
134
- ) => {
135
- const targetShadowNode = getShadowNode(target);
136
- const observation = observations.find(
137
- obs =>
138
- obs.intersectionObserverId === observer.__getObserverID() &&
139
- obs.targetShadowNode === targetShadowNode,
140
- );
141
- invariant(
142
- observation != null,
143
- 'cannot force transition on an unobserved target',
144
- );
145
- if (observation.state.intersecting) {
146
- observation.state.intersecting = false;
147
- observation.state.currentThreshold = null;
148
- observation.state.currentRootThreshold = null;
149
- } else {
150
- observation.state.intersecting = true;
151
- observation.state.currentThreshold = observation.thresholds[0];
152
- observation.state.currentRootThreshold =
153
- observation.rootThresholds != null
154
- ? observation.rootThresholds[0]
155
- : null;
156
- }
157
- pendingRecords.push(createRecordFromObservation(observation));
158
- setImmediate(notifyIntersectionObservers);
159
- },
160
- __getObservationsForTests: (
161
- observer: IntersectionObserver,
162
- ): Array<{targetShadowNode: mixed, thresholds: $ReadOnlyArray<number>}> => {
163
- const intersectionObserverId = observer.__getObserverID();
164
- return observations
165
- .filter(
166
- observation =>
167
- observation.intersectionObserverId === intersectionObserverId,
168
- )
169
- .map(observation => ({
170
- targetShadowNode: observation.targetShadowNode,
171
- thresholds: observation.thresholds,
172
- }));
173
- },
174
- __isConnected: (): boolean => {
175
- return callback != null;
176
- },
177
- };
178
-
179
- (NativeIntersectionObserverMock: Spec);
180
-
181
- export default NativeIntersectionObserverMock;