@office-iss/react-native-win32 0.81.2 → 0.82.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 (209) hide show
  1. package/.flowconfig +3 -11
  2. package/CHANGELOG.json +118 -43
  3. package/CHANGELOG.md +45 -27
  4. package/IntegrationTests/IntegrationTestsApp.js +2 -2
  5. package/IntegrationTests/LayoutEventsTest.js +3 -3
  6. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +7 -3
  7. package/Libraries/Alert/RCTAlertManager.android.js +4 -2
  8. package/Libraries/Animated/Animated.d.ts +2 -0
  9. package/Libraries/Animated/AnimatedEvent.js +1 -1
  10. package/Libraries/Animated/AnimatedExports.js.flow +1 -0
  11. package/Libraries/Animated/AnimatedImplementation.js +4 -2
  12. package/Libraries/Animated/AnimatedMock.js +1 -1
  13. package/Libraries/Animated/Easing.js +2 -0
  14. package/Libraries/Animated/NativeAnimatedAllowlist.js +1 -0
  15. package/Libraries/Animated/animations/Animation.js +19 -20
  16. package/Libraries/Animated/animations/TimingAnimation.js +2 -0
  17. package/Libraries/Animated/components/AnimatedScrollView.js +3 -2
  18. package/Libraries/Animated/components/AnimatedSectionList.js +1 -1
  19. package/Libraries/Animated/nodes/AnimatedColor.js +9 -9
  20. package/Libraries/Animated/nodes/AnimatedInterpolation.js +4 -4
  21. package/Libraries/Animated/nodes/AnimatedNode.js +14 -7
  22. package/Libraries/Animated/nodes/AnimatedObject.js +7 -7
  23. package/Libraries/Animated/nodes/AnimatedProps.js +32 -32
  24. package/Libraries/Animated/nodes/AnimatedStyle.js +23 -21
  25. package/Libraries/Animated/nodes/AnimatedTransform.js +6 -6
  26. package/Libraries/Animated/nodes/AnimatedValue.js +18 -26
  27. package/Libraries/AppState/AppState.js +8 -4
  28. package/Libraries/BatchedBridge/BatchedBridge.js +1 -0
  29. package/Libraries/BatchedBridge/MessageQueue.js +5 -0
  30. package/Libraries/BatchedBridge/NativeModules.js +1 -1
  31. package/Libraries/Blob/BlobManager.js +1 -1
  32. package/Libraries/Blob/URLSearchParams.js +2 -0
  33. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +2 -2
  34. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +2 -2
  35. package/Libraries/Components/Button.js +1 -1
  36. package/Libraries/Components/Button.win32.js +1 -1
  37. package/Libraries/Components/Pressable/Pressable.js +10 -1
  38. package/Libraries/Components/Pressable/Pressable.win32.js +9 -0
  39. package/Libraries/Components/Pressable/useAndroidRippleForView.js +2 -2
  40. package/Libraries/Components/ScrollView/ScrollView.js +13 -4
  41. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  42. package/Libraries/Components/StatusBar/StatusBar.js +2 -2
  43. package/Libraries/Components/Switch/Switch.js +1 -1
  44. package/Libraries/Components/TextInput/TextInput.flow.js +12 -5
  45. package/Libraries/Components/TextInput/TextInput.flow.win32.js +12 -5
  46. package/Libraries/Components/TextInput/TextInput.js +14 -5
  47. package/Libraries/Components/TextInput/TextInput.win32.js +15 -7
  48. package/Libraries/Components/TextInput/TextInputState.js +1 -1
  49. package/Libraries/Components/TextInput/TextInputState.win32.js +1 -1
  50. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +2 -3
  51. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  52. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  53. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  54. package/Libraries/Components/Touchable/TouchableOpacity.js +1 -1
  55. package/Libraries/Components/Touchable/TouchableWin32.js +1 -1
  56. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  57. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +3 -3
  58. package/Libraries/Components/View/View.js +81 -167
  59. package/Libraries/Components/View/View.win32.js +3 -1
  60. package/Libraries/Core/Devtools/loadBundleFromServer.js +1 -1
  61. package/Libraries/Core/Devtools/loadBundleFromServer.win32.js +1 -1
  62. package/Libraries/Core/ExceptionsManager.js +4 -2
  63. package/Libraries/Core/ReactFiberErrorDialog.js +3 -3
  64. package/Libraries/Core/ReactNativeVersion.js +37 -10
  65. package/Libraries/Core/Timers/JSTimers.js +4 -1
  66. package/Libraries/Core/Timers/NativeTiming.js +1 -0
  67. package/Libraries/Core/Timers/immediateShim.js +2 -1
  68. package/Libraries/Core/Timers/queueMicrotask.js +1 -0
  69. package/Libraries/Core/setUpPerformance.js +3 -4
  70. package/Libraries/Debugging/DebuggingOverlayRegistry.js +5 -3
  71. package/Libraries/Image/Image.android.js +327 -111
  72. package/Libraries/Image/Image.ios.js +6 -1
  73. package/Libraries/Image/Image.win32.js +6 -1
  74. package/Libraries/Image/ImageSourceUtils.js +8 -2
  75. package/Libraries/Image/assetPaths.js +1 -1
  76. package/Libraries/Image/resolveAssetSource.js +1 -1
  77. package/Libraries/Image/resolveAssetSource.win32.js +6 -7
  78. package/Libraries/Interaction/InteractionManager.js +118 -167
  79. package/Libraries/Interaction/PanResponder.js +7 -52
  80. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -0
  81. package/Libraries/Lists/FlatList.js +5 -6
  82. package/Libraries/LogBox/Data/LogBoxData.js +5 -2
  83. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  84. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +2 -2
  85. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +1 -1
  86. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js +1 -1
  87. package/Libraries/Modal/Modal.js +3 -3
  88. package/Libraries/NativeComponent/NativeComponentRegistry.js +1 -1
  89. package/Libraries/NativeComponent/ViewConfig.js +2 -2
  90. package/Libraries/Network/RCTNetworking.android.js +1 -1
  91. package/Libraries/Network/RCTNetworking.ios.js +1 -1
  92. package/Libraries/Network/RCTNetworking.win32.js +1 -1
  93. package/Libraries/Network/XMLHttpRequest.js +20 -5
  94. package/Libraries/Network/convertRequestBody.js +1 -1
  95. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +10 -9
  96. package/Libraries/Pressability/HoverState.js +2 -0
  97. package/Libraries/Pressability/HoverState.win32.js +2 -0
  98. package/Libraries/Pressability/Pressability.js +1 -1
  99. package/Libraries/Pressability/Pressability.win32.js +1 -1
  100. package/Libraries/PushNotificationIOS/PushNotificationIOS.js +2 -2
  101. package/Libraries/ReactNative/AppRegistryImpl.js +4 -2
  102. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -0
  103. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +3 -3
  104. package/Libraries/ReactNative/RendererImplementation.js +116 -116
  105. package/Libraries/ReactNative/UIManager.js +3 -3
  106. package/Libraries/ReactNative/renderApplication.js +1 -0
  107. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -1
  108. package/Libraries/Renderer/implementations/ReactFabric-dev.js +38 -35
  109. package/Libraries/Renderer/implementations/ReactFabric-prod.js +51 -22
  110. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +54 -24
  111. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +36 -33
  112. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5 -5
  113. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5 -5
  114. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  115. package/Libraries/Share/Share.js +4 -0
  116. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +2 -2
  117. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +2 -2
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +4 -0
  119. package/Libraries/StyleSheet/StyleSheet.d.ts +7 -22
  120. package/Libraries/StyleSheet/StyleSheetExports.js +2 -8
  121. package/Libraries/StyleSheet/StyleSheetExports.js.flow +11 -18
  122. package/Libraries/StyleSheet/flattenStyle.js +2 -2
  123. package/Libraries/StyleSheet/processAspectRatio.js +2 -0
  124. package/Libraries/StyleSheet/processFilter.js +5 -5
  125. package/Libraries/StyleSheet/splitLayoutProps.js +2 -2
  126. package/Libraries/Text/Text.js +534 -234
  127. package/Libraries/Text/Text.win32.js +647 -274
  128. package/Libraries/Text/TextNativeComponent.js +2 -2
  129. package/Libraries/Text/TextNativeComponent.win32.js +2 -2
  130. package/Libraries/Utilities/Appearance.d.ts +3 -5
  131. package/Libraries/Utilities/Appearance.js +5 -17
  132. package/Libraries/Utilities/HMRClient.js +2 -1
  133. package/Libraries/Utilities/Platform.android.js +3 -3
  134. package/Libraries/Utilities/Platform.d.ts +1 -0
  135. package/Libraries/Utilities/Platform.ios.js +1 -1
  136. package/Libraries/Utilities/Platform.win32.js +3 -3
  137. package/Libraries/Utilities/PlatformTypes.js +1 -1
  138. package/Libraries/Utilities/ReactNativeTestTools.js +12 -0
  139. package/Libraries/Utilities/SceneTracker.js +1 -1
  140. package/Libraries/Utilities/codegenNativeCommands.js +1 -1
  141. package/Libraries/Utilities/codegenNativeComponent.js +1 -1
  142. package/Libraries/Utilities/createPerformanceLogger.js +32 -0
  143. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  144. package/Libraries/Utilities/differ/pointsDiffer.js +1 -1
  145. package/Libraries/Utilities/useMergeRefs.js +1 -1
  146. package/Libraries/WebSocket/WebSocketInterceptor.js +2 -0
  147. package/Libraries/promiseRejectionTrackingOptions.js +17 -31
  148. package/Libraries/vendor/emitter/EventEmitter.js +1 -1
  149. package/flow/bom.js.flow +223 -1
  150. package/flow/prettier.js.flow +14 -0
  151. package/index.js +14 -2
  152. package/index.win32.js +16 -2
  153. package/jest/local-setup.js +2 -2
  154. package/jest/mock.js +1 -1
  155. package/jest/mockComponent.js +9 -9
  156. package/jest/mockNativeComponent.js +3 -2
  157. package/jest/mocks/Modal.js +1 -1
  158. package/jest/mocks/ScrollView.js +1 -1
  159. package/jest/mocks/ViewNativeComponent.js +1 -1
  160. package/jest/setup.js +23 -12
  161. package/overrides.json +23 -23
  162. package/package.json +28 -27
  163. package/saveAssetPlugin.js +2 -2
  164. package/src/private/animated/NativeAnimatedHelper.js +16 -5
  165. package/src/private/animated/NativeAnimatedHelper.win32.js +16 -5
  166. package/src/private/animated/createAnimatedPropsHook.js +11 -60
  167. package/src/private/animated/createAnimatedPropsMemoHook.js +8 -54
  168. package/src/private/components/virtualview/VirtualView.js +43 -12
  169. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +93 -0
  170. package/src/private/components/virtualview/VirtualViewNativeComponent.js +6 -0
  171. package/src/private/devsupport/devmenu/elementinspector/Inspector.js +2 -2
  172. package/src/private/devsupport/devmenu/elementinspector/ReactDevToolsOverlay.js +2 -2
  173. package/src/private/featureflags/ReactNativeFeatureFlags.js +85 -52
  174. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  175. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +15 -6
  176. package/src/private/renderer/errorhandling/ErrorHandlers.js +3 -3
  177. package/src/private/setup/{setUpPerformanceObserver.js → setUpPerformanceModern.js} +43 -18
  178. package/src/private/specs_DEPRECATED/modules/NativeTiming.js +1 -0
  179. package/src/private/types/HostInstance.js +4 -1
  180. package/src/private/webapis/dom/nodes/ReactNativeDocument.js +22 -2
  181. package/src/private/webapis/dom/nodes/ReactNativeElement.js +1 -1
  182. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +5 -3
  183. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +16 -13
  184. package/src/private/webapis/dom/nodes/internals/NodeInternals.js +45 -22
  185. package/src/private/webapis/dom/nodes/internals/ReactNativeDocumentInstanceHandle.js +1 -1
  186. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +26 -192
  187. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +15 -12
  188. package/src/private/webapis/dom/oldstylecollections/NodeList.js +14 -11
  189. package/src/private/webapis/geometry/DOMRectList.js +2 -2
  190. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +19 -74
  191. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +0 -4
  192. package/src/private/webapis/mutationobserver/internals/MutationObserverManager.js +1 -1
  193. package/src/private/webapis/performance/EventTiming.js +40 -25
  194. package/src/private/webapis/performance/LongTasks.js +35 -2
  195. package/src/private/webapis/performance/Performance.js +347 -166
  196. package/src/private/webapis/performance/PerformanceEntry.js +40 -23
  197. package/src/private/webapis/performance/PerformanceObserver.js +37 -29
  198. package/src/private/webapis/performance/ReactNativeStartupTiming.js +3 -24
  199. package/src/private/webapis/performance/ResourceTiming.js +29 -18
  200. package/src/private/webapis/performance/UserTiming.js +92 -34
  201. package/src/private/webapis/performance/UserTimingExtensibility.js.flow +38 -0
  202. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +3 -4
  203. package/src/private/webapis/performance/internals/Utilities.js +9 -0
  204. package/src/private/webapis/performance/specs/NativePerformance.js +23 -23
  205. package/src/private/webapis/structuredClone/structuredClone.js +10 -10
  206. package/src-win/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  207. package/Libraries/Interaction/InteractionManagerStub.js +0 -184
  208. package/Libraries/Interaction/TaskQueue.js +0 -183
  209. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -31
