@office-iss/react-native-win32 0.0.0-canary.296 → 0.0.0-canary.297

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 (141) hide show
  1. package/.flowconfig +3 -1
  2. package/CHANGELOG.json +22 -1
  3. package/CHANGELOG.md +13 -4
  4. package/Libraries/Animated/Animated.js +0 -1
  5. package/Libraries/Animated/Animated.js.flow +0 -1
  6. package/Libraries/Animated/AnimatedExports.js +0 -1
  7. package/Libraries/Animated/AnimatedExports.js.flow +1 -2
  8. package/Libraries/Animated/animations/Animation.js +5 -2
  9. package/Libraries/Animated/components/AnimatedScrollView.js +53 -52
  10. package/Libraries/Animated/createAnimatedComponent.js +37 -33
  11. package/Libraries/Animated/nodes/AnimatedObject.js +2 -3
  12. package/Libraries/Animated/nodes/AnimatedProps.js +1 -1
  13. package/Libraries/Animated/shouldUseTurboAnimatedModule.js +6 -1
  14. package/Libraries/AppState/AppState.js +6 -1
  15. package/Libraries/Components/ActivityIndicator/ActivityIndicator.js +19 -18
  16. package/Libraries/Components/Button.js +2 -2
  17. package/Libraries/Components/Button.win32.js +2 -2
  18. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +2 -3
  19. package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +2 -1
  20. package/Libraries/Components/LayoutConformance/LayoutConformance.js +0 -1
  21. package/Libraries/Components/Pressable/Pressable.js +9 -6
  22. package/Libraries/Components/Pressable/Pressable.win32.js +9 -6
  23. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +14 -13
  24. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js +13 -1
  25. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidTypes.js +29 -20
  26. package/Libraries/Components/ScrollView/ScrollView.d.ts +9 -5
  27. package/Libraries/Components/ScrollView/ScrollView.js +18 -12
  28. package/Libraries/Components/ScrollView/ScrollViewContext.js +2 -1
  29. package/Libraries/Components/ScrollView/ScrollViewNativeComponentType.js +1 -1
  30. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +19 -6
  31. package/Libraries/Components/Switch/Switch.js +8 -2
  32. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +1 -5
  33. package/Libraries/Components/TextInput/TextInput.flow.js +1 -5
  34. package/Libraries/Components/TextInput/TextInput.flow.win32.js +1 -5
  35. package/Libraries/Components/TextInput/TextInput.js +26 -25
  36. package/Libraries/Components/TextInput/TextInput.win32.js +27 -25
  37. package/Libraries/Components/Touchable/TouchableBounce.js +9 -3
  38. package/Libraries/Components/Touchable/TouchableHighlight.js +9 -4
  39. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +2 -1
  40. package/Libraries/Components/Touchable/TouchableNativeFeedback.win32.js +2 -0
  41. package/Libraries/Components/Touchable/TouchableOpacity.js +7 -3
  42. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +2 -2
  43. package/Libraries/Components/View/View.js +111 -25
  44. package/Libraries/Core/Devtools/loadBundleFromServer.js +49 -7
  45. package/Libraries/Core/Devtools/loadBundleFromServer.win32.js +49 -7
  46. package/Libraries/Core/InitializeCore.js +1 -22
  47. package/Libraries/Core/ReactNativeVersion.js +3 -2
  48. package/Libraries/Debugging/DebuggingOverlay.js +6 -8
  49. package/Libraries/Debugging/DebuggingOverlayRegistry.js +0 -1
  50. package/Libraries/Debugging/useSubscribeToDebuggingOverlayRegistry.js +0 -1
  51. package/Libraries/EventEmitter/NativeEventEmitter.js +1 -1
  52. package/Libraries/Image/AssetRegistry.js +4 -10
  53. package/Libraries/Image/AssetSourceResolver.js +17 -4
  54. package/Libraries/Image/Image.android.js +112 -106
  55. package/Libraries/Image/Image.ios.js +10 -2
  56. package/Libraries/Image/Image.win32.js +11 -3
  57. package/Libraries/Image/ImageAnalyticsTagContext.js +2 -2
  58. package/Libraries/Image/RelativeImageStub.js +1 -0
  59. package/Libraries/Lists/FlatList.d.ts +9 -5
  60. package/Libraries/Lists/FlatList.js +1 -1
  61. package/Libraries/Lists/SectionListModern.js +9 -3
  62. package/Libraries/LogBox/UI/LogBoxButton.js +2 -1
  63. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js +2 -1
  64. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.win32.js +2 -1
  65. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +3 -2
  66. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js +3 -2
  67. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +2 -1
  68. package/Libraries/ReactNative/AppContainer-dev.js +4 -4
  69. package/Libraries/ReactNative/AppContainer-prod.js +0 -1
  70. package/Libraries/ReactNative/RootTag.js +2 -2
  71. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -0
  72. package/Libraries/Renderer/shims/ReactNativeTypes.js +21 -25
  73. package/Libraries/Renderer/shims/ReactNativeTypes.win32.js +270 -0
  74. package/Libraries/StyleSheet/StyleSheetExports.js.flow +3 -1
  75. package/Libraries/StyleSheet/StyleSheetTypes.js +4 -3
  76. package/Libraries/StyleSheet/private/_TransformStyle.js +49 -21
  77. package/Libraries/StyleSheet/processBoxShadow.js +0 -1
  78. package/Libraries/StyleSheet/processFilter.js +0 -1
  79. package/Libraries/Text/Text.d.ts +7 -0
  80. package/Libraries/Text/Text.js +255 -244
  81. package/Libraries/Text/Text.win32.js +293 -284
  82. package/Libraries/Text/TextAncestor.js +3 -2
  83. package/Libraries/Text/TextProps.js +2 -34
  84. package/Libraries/Text/TextProps.win32.js +2 -33
  85. package/Libraries/Types/ReactDevToolsTypes.js +0 -1
  86. package/Libraries/Utilities/PerformanceLoggerContext.js +2 -2
  87. package/Libraries/Utilities/PlatformTypes.js +1 -1
  88. package/Libraries/vendor/core/ErrorUtils.js +28 -4
  89. package/index.js +0 -1
  90. package/jest/mockNativeComponent.js +2 -1
  91. package/jest/renderer.js +0 -1
  92. package/jest/resolver.js +31 -0
  93. package/jest/setup.js +1 -1
  94. package/overrides.json +27 -20
  95. package/package.json +13 -13
  96. package/src/private/animated/NativeAnimatedHelper.js +6 -1
  97. package/src/private/animated/NativeAnimatedHelper.win32.js +6 -1
  98. package/src/private/animated/createAnimatedPropsHook.js +11 -4
  99. package/src/private/animated/createAnimatedPropsMemoHook.js +0 -1
  100. package/src/private/components/safeareaview/SafeAreaView_INTERNAL_DO_NOT_USE.js +0 -1
  101. package/src/private/components/scrollview/HScrollViewNativeComponents.js +0 -1
  102. package/src/private/components/scrollview/VScrollViewNativeComponents.js +0 -1
  103. package/src/private/devsupport/rndevtools/FuseboxSessionObserver.js +0 -1
  104. package/src/private/devsupport/rndevtools/ReactDevToolsSettingsManager.android.js +8 -9
  105. package/src/private/devsupport/rndevtools/ReactDevToolsSettingsManager.ios.js +12 -15
  106. package/src/private/devsupport/rndevtools/ReactDevToolsSettingsManager.win32.js +8 -9
  107. package/src/private/devsupport/rndevtools/setUpFuseboxReactDevToolsDispatcher.js +0 -1
  108. package/src/private/devsupport/rndevtools/specs/NativeReactDevToolsRuntimeSettingsModule.js +0 -1
  109. package/src/private/featureflags/ReactNativeFeatureFlags.js +39 -4
  110. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +5 -2
  111. package/src/private/setup/setUpDefaultReactNativeEnvironment.js +44 -0
  112. package/src/private/styles/composeStyles.js +12 -5
  113. package/src/private/webapis/dom/events/Event.js +3 -0
  114. package/src/private/webapis/dom/events/EventTarget.js +3 -0
  115. package/src/private/webapis/dom/nodes/ReactNativeElement.js +6 -23
  116. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +3 -1
  117. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +38 -0
  118. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +3 -0
  119. package/src/private/webapis/dom/oldstylecollections/NodeList.js +3 -0
  120. package/src/private/webapis/errors/DOMException.js +166 -0
  121. package/src/private/webapis/geometry/DOMRect.js +5 -0
  122. package/src/private/webapis/geometry/DOMRectList.js +3 -0
  123. package/src/private/webapis/geometry/DOMRectReadOnly.js +6 -0
  124. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +15 -7
  125. package/src/private/webapis/intersectionobserver/IntersectionObserverEntry.js +3 -0
  126. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +80 -18
  127. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +12 -0
  128. package/src/private/webapis/mutationobserver/MutationObserver.js +23 -33
  129. package/src/private/webapis/mutationobserver/MutationRecord.js +3 -0
  130. package/src/private/webapis/mutationobserver/internals/MutationObserverManager.js +56 -24
  131. package/src/private/webapis/mutationobserver/specs/NativeMutationObserver.js +4 -1
  132. package/src/private/webapis/performance/MemoryInfo.js +4 -1
  133. package/src/private/webapis/performance/Performance.js +19 -8
  134. package/src/private/webapis/performance/PerformanceEntry.js +4 -0
  135. package/src/private/webapis/performance/ReactNativeStartupTiming.js +4 -1
  136. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +2 -0
  137. package/src/private/webapis/structuredClone/structuredClone.js +233 -0
  138. package/src/private/webapis/webidl/PlatformObjects.js +59 -0
  139. package/src/types/globals.d.ts +42 -0
  140. package/src-win/Libraries/Text/Text.d.ts +7 -0
  141. package/types/index.d.ts +1 -1