@@ -14,9 +14,9 @@ import type {RootTag} from '../../../../../Libraries/ReactNative/RootTag';
14
14
  import type {ViewConfig} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
15
15
  import type HTMLCollection from '../oldstylecollections/HTMLCollection';
16
16
  import type {ReactNativeDocumentInstanceHandle} from './internals/ReactNativeDocumentInstanceHandle';
17
- import type ReadOnlyElement from './ReadOnlyElement';
18
17
 
19
18
  import {createHTMLCollection} from '../oldstylecollections/HTMLCollection';
19
+ import {getPublicInstanceFromInstanceHandle} from './internals/NodeInternals';
20
20
  import {
21
21
  createReactNativeDocumentElementInstanceHandle,
22
22
  setNativeElementReferenceForReactNativeDocumentElementInstanceHandle,
@@ -24,10 +24,12 @@ import {
24
24
  } from './internals/ReactNativeDocumentElementInstanceHandle';
25
25
  import {createReactNativeDocumentInstanceHandle} from './internals/ReactNativeDocumentInstanceHandle';
26
26
  import ReactNativeElement from './ReactNativeElement';
27
+ import ReadOnlyElement from './ReadOnlyElement';
27
28
  import ReadOnlyNode from './ReadOnlyNode';
28
29
  import NativeDOM from './specs/NativeDOM';
29
30
 
30
31
  export default class ReactNativeDocument extends ReadOnlyNode {
32
+ _rootTag: RootTag;
31
33
  _documentElement: ReactNativeElement;
32
34
 
33
35
  constructor(
@@ -35,6 +37,7 @@ export default class ReactNativeDocument extends ReadOnlyNode {
35
37
  instanceHandle: ReactNativeDocumentInstanceHandle,
36
38
  ) {
37
39
  super(instanceHandle, null);
40
+ this._rootTag = rootTag;
38
41
  this._documentElement = createDocumentElement(rootTag, this);
39
42
  }
40
43
 
@@ -71,10 +74,27 @@ export default class ReactNativeDocument extends ReadOnlyNode {
71
74
  return null;
72
75
  }
73
76
 
74
- // $FlowExpectedError[incompatible-extend] This is defined as returning string in Node, but it's actually null in Document.
77
+ // $FlowExpectedError[incompatible-type] This is defined as returning string in Node, but it's actually null in Document.
75
78
  get textContent(): null {
76
79
  return null;
77
80
  }
81
+
82
+ getElementById(id: string): ReadOnlyElement | null {
83
+ const elementByIdInstanceHandle = NativeDOM.getElementById(
84
+ this._rootTag,
85
+ id,
86
+ );
87
+
88
+ if (elementByIdInstanceHandle == null) {
89
+ return null;
90
+ }
91
+
92
+ const elementById = getPublicInstanceFromInstanceHandle(
93
+ elementByIdInstanceHandle,
94
+ );
95
+
96
+ return elementById instanceof ReadOnlyElement ? elementById : null;
97
+ }
78
98
  }
79
99
 
80
100
  function createDocumentElement(
@@ -233,7 +233,7 @@ function replaceConstructorWithoutSuper(
233
233
 
234
234
  ReactNativeElement.prototype = ReactNativeElementClass.prototype;
235
235
 
236
- // $FlowExpectedError[incompatible-return]
236
+ // $FlowExpectedError[incompatible-type]
237
237
  return ReactNativeElement;
238
238
  }
239
239
 
@@ -220,9 +220,11 @@ export default class ReadOnlyElement extends ReadOnlyNode {
220
220
  }
221
221
 
222
222
  function getChildElements(node: ReadOnlyNode): $ReadOnlyArray<ReadOnlyElement> {
223
- // $FlowIssue[incompatible-call]
224
- return getChildNodes(node).filter(
225
- childNode => childNode instanceof ReadOnlyElement,
223
+ // $FlowFixMe[incompatible-type]
224
+ return getChildNodes(
225
+ node,
226
+ (childNode: ReadOnlyNode) =>
227
+ childNode.nodeType === ReadOnlyNode.ELEMENT_NODE,
226
228
  );
227
229
  }
228
230
 
@@ -118,7 +118,11 @@ export default class ReadOnlyNode {
118
118
  get parentElement(): ReadOnlyElement | null {
119
119
  const parentNode = this.parentNode;
120
120
 
121
- if (parentNode instanceof getReadOnlyElementClass()) {
121
+ if (
122
+ parentNode != null &&
123
+ parentNode.nodeType === ReadOnlyNode.ELEMENT_NODE
124
+ ) {
125
+ // $FlowExpectedError[incompatible-type] parentNode is an instance of ReadOnlyElement as per the `nodeType` check
122
126
  return parentNode;
123
127
  }
124
128
 
@@ -292,6 +296,7 @@ setPlatformObject(ReadOnlyNode);
292
296
 
293
297
  export function getChildNodes(
294
298
  node: ReadOnlyNode,
299
+ filter?: (node: ReadOnlyNode) => boolean,
295
300
  ): $ReadOnlyArray<ReadOnlyNode> {
296
301
  const shadowNode = getNativeNodeReference(node);
297
302
 
@@ -300,9 +305,16 @@ export function getChildNodes(
300
305
  }
301
306
 
302
307
  const childNodeInstanceHandles = NativeDOM.getChildNodes(shadowNode);
303
- return childNodeInstanceHandles
304
- .map(instanceHandle => getPublicInstanceFromInstanceHandle(instanceHandle))
305
- .filter(Boolean);
308
+ const childNodes = [];
309
+ for (const childNodeInstanceHandle of childNodeInstanceHandles) {
310
+ const childNode = getPublicInstanceFromInstanceHandle(
311
+ childNodeInstanceHandle,
312
+ );
313
+ if (childNode != null && (filter == null || filter(childNode))) {
314
+ childNodes.push(childNode);
315
+ }
316
+ }
317
+ return childNodes;
306
318
  }
307
319
 
308
320
  function getNodeSiblingsAndPosition(
@@ -323,12 +335,3 @@ function getNodeSiblingsAndPosition(
323
335
 
324
336
  return [siblings, position];
325
337
  }
326
-
327
- let ReadOnlyElementClass;
328
- function getReadOnlyElementClass(): Class<ReadOnlyElement> {
329
- if (ReadOnlyElementClass == null) {
330
- // We initialize this lazily to avoid a require cycle.
331
- ReadOnlyElementClass = require('./ReadOnlyElement').default;
332
- }
333
- return ReadOnlyElementClass;
334
- }
@@ -37,14 +37,30 @@ export type InstanceHandle =
37
37
  | ReactNativeDocumentElementInstanceHandle // root element managed by React Native
38
38
  | ReactNativeDocumentInstanceHandle; // document node managed by React Native
39
39
 
40
- let RendererProxy;
41
- function getRendererProxy() {
42
- if (RendererProxy == null) {
40
+ let cachedGetNodeFromInternalInstanceHandle;
41
+ function getNodeFromInternalInstanceHandle(
42
+ instanceHandle: InternalInstanceHandle,
43
+ ) {
44
+ if (cachedGetNodeFromInternalInstanceHandle == null) {
43
45
  // Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects.
44
46
  // With a static import we can't use these classes for Paper-only variants.
45
- RendererProxy = require('../../../../../../Libraries/ReactNative/RendererProxy');
47
+ cachedGetNodeFromInternalInstanceHandle =
48
+ require('../../../../../../Libraries/ReactNative/RendererProxy').getNodeFromInternalInstanceHandle;
46
49
  }
47
- return RendererProxy;
50
+ return cachedGetNodeFromInternalInstanceHandle(instanceHandle);
51
+ }
52
+
53
+ let cachedGetPublicInstanceFromInternalInstanceHandle;
54
+ function getPublicInstanceFromInternalInstanceHandle(
55
+ instanceHandle: InternalInstanceHandle,
56
+ ) {
57
+ if (cachedGetPublicInstanceFromInternalInstanceHandle == null) {
58
+ // Lazy import Fabric here to avoid DOM Node APIs classes from having side-effects.
59
+ // With a static import we can't use these classes for Paper-only variants.
60
+ cachedGetPublicInstanceFromInternalInstanceHandle =
61
+ require('../../../../../../Libraries/ReactNative/RendererProxy').getPublicInstanceFromInternalInstanceHandle;
62
+ }
63
+ return cachedGetPublicInstanceFromInternalInstanceHandle(instanceHandle);
48
64
  }
49
65
 
50
66
  const INSTANCE_HANDLE_KEY = Symbol('internalInstanceHandle');
@@ -81,6 +97,15 @@ export function setOwnerDocument(
81
97
  export function getPublicInstanceFromInstanceHandle(
82
98
  instanceHandle: InstanceHandle,
83
99
  ): ?ReadOnlyNode {
100
+ const mixedPublicInstance =
101
+ // $FlowExpectedError[incompatible-type]
102
+ getPublicInstanceFromInternalInstanceHandle(instanceHandle);
103
+
104
+ if (mixedPublicInstance != null) {
105
+ // $FlowExpectedError[incompatible-type] React defines public instances as "mixed" because it can't access the definition from React Native.
106
+ return mixedPublicInstance;
107
+ }
108
+
84
109
  if (isReactNativeDocumentInstanceHandle(instanceHandle)) {
85
110
  return getPublicInstanceFromReactNativeDocumentInstanceHandle(
86
111
  instanceHandle,
@@ -92,14 +117,6 @@ export function getPublicInstanceFromInstanceHandle(
92
117
  instanceHandle,
93
118
  );
94
119
  }
95
-
96
- const mixedPublicInstance =
97
- getRendererProxy().getPublicInstanceFromInternalInstanceHandle(
98
- instanceHandle,
99
- );
100
-
101
- // $FlowExpectedError[incompatible-return] React defines public instances as "mixed" because it can't access the definition from React Native.
102
- return mixedPublicInstance;
103
120
  }
104
121
 
105
122
  export function getNativeNodeReference(
@@ -107,6 +124,15 @@ export function getNativeNodeReference(
107
124
  ): ?NativeNodeReference {
108
125
  const instanceHandle = getInstanceHandle(node);
109
126
 
127
+ // Try React nodes first
128
+ const nativeReference =
129
+ // $FlowExpectedError[incompatible-type]
130
+ getNodeFromInternalInstanceHandle(instanceHandle);
131
+ if (nativeReference != null) {
132
+ // $FlowExpectedError[incompatible-type]
133
+ return nativeReference;
134
+ }
135
+
110
136
  if (isReactNativeDocumentInstanceHandle(instanceHandle)) {
111
137
  return getNativeNodeReferenceFromReactNativeDocumentInstanceHandle(
112
138
  instanceHandle,
@@ -118,15 +144,12 @@ export function getNativeNodeReference(
118
144
  instanceHandle,
119
145
  );
120
146
  }
121
-
122
- // $FlowExpectedError[incompatible-return]
123
- return getRendererProxy().getNodeFromInternalInstanceHandle(instanceHandle);
124
147
  }
125
148
 
126
149
  export function getNativeElementReference(
127
150
  node: ReadOnlyElement,
128
151
  ): ?NativeElementReference {
129
- // $FlowExpectedError[incompatible-cast] We know ReadOnlyElement instances provide InternalInstanceHandle
152
+ // $FlowExpectedError[incompatible-type] We know ReadOnlyElement instances provide InternalInstanceHandle
130
153
  const instanceHandle = getInstanceHandle(node) as InternalInstanceHandle;
131
154
 
132
155
  if (isReactNativeDocumentElementInstanceHandle(instanceHandle)) {
@@ -135,16 +158,16 @@ export function getNativeElementReference(
135
158
  );
136
159
  }
137
160
 
138
- // $FlowExpectedError[incompatible-return]
139
- return getRendererProxy().getNodeFromInternalInstanceHandle(instanceHandle);
161
+ // $FlowExpectedError[incompatible-type]
162
+ return getNodeFromInternalInstanceHandle(instanceHandle);
140
163
  }
141
164
 
142
165
  export function getNativeTextReference(
143
166
  node: ReadOnlyCharacterData,
144
167
  ): ?NativeTextReference {
145
- // $FlowExpectedError[incompatible-cast] We know ReadOnlyText instances provide InternalInstanceHandle
168
+ // $FlowExpectedError[incompatible-type] We know ReadOnlyText instances provide InternalInstanceHandle
146
169
  const instanceHandle = getInstanceHandle(node) as InternalInstanceHandle;
147
170
 
148
- // $FlowExpectedError[incompatible-return]
149
- return getRendererProxy().getNodeFromInternalInstanceHandle(instanceHandle);
171
+ // $FlowExpectedError[incompatible-type]
172
+ return getNodeFromInternalInstanceHandle(instanceHandle);
150
173
  }
@@ -31,7 +31,7 @@ export function getNativeNodeReferenceFromReactNativeDocumentInstanceHandle(
31
31
  export function getPublicInstanceFromReactNativeDocumentInstanceHandle(
32
32
  instanceHandle: ReactNativeDocumentInstanceHandle,
33
33
  ): ?ReactNativeDocument {
34
- // $FlowExpectedError[incompatible-return] React defines public instances as "mixed" because it can't access the definition from React Native.
34
+ // $FlowExpectedError[incompatible-type] React defines public instances as "mixed" because it can't access the definition from React Native.
35
35
  return RendererProxy.getPublicInstanceFromRootTag(Number(instanceHandle));
36
36
  }
37
37
 
@@ -13,9 +13,7 @@ import type {Node as ShadowNode} from '../../../../../../Libraries/Renderer/shim
13
13
  import type {TurboModule} from '../../../../../../Libraries/TurboModule/RCTExport';
14
14
  import type {InstanceHandle} from '../internals/NodeInternals';
15
15
 
16
- import {getFabricUIManager} from '../../../../../../Libraries/ReactNative/FabricUIManager';
17
16
  import * as TurboModuleRegistry from '../../../../../../Libraries/TurboModule/TurboModuleRegistry';
18
- import nullthrows from 'nullthrows';
19
17
 
20
18
  export opaque type NativeElementReference = ShadowNode;
21
19
  export opaque type NativeTextReference = ShadowNode;
@@ -62,6 +60,11 @@ export interface Spec extends TurboModule {
62
60
  nativeNodeReference: mixed /* NativeNodeReference */,
63
61
  ) => $ReadOnlyArray<mixed> /* $ReadOnlyArray<InstanceHandle> */;
64
62
 
63
+ +getElementById?: (
64
+ nativeNodeReference: mixed /* NativeNodeReference */,
65
+ id: string,
66
+ ) => mixed /* ?InstanceHandle */;
67
+
65
68
  +getParentNode: (
66
69
  nativeNodeReference: mixed /* NativeNodeReference */,
67
70
  ) => mixed /* ?InstanceHandle */;
@@ -160,18 +163,12 @@ export interface Spec extends TurboModule {
160
163
  * Legacy direct manipulation APIs (for `ReactNativeElement`).
161
164
  */
162
165
 
163
- +setNativeProps?: (
166
+ +setNativeProps: (
164
167
  nativeElementReference: mixed,
165
168
  updatePayload: mixed,
166
169
  ) => void;
167
170
  }
168
171
 
169
- const RawNativeDOM = (TurboModuleRegistry.get<Spec>('NativeDOMCxx'): ?Spec);
170
-
171
- export function getRawNativeDOMForTests(): ?Spec {
172
- return RawNativeDOM;
173
- }
174
-
175
172
  // This is the actual interface of this module, but the native module codegen
176
173
  // isn't expressive enough yet.
177
174
  export interface RefinedSpec {
@@ -204,6 +201,15 @@ export interface RefinedSpec {
204
201
  nativeNodeReference: NativeNodeReference,
205
202
  ) => $ReadOnlyArray<InstanceHandle>;
206
203
 
204
+ /**
205
+ * This is a React Native implementation of `Document.prototype.getElementById`
206
+ * (see https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById).
207
+ *
208
+ * If the document is active and contains an element with the given ID, it
209
+ * returns the instance handle of that element. Otherwise, it returns `null`.
210
+ */
211
+ +getElementById: (rootTag: RootTag, id: string) => ?InstanceHandle;
212
+
207
213
  /**
208
214
  * This is a React Native implementation of `Node.prototype.parentNode`
209
215
  * (see https://developer.mozilla.org/en-US/docs/Web/API/Node/parentNode).
@@ -432,186 +438,14 @@ export interface RefinedSpec {
432
438
  ) => void;
433
439
  }
434
440
 
435
- const NativeDOM: RefinedSpec = {
436
- /*
437
- * Methods from the `Node` interface (for `ReadOnlyNode`).
438
- */
439
-
440
- compareDocumentPosition(nativeNodeReference, otherNativeNodeReference) {
441
- return nullthrows(RawNativeDOM).compareDocumentPosition(
442
- nativeNodeReference,
443
- otherNativeNodeReference,
444
- );
445
- },
446
-
447
- getChildNodes(nativeNodeReference) {
448
- // $FlowExpectedError[incompatible-cast]
449
- return (nullthrows(RawNativeDOM).getChildNodes(
450
- nativeNodeReference,
451
- ): $ReadOnlyArray<InstanceHandle>);
452
- },
453
-
454
- getParentNode(nativeNodeReference) {
455
- // $FlowExpectedError[incompatible-cast]
456
- return (nullthrows(RawNativeDOM).getParentNode(
457
- nativeNodeReference,
458
- ): ?InstanceHandle);
459
- },
460
-
461
- isConnected(nativeNodeReference) {
462
- return nullthrows(RawNativeDOM).isConnected(nativeNodeReference);
463
- },
464
-
465
- /*
466
- * Methods from the `Element` interface (for `ReactNativeElement`).
467
- */
468
-
469
- getBorderWidth(nativeNodeReference) {
470
- // $FlowExpectedError[incompatible-cast]
471
- return (nullthrows(RawNativeDOM).getBorderWidth(
472
- nativeNodeReference,
473
- ): $ReadOnly<
474
- [
475
- /* topWidth: */ number,
476
- /* rightWidth: */ number,
477
- /* bottomWidth: */ number,
478
- /* leftWidth: */ number,
479
- ],
480
- >);
481
- },
482
-
483
- getBoundingClientRect(nativeNodeReference, includeTransform: boolean) {
484
- // $FlowExpectedError[incompatible-cast]
485
- return (nullthrows(RawNativeDOM).getBoundingClientRect(
486
- nativeNodeReference,
487
- includeTransform,
488
- ): $ReadOnly<
489
- [
490
- /* x: */ number,
491
- /* y: */ number,
492
- /* width: */ number,
493
- /* height: */ number,
494
- ],
495
- >);
496
- },
497
-
498
- getInnerSize(nativeNodeReference) {
499
- // $FlowExpectedError[incompatible-cast]
500
- return (nullthrows(RawNativeDOM).getInnerSize(
501
- nativeNodeReference,
502
- ): $ReadOnly<[/* width: */ number, /* height: */ number]>);
503
- },
504
-
505
- getScrollPosition(nativeNodeReference) {
506
- // $FlowExpectedError[incompatible-cast]
507
- return (nullthrows(RawNativeDOM).getScrollPosition(
508
- nativeNodeReference,
509
- ): $ReadOnly<[/* scrollLeft: */ number, /* scrollTop: */ number]>);
510
- },
511
-
512
- getScrollSize(nativeNodeReference) {
513
- // $FlowExpectedError[incompatible-cast]
514
- return (nullthrows(RawNativeDOM).getScrollSize(
515
- nativeNodeReference,
516
- ): $ReadOnly<[/* scrollWidth: */ number, /* scrollHeight: */ number]>);
517
- },
518
-
519
- getTagName(nativeNodeReference) {
520
- return nullthrows(RawNativeDOM).getTagName(nativeNodeReference);
521
- },
522
-
523
- getTextContent(nativeNodeReference) {
524
- return nullthrows(RawNativeDOM).getTextContent(nativeNodeReference);
525
- },
526
-
527
- hasPointerCapture(nativeNodeReference, pointerId) {
528
- return nullthrows(RawNativeDOM).hasPointerCapture(
529
- nativeNodeReference,
530
- pointerId,
531
- );
532
- },
533
-
534
- releasePointerCapture(nativeNodeReference, pointerId) {
535
- return nullthrows(RawNativeDOM).releasePointerCapture(
536
- nativeNodeReference,
537
- pointerId,
538
- );
539
- },
540
-
541
- setPointerCapture(nativeNodeReference, pointerId) {
542
- return nullthrows(RawNativeDOM).setPointerCapture(
543
- nativeNodeReference,
544
- pointerId,
545
- );
546
- },
547
-
548
- /*
549
- * Methods from the `HTMLElement` interface (for `ReactNativeElement`).
550
- */
551
-
552
- getOffset(nativeNodeReference) {
553
- // $FlowExpectedError[incompatible-cast]
554
- return (nullthrows(RawNativeDOM).getOffset(nativeNodeReference): $ReadOnly<
555
- [
556
- /* offsetParent: */ ?InstanceHandle,
557
- /* top: */ number,
558
- /* left: */ number,
559
- ],
560
- >);
561
- },
562
-
563
- /*
564
- * Special methods to handle the root node.
565
- */
566
-
567
- linkRootNode(rootTag, instanceHandle) {
568
- // $FlowExpectedError[incompatible-cast]
569
- return (nullthrows(RawNativeDOM?.linkRootNode)(
570
- // $FlowExpectedError[incompatible-call]
571
- rootTag,
572
- instanceHandle,
573
- ): ?NativeElementReference);
574
- },
575
-
576
- /**
577
- * Legacy layout APIs
578
- */
579
-
580
- measure(nativeNodeReference, callback) {
581
- return nullthrows(RawNativeDOM).measure(nativeNodeReference, callback);
582
- },
583
-
584
- measureInWindow(nativeNodeReference, callback) {
585
- return nullthrows(RawNativeDOM).measureInWindow(
586
- nativeNodeReference,
587
- callback,
588
- );
589
- },
590
-
591
- measureLayout(nativeNodeReference, relativeNode, onFail, onSuccess) {
592
- return nullthrows(RawNativeDOM).measureLayout(
593
- nativeNodeReference,
594
- relativeNode,
595
- onFail,
596
- onSuccess,
597
- );
598
- },
599
-
600
- /**
601
- * Legacy direct manipulation APIs
602
- */
603
- setNativeProps(nativeNodeReference, updatePayload) {
604
- // TODO: remove when RawNativeDOM.setNativeProps is NOT nullable.
605
- if (RawNativeDOM?.setNativeProps == null) {
606
- nullthrows(getFabricUIManager()).setNativeProps(
607
- nativeNodeReference,
608
- updatePayload,
609
- );
610
- return;
611
- }
612
-
613
- return RawNativeDOM.setNativeProps(nativeNodeReference, updatePayload);
614
- },
615
- };
616
-
617
- export default NativeDOM;
441
+ // We used to implement all methods in RefineSpec, manually refining the types
442
+ // for all methods. However, this is slower as every call to the native module
443
+ // requires an additional call only to handle types. Instead, we do an unsafe
444
+ // casting here. Keep in mind that:
445
+ // 1. We use `get` and not `getEnforcing` because we don't want to fail when
446
+ // the module is evaluated, only when used. This is necessary because we
447
+ // don't use inline requires within the `react-native` package and some code
448
+ // might end up loading this but not using it.
449
+ // 2. We lose automatic backwards compatibility checks because of this.
450
+ // $FlowExpectedError[incompatible-type]
451
+ export default (TurboModuleRegistry.get<Spec>('NativeDOMCxx'): RefinedSpec);
@@ -18,9 +18,16 @@ import {setPlatformObject} from '../../webidl/PlatformObjects';
18
18
  // IMPORTANT: The type definition for this module is defined in `HTMLCollection.js.flow`
19
19
  // because Flow only supports indexers in classes in declaration files.
20
20
 
21
- // $FlowIssue[prop-missing] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable<T> interface.
21
+ const REUSABLE_PROPERTY_DESCRIPTOR: {...PropertyDescriptor<mixed>, ...} = {
22
+ value: {},
23
+ enumerable: true,
24
+ configurable: false,
25
+ writable: false,
26
+ };
27
+
28
+ // $FlowFixMe[incompatible-type] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable<T> interface.
22
29
  export default class HTMLCollection<T> implements Iterable<T>, ArrayLike<T> {
23
- #length: number;
30
+ _length: number;
24
31
 
25
32
  /**
26
33
  * Use `createHTMLCollection` to create instances of this class.
@@ -30,23 +37,19 @@ export default class HTMLCollection<T> implements Iterable<T>, ArrayLike<T> {
30
37
  */
31
38
  constructor(elements: $ReadOnlyArray<T>) {
32
39
  for (let i = 0; i < elements.length; i++) {
33
- Object.defineProperty(this, i, {
34
- value: elements[i],
35
- enumerable: true,
36
- configurable: false,
37
- writable: false,
38
- });
40
+ REUSABLE_PROPERTY_DESCRIPTOR.value = elements[i];
41
+ Object.defineProperty(this, i, REUSABLE_PROPERTY_DESCRIPTOR);
39
42
  }
40
43
 
41
- this.#length = elements.length;
44
+ this._length = elements.length;
42
45
  }
43
46
 
44
47
  get length(): number {
45
- return this.#length;
48
+ return this._length;
46
49
  }
47
50
 
48
51
  item(index: number): T | null {
49
- if (index < 0 || index >= this.#length) {
52
+ if (index < 0 || index >= this._length) {
50
53
  return null;
51
54
  }
52
55
 
@@ -64,7 +67,7 @@ export default class HTMLCollection<T> implements Iterable<T>, ArrayLike<T> {
64
67
  return null;
65
68
  }
66
69
 
67
- // $FlowIssue[unsupported-syntax] Flow does not support computed properties in classes.
70
+ // $FlowFixMe[unsupported-syntax] Flow does not support computed properties in classes.
68
71
  [Symbol.iterator](): Iterator<T> {
69
72
  return createValueIterator(this);
70
73
  }
@@ -22,9 +22,14 @@ import {setPlatformObject} from '../../webidl/PlatformObjects';
22
22
  // IMPORTANT: The Flow type definition for this module is defined in `NodeList.js.flow`
23
23
  // because Flow only supports indexers in classes in declaration files.
24
24
 
25
- // $FlowIssue[prop-missing] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable<T> interface.
25
+ const REUSABLE_PROPERTY_DESCRIPTOR: {...PropertyDescriptor<mixed>, ...} = {
26
+ value: {},
27
+ writable: false,
28
+ };
29
+
30
+ // $FlowFixMe[incompatible-type] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable<T> interface.
26
31
  export default class NodeList<T> implements Iterable<T>, ArrayLike<T> {
27
- #length: number;
32
+ _length: number;
28
33
 
29
34
  /**
30
35
  * Use `createNodeList` to create instances of this class.
@@ -34,20 +39,18 @@ export default class NodeList<T> implements Iterable<T>, ArrayLike<T> {
34
39
  */
35
40
  constructor(elements: $ReadOnlyArray<T>) {
36
41
  for (let i = 0; i < elements.length; i++) {
37
- Object.defineProperty(this, i, {
38
- value: elements[i],
39
- writable: false,
40
- });
42
+ REUSABLE_PROPERTY_DESCRIPTOR.value = elements[i];
43
+ Object.defineProperty(this, i, REUSABLE_PROPERTY_DESCRIPTOR);
41
44
  }
42
- this.#length = elements.length;
45
+ this._length = elements.length;
43
46
  }
44
47
 
45
48
  get length(): number {
46
- return this.#length;
49
+ return this._length;
47
50
  }
48
51
 
49
52
  item(index: number): T | null {
50
- if (index < 0 || index >= this.#length) {
53
+ if (index < 0 || index >= this._length) {
51
54
  return null;
52
55
  }
53
56
 
@@ -71,7 +74,7 @@ export default class NodeList<T> implements Iterable<T>, ArrayLike<T> {
71
74
  // eslint-disable-next-line consistent-this
72
75
  const arrayLike: ArrayLike<T> = this;
73
76
 
74
- for (let index = 0; index < this.#length; index++) {
77
+ for (let index = 0; index < this._length; index++) {
75
78
  if (thisArg == null) {
76
79
  callbackFn(arrayLike[index], index, this);
77
80
  } else {
@@ -88,7 +91,7 @@ export default class NodeList<T> implements Iterable<T>, ArrayLike<T> {
88
91
  return createValueIterator(this);
89
92
  }
90
93
 
91
- // $FlowIssue[unsupported-syntax] Flow does not support computed properties in classes.
94
+ // $FlowFixMe[unsupported-syntax] Flow does not support computed properties in classes.
92
95
  [Symbol.iterator](): Iterator<T> {
93
96
  return createValueIterator(this);
94
97
  }
@@ -19,7 +19,7 @@ import {setPlatformObject} from '../webidl/PlatformObjects';
19
19
  // IMPORTANT: The Flow type definition for this module is defined in `DOMRectList.js.flow`
20
20
  // because Flow only supports indexers in classes in declaration files.
21
21
 
22
- // $FlowIssue[prop-missing] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable interface.
22
+ // $FlowFixMe[incompatible-type] Flow doesn't understand [Symbol.iterator]() {} and thinks this class doesn't implement the Iterable interface.
23
23
  export default class DOMRectList implements Iterable<DOMRectReadOnly> {
24
24
  #length: number;
25
25
 
@@ -58,7 +58,7 @@ export default class DOMRectList implements Iterable<DOMRectReadOnly> {
58
58
  return arrayLike[index];
59
59
  }
60
60
 
61
- // $FlowIssue[unsupported-syntax] Flow does not support computed properties in classes.
61
+ // $FlowFixMe[unsupported-syntax] Flow does not support computed properties in classes.
62
62
  [Symbol.iterator](): Iterator<DOMRectReadOnly> {
63
63
  return createValueIterator(this);
64
64
  }