@@ -43,6 +43,7 @@ const registeredMutationObservers: Map<
43
43
 
44
44
  // The mapping between ReactNativeElement and their corresponding shadow node
45
45
  // needs to be kept here because React removes the link when unmounting.
46
+ // TODO: remove this code when NativeMutationObserver.unobserveAll is available in all apps
46
47
  const targetToShadowNodeMap: WeakMap<
47
48
  ReactNativeElement,
48
49
  ReturnType<typeof getNativeNodeReference>,
@@ -111,7 +112,11 @@ export function observe({
111
112
  return false;
112
113
  }
113
114
 
114
- targetToShadowNodeMap.set(target, targetShadowNode);
115
+ // We need to keep this temporarily until the changes in the native module have propagated.
116
+ // After that, we don't need to keep this mapping that can cause memory leaks.
117
+ if (!nativeUnobserveAll) {
118
+ targetToShadowNodeMap.set(target, targetShadowNode);
119
+ }
115
120
 
116
121
  if (!isConnected) {
117
122
  NativeMutationObserver.connect(
@@ -135,34 +140,61 @@ export function observe({
135
140
  return true;
136
141
  }
137
142
 
138
- export function unobserve(
143
+ const nativeUnobserve = NativeMutationObserver?.unobserve;
144
+
145
+ // TODO: delete in the next version, when NativeMutationObserver.unobserveAll is available in all apps
146
+ export const unobserve: ?(
139
147
  mutationObserverId: number,
140
148
  target: ReactNativeElement,
141
- ): void {
142
- if (NativeMutationObserver == null) {
143
- warnNoNativeMutationObserver();
144
- return;
145
- }
149
+ ) => void = nativeUnobserve
150
+ ? function unobserve(
151
+ mutationObserverId: number,
152
+ target: ReactNativeElement,
153
+ ): void {
154
+ if (NativeMutationObserver == null) {
155
+ warnNoNativeMutationObserver();
156
+ return;
157
+ }
146
158
 
147
- const registeredObserver =
148
- registeredMutationObservers.get(mutationObserverId);
149
- if (registeredObserver == null) {
150
- console.error(
151
- `MutationObserverManager: could not stop observing target because MutationObserver with ID ${mutationObserverId} was not registered.`,
152
- );
153
- return;
154
- }
159
+ const registeredObserver =
160
+ registeredMutationObservers.get(mutationObserverId);
161
+ if (registeredObserver == null) {
162
+ console.error(
163
+ `MutationObserverManager: could not stop observing target because MutationObserver with ID ${mutationObserverId} was not registered.`,
164
+ );
165
+ return;
166
+ }
155
167
 
156
- const targetShadowNode = targetToShadowNodeMap.get(target);
157
- if (targetShadowNode == null) {
158
- console.error(
159
- 'MutationObserverManager: could not find registration data for target',
160
- );
161
- return;
162
- }
168
+ const targetShadowNode = targetToShadowNodeMap.get(target);
169
+ if (targetShadowNode == null) {
170
+ console.error(
171
+ 'MutationObserverManager: could not find registration data for target',
172
+ );
173
+ return;
174
+ }
163
175
 
164
- NativeMutationObserver.unobserve(mutationObserverId, targetShadowNode);
165
- }
176
+ nativeUnobserve(mutationObserverId, targetShadowNode);
177
+ }
178
+ : null;
179
+
180
+ const nativeUnobserveAll = NativeMutationObserver?.unobserveAll;
181
+
182
+ // TODO: clean up as a regular export in the next version, when NativeMutationObserver.unobserveAll is available in all apps
183
+ export const unobserveAll: ?(mutationObserverId: number) => void =
184
+ nativeUnobserveAll
185
+ ? function unobserveAll(mutationObserverId: MutationObserverId): void {
186
+ const registeredObserver =
187
+ registeredMutationObservers.get(mutationObserverId);
188
+ if (registeredObserver == null) {
189
+ console.error(
190
+ `MutationObserverManager: could not stop observing target because MutationObserver with ID ${mutationObserverId} was not registered.`,
191
+ );
192
+ return;
193
+ }
194
+
195
+ nativeUnobserveAll(mutationObserverId);
196
+ }
197
+ : null;
166
198
 
167
199
  /**
168
200
  * This function is called from native when there are `MutationObserver`
@@ -36,10 +36,13 @@ export type NativeMutationObserverObserveOptions = {
36
36
 
37
37
  export interface Spec extends TurboModule {
38
38
  +observe: (options: NativeMutationObserverObserveOptions) => void;
39
- +unobserve: (
39
+ // TODO: remove in the next version
40
+ +unobserve?: (
40
41
  mutationObserverId: number,
41
42
  targetShadowNode: ShadowNode,
42
43
  ) => void;
44
+ // TODO: remove optionality in the next version
45
+ +unobserveAll?: (mutationObserverId: number) => void;
43
46
  +connect: (
44
47
  notifyMutationObservers: () => void,
45
48
  // We need this to retain the public instance before React removes the
@@ -6,11 +6,12 @@
6
6
  *
7
7
  * @flow strict
8
8
  * @format
9
- * @oncall react_native
10
9
  */
11
10
 
12
11
  // flowlint unsafe-getters-setters:off
13
12
 
13
+ import {setPlatformObject} from '../webidl/PlatformObjects';
14
+
14
15
  type MemoryInfoLike = {
15
16
  jsHeapSizeLimit: ?number,
16
17
  totalJSHeapSize: ?number,
@@ -52,3 +53,5 @@ export default class MemoryInfo {
52
53
  return this.#usedJSHeapSize;
53
54
  }
54
55
  }
56
+
57
+ setPlatformObject(MemoryInfo);
@@ -17,6 +17,8 @@ import type {
17
17
  } from './PerformanceEntry';
18
18
  import type {DetailType, PerformanceMarkOptions} from './UserTiming';
19
19
 
20
+ import DOMException from '../errors/DOMException';
21
+ import {setPlatformObject} from '../webidl/PlatformObjects';
20
22
  import {EventCounts} from './EventTiming';
21
23
  import {
22
24
  performanceEntryTypeToRaw,
@@ -191,15 +193,22 @@ export default class Performance {
191
193
  let computedDuration = duration;
192
194
 
193
195
  if (NativePerformance?.measureWithResult) {
194
- [computedStartTime, computedDuration] =
195
- NativePerformance.measureWithResult(
196
- measureName,
197
- startTime,
198
- endTime,
199
- duration,
200
- startMarkName,
201
- endMarkName,
196
+ try {
197
+ [computedStartTime, computedDuration] =
198
+ NativePerformance.measureWithResult(
199
+ measureName,
200
+ startTime,
201
+ endTime,
202
+ duration,
203
+ startMarkName,
204
+ endMarkName,
205
+ );
206
+ } catch (error) {
207
+ throw new DOMException(
208
+ "Failed to execute 'measure' on 'Performance': " + error.message,
209
+ 'SyntaxError',
202
210
  );
211
+ }
203
212
  } else {
204
213
  warnNoNativePerformance();
205
214
  }
@@ -283,3 +292,5 @@ export default class Performance {
283
292
  ).map(rawToPerformanceEntry);
284
293
  }
285
294
  }
295
+
296
+ setPlatformObject(Performance);
@@ -10,6 +10,8 @@
10
10
 
11
11
  // flowlint unsafe-getters-setters:off
12
12
 
13
+ import {setPlatformObject} from '../webidl/PlatformObjects';
14
+
13
15
  export type DOMHighResTimeStamp = number;
14
16
  export type PerformanceEntryType =
15
17
  | 'mark'
@@ -70,4 +72,6 @@ export class PerformanceEntry {
70
72
  }
71
73
  }
72
74
 
75
+ setPlatformObject(PerformanceEntry);
76
+
73
77
  export type PerformanceEntryList = $ReadOnlyArray<PerformanceEntry>;
@@ -6,11 +6,12 @@
6
6
  *
7
7
  * @flow strict
8
8
  * @format
9
- * @oncall react_native
10
9
  */
11
10
 
12
11
  // flowlint unsafe-getters-setters:off
13
12
 
13
+ import {setPlatformObject} from '../webidl/PlatformObjects';
14
+
14
15
  type ReactNativeStartupTimingLike = {
15
16
  startTime: ?number,
16
17
  endTime: ?number,
@@ -89,3 +90,5 @@ export default class ReactNativeStartupTiming {
89
90
  return this.#executeJavaScriptBundleEntryPointEnd;
90
91
  }
91
92
  }
93
+
94
+ setPlatformObject(ReactNativeStartupTiming);
@@ -77,6 +77,8 @@ export function rawToPerformanceEntryType(
77
77
  return 'event';
78
78
  case RawPerformanceEntryTypeValues.LONGTASK:
79
79
  return 'longtask';
80
+ case RawPerformanceEntryTypeValues.RESOURCE:
81
+ return 'resource';
80
82
  default:
81
83
  throw new TypeError(
82
84
  `rawToPerformanceEntryType: unexpected performance entry type received: ${type}`,
@@ -0,0 +1,233 @@
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
8
+ * @format
9
+ */
10
+
11
+ import DOMException from '../errors/DOMException';
12
+ import {
13
+ getPlatformObjectClone,
14
+ isPlatformObject,
15
+ } from '../webidl/PlatformObjects';
16
+
17
+ const VALID_ERROR_NAMES = new Set([
18
+ 'Error',
19
+ 'EvalError',
20
+ 'RangeError',
21
+ 'ReferenceError',
22
+ 'SyntaxError',
23
+ 'TypeError',
24
+ 'URIError',
25
+ ]);
26
+
27
+ const BASIC_CONSTRUCTORS = [Number, String, Boolean, Date];
28
+
29
+ const ObjectPrototype = Object.prototype;
30
+
31
+ // Technicall the memory value should be a parameter in
32
+ // `structuredCloneInternal` but as an optimization we can reuse the same map
33
+ // and avoid allocating a new one in every call to `structuredClone`.
34
+ // This is safe because we don't invoke user code in `structuredClone`, so at
35
+ // any given point we only have one memory object alive anyway.
36
+ const memory: Map<mixed, mixed> = new Map();
37
+
38
+ function structuredCloneInternal<T>(value: T): T {
39
+ // Handles `null` and `undefined`.
40
+ if (value == null) {
41
+ return value;
42
+ }
43
+
44
+ // Handles remaining primitive values.
45
+ switch (typeof value) {
46
+ case 'boolean':
47
+ case 'number':
48
+ case 'string':
49
+ case 'bigint':
50
+ return value;
51
+ }
52
+
53
+ // Handles unsupported types (symbols and functions).
54
+ if (typeof value !== 'object') {
55
+ // value is symbol or function
56
+ throw new DOMException(
57
+ `Failed to execute 'structuredClone' on 'Window': ${String(value)} could not be cloned.`,
58
+ 'DataCloneError',
59
+ );
60
+ }
61
+
62
+ // Handles circular references.
63
+ if (memory.has(value)) {
64
+ // $FlowExpectedError[incompatible-return] we know memory.get(value) is T
65
+ return memory.get(value);
66
+ }
67
+
68
+ // Handles arrays.
69
+ if (Array.isArray(value)) {
70
+ const result = [];
71
+ memory.set(value, result);
72
+
73
+ for (const key of Object.keys(value)) {
74
+ result[key] = structuredCloneInternal(value[key]);
75
+ }
76
+
77
+ // $FlowExpectedError[incompatible-return] we know result is T
78
+ return result;
79
+ }
80
+
81
+ // Simple object fast path
82
+ // $FlowIssue[prop-missing] Why doesn't Flow know about Object.prototype?
83
+ if (Object.getPrototypeOf(value) === ObjectPrototype) {
84
+ const result = {};
85
+ memory.set(value, result);
86
+
87
+ for (const key of Object.keys(value)) {
88
+ // $FlowExpectedError[prop-missing]
89
+ result[key] = structuredCloneInternal(value[key]);
90
+ }
91
+
92
+ // $FlowExpectedError[incompatible-return] we know result is T
93
+ return result;
94
+ }
95
+
96
+ // Handles complex types (typeof === 'object').
97
+
98
+ for (const Cls of BASIC_CONSTRUCTORS) {
99
+ if (value instanceof Cls) {
100
+ const result = new Cls(value);
101
+ memory.set(value, result);
102
+ // $FlowExpectedError[incompatible-return] we know result is T
103
+ return result;
104
+ }
105
+ }
106
+
107
+ if (value instanceof Map) {
108
+ const result = new Map<mixed, mixed>();
109
+ memory.set(value, result);
110
+
111
+ for (const [innerKey, innerValue] of value) {
112
+ result.set(
113
+ structuredCloneInternal(innerKey),
114
+ structuredCloneInternal(innerValue),
115
+ );
116
+ }
117
+
118
+ // $FlowExpectedError[incompatible-return] we know result is T
119
+ return result;
120
+ }
121
+
122
+ if (value instanceof Set) {
123
+ const result = new Set<mixed>();
124
+ memory.set(value, result);
125
+
126
+ for (const innerValue of value) {
127
+ result.add(structuredCloneInternal(innerValue));
128
+ }
129
+
130
+ // $FlowExpectedError[incompatible-return] we know result is T
131
+ return result;
132
+ }
133
+
134
+ if (value instanceof RegExp) {
135
+ const result = new RegExp(value.source, value.flags);
136
+ memory.set(value, result);
137
+
138
+ // $FlowExpectedError[incompatible-return] we know result is T
139
+ return result;
140
+ }
141
+
142
+ // We need to check platform objects before `Error` because `DOMException`
143
+ // is a platform object AND an `Error` subclass.
144
+ const clone = getPlatformObjectClone(value);
145
+ if (clone != null) {
146
+ const result = clone(value);
147
+ memory.set(value, result);
148
+ return result;
149
+ }
150
+
151
+ if (value instanceof Error) {
152
+ const result = value.cause
153
+ ? new Error(value.message, {cause: value.cause})
154
+ : new Error(value.message);
155
+ memory.set(value, result);
156
+
157
+ if (VALID_ERROR_NAMES.has(value.name)) {
158
+ result.name = value.name;
159
+ } else {
160
+ result.name = 'Error';
161
+ }
162
+
163
+ result.stack = value.stack;
164
+
165
+ // $FlowExpectedError[incompatible-return] we know result is T
166
+ return result;
167
+ }
168
+
169
+ // Known non-serializable objects.
170
+ if (isNonSerializableObject(value) || isPlatformObject(value)) {
171
+ throw new DOMException(
172
+ `Failed to execute 'structuredClone' on 'Window': ${String(value)} could not be cloned.`,
173
+ 'DataCloneError',
174
+ );
175
+ }
176
+
177
+ // Arbitrary object slow path
178
+ const result = {};
179
+ memory.set(value, result);
180
+
181
+ // We need to use Object.keys instead of iterating by indices because we
182
+ // also need to copy arbitrary fields set in the array.
183
+ for (const key of Object.keys(value)) {
184
+ // $FlowExpectedError[prop-missing]
185
+ result[key] = structuredCloneInternal(value[key]);
186
+ }
187
+
188
+ // $FlowExpectedError[incompatible-return] we know result is T
189
+ return result;
190
+ }
191
+
192
+ /**
193
+ * Basic implementation of `structuredClone`.
194
+ * See:
195
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone.
196
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
197
+ * - https://html.spec.whatwg.org/multipage/structured-data.html#structured-cloning
198
+ *
199
+ * Supports cloning all built-in types supported by the spec, circular
200
+ * references and referential equality of the same objects found in the
201
+ * structure.
202
+ *
203
+ * Shortcuts:
204
+ * - This implementation does NOT serialize and deserialize the value
205
+ * but implements the cloning in a single step.
206
+ *
207
+ * Known limitations:
208
+ * - It does not support transfering values.
209
+ */
210
+ export default function structuredClone<T>(value: T): T {
211
+ try {
212
+ return structuredCloneInternal(value);
213
+ } finally {
214
+ memory.clear();
215
+ }
216
+ }
217
+
218
+ const NON_SERIALIZABLE_OBJECT_KEY = Symbol('nonSerializableObject');
219
+
220
+ function isNonSerializableObject<T: interface {}>(obj: T): boolean {
221
+ // $FlowExpectedError[invalid-in-lhs]
222
+ return NON_SERIALIZABLE_OBJECT_KEY in obj;
223
+ }
224
+
225
+ function markClassAsNonSerializable<T>(cls: Class<T>): void {
226
+ // $FlowExpectedError[incompatible-use]
227
+ cls.prototype[NON_SERIALIZABLE_OBJECT_KEY] = true;
228
+ }
229
+
230
+ // Non-serializable built-ins.
231
+ markClassAsNonSerializable(WeakMap);
232
+ markClassAsNonSerializable(WeakSet);
233
+ markClassAsNonSerializable(Promise);
@@ -0,0 +1,59 @@
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
8
+ * @format
9
+ */
10
+
11
+ const IS_PLATFORM_OBJECT_KEY = Symbol('isPlatformObject');
12
+ const CLONE_PLATFORM_OBJECT_KEY = Symbol('clonePlatformObject');
13
+
14
+ /**
15
+ * Marks the given object or instances of the given class as platform objects.
16
+ *
17
+ * Optionally, it sets the clone function for that platform object, which is a
18
+ * simplification of the serializable attribute of the Web interface.
19
+ */
20
+ export const setPlatformObject: (<T: interface {}>(
21
+ obj: Class<T>,
22
+ options?: {clone: T => T},
23
+ ) => void) &
24
+ (<T: interface {}>(obj: T, options?: {clone: T => T}) => void) =
25
+ function setPlatformObject(obj, options) {
26
+ if (typeof obj === 'function') {
27
+ // $FlowExpectedError[prop-missing]
28
+ obj.prototype[IS_PLATFORM_OBJECT_KEY] = true;
29
+ if (options) {
30
+ // $FlowExpectedError[prop-missing]
31
+ obj.prototype[CLONE_PLATFORM_OBJECT_KEY] = options.clone;
32
+ }
33
+ } else {
34
+ // $FlowExpectedError[prop-missing]
35
+ obj[IS_PLATFORM_OBJECT_KEY] = true;
36
+ if (options) {
37
+ // $FlowExpectedError[prop-missing]
38
+ obj[CLONE_PLATFORM_OBJECT_KEY] = options.clone;
39
+ }
40
+ }
41
+ };
42
+
43
+ /**
44
+ * Indicates if the given object is a platform object.
45
+ */
46
+ export function isPlatformObject<T: interface {}>(obj: T): boolean {
47
+ // $FlowExpectedError[invalid-in-lhs]
48
+ return IS_PLATFORM_OBJECT_KEY in obj;
49
+ }
50
+
51
+ /**
52
+ * Returns the clone function for the given platform object, if it was set.
53
+ */
54
+ export function getPlatformObjectClone<T: interface {}>(
55
+ obj: T,
56
+ ): (T => T) | void {
57
+ // $FlowExpectedError[prop-missing]
58
+ return obj[CLONE_PLATFORM_OBJECT_KEY];
59
+ }
@@ -57,6 +57,48 @@ declare global {
57
57
 
58
58
  const HermesInternal: null | {};
59
59
 
60
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly) */
61
+ interface DOMRectReadOnly {
62
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/bottom) */
63
+ readonly bottom: number;
64
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/height) */
65
+ readonly height: number;
66
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/left) */
67
+ readonly left: number;
68
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/right) */
69
+ readonly right: number;
70
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/top) */
71
+ readonly top: number;
72
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/width) */
73
+ readonly width: number;
74
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/x) */
75
+ readonly x: number;
76
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRectReadOnly/y) */
77
+ readonly y: number;
78
+ toJSON(): any;
79
+ }
80
+
81
+ interface DOMRect extends DOMRectReadOnly {
82
+ height: number;
83
+ width: number;
84
+ x: number;
85
+ y: number;
86
+ }
87
+
88
+ interface DOMRectInit {
89
+ height?: number | undefined;
90
+ width?: number | undefined;
91
+ x?: number | undefined;
92
+ y?: number | undefined;
93
+ }
94
+
95
+ var DOMRect: {
96
+ prototype: DOMRect;
97
+ new (x?: number, y?: number, width?: number, height?: number): DOMRect;
98
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMRect/fromRect_static) */
99
+ fromRect(other?: DOMRectInit): DOMRect;
100
+ };
101
+
60
102
  // #region Timer Functions
61
103
 
62
104
  function clearInterval(handle: number): void;
@@ -296,6 +296,13 @@ export interface TextProps
296
296
  * Controls how touch events are handled. Similar to `View`'s `pointerEvents`.
297
297
  */
298
298
  pointerEvents?: ViewStyle['pointerEvents'] | undefined;
299
+
300
+ /**
301
+ * Defines how far your touch may move off of the button, before deactivating the button.
302
+ */
303
+ pressRetentionOffset?:
304
+ | {top: number; left: number; bottom: number; right: number}
305
+ | undefined;
299
306
  }
300
307
 
301
308
  /**
package/types/index.d.ts CHANGED
@@ -68,7 +68,7 @@
68
68
  /// <reference path="modules/BatchedBridge.d.ts" />
69
69
  /// <reference path="modules/Codegen.d.ts" />
70
70
  /// <reference path="modules/Devtools.d.ts" />
71
- /// <reference types="../src/types/globals.d.ts" />
71
+ /// <reference path="../src/types/globals.d.ts" />
72
72
 
73
73
  export * from '../Libraries/ActionSheetIOS/ActionSheetIOS';
74
74
  export * from '../Libraries/Alert/Alert';