@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
@@ -28,50 +28,67 @@ export type PerformanceEntryJSON = {
28
28
  ...
29
29
  };
30
30
 
31
+ export interface PerformanceEntryInit {
32
+ +name: string;
33
+ +startTime: DOMHighResTimeStamp;
34
+ +duration: DOMHighResTimeStamp;
35
+ }
36
+
31
37
  export class PerformanceEntry {
32
- #name: string;
33
- #entryType: PerformanceEntryType;
34
- #startTime: DOMHighResTimeStamp;
35
- #duration: DOMHighResTimeStamp;
36
-
37
- constructor(init: {
38
- name: string,
39
- entryType: PerformanceEntryType,
40
- startTime: DOMHighResTimeStamp,
41
- duration: DOMHighResTimeStamp,
42
- }) {
43
- this.#name = init.name;
44
- this.#entryType = init.entryType;
45
- this.#startTime = init.startTime;
46
- this.#duration = init.duration;
38
+ // We don't use private fields because they're significantly slower to
39
+ // initialize on construction and to access.
40
+ // We also need these to be protected so they can be initialized in subclasses
41
+ // where we avoid calling `super()` for performance reasons.
42
+ __entryType: PerformanceEntryType;
43
+ __name: string;
44
+ __startTime: DOMHighResTimeStamp;
45
+ __duration: DOMHighResTimeStamp;
46
+
47
+ constructor(entryType: PerformanceEntryType, init: PerformanceEntryInit) {
48
+ this.__entryType = entryType;
49
+ this.__name = init.name;
50
+ this.__startTime = init.startTime;
51
+ this.__duration = init.duration;
47
52
  }
48
53
 
49
54
  get name(): string {
50
- return this.#name;
55
+ return this.__name;
51
56
  }
52
57
 
53
58
  get entryType(): PerformanceEntryType {
54
- return this.#entryType;
59
+ return this.__entryType;
55
60
  }
56
61
 
57
62
  get startTime(): DOMHighResTimeStamp {
58
- return this.#startTime;
63
+ return this.__startTime;
59
64
  }
60
65
 
61
66
  get duration(): DOMHighResTimeStamp {
62
- return this.#duration;
67
+ return this.__duration;
63
68
  }
64
69
 
65
70
  toJSON(): PerformanceEntryJSON {
66
71
  return {
67
- name: this.#name,
68
- entryType: this.#entryType,
69
- startTime: this.#startTime,
70
- duration: this.#duration,
72
+ name: this.__name,
73
+ entryType: this.__entryType,
74
+ startTime: this.__startTime,
75
+ duration: this.__duration,
71
76
  };
72
77
  }
73
78
  }
74
79
 
80
+ export const PerformanceEntry_public: typeof PerformanceEntry =
81
+ /* eslint-disable no-shadow */
82
+ // $FlowExpectedError[incompatible-type]
83
+ function PerformanceEntry() {
84
+ throw new TypeError(
85
+ "Failed to construct 'PerformanceEntry': Illegal constructor",
86
+ );
87
+ };
88
+
89
+ // $FlowExpectedError[prop-missing]
90
+ PerformanceEntry_public.prototype = PerformanceEntry.prototype;
91
+
75
92
  setPlatformObject(PerformanceEntry);
76
93
 
77
94
  export type PerformanceEntryList = $ReadOnlyArray<PerformanceEntry>;
@@ -21,12 +21,13 @@ import {
21
21
  rawToPerformanceEntry,
22
22
  rawToPerformanceEntryType,
23
23
  } from './internals/RawPerformanceEntry';
24
- import {warnNoNativePerformance} from './internals/Utilities';
25
- import NativePerformance from './specs/NativePerformance';
24
+ import MaybeNativePerformance from './specs/NativePerformance';
26
25
  import nullthrows from 'nullthrows';
27
26
 
28
27
  export {PerformanceEntry} from './PerformanceEntry';
29
28
 
29
+ const NativePerformance = nullthrows(MaybeNativePerformance);
30
+
30
31
  export class PerformanceObserverEntryList {
31
32
  #entries: PerformanceEntryList;
32
33
 
@@ -56,6 +57,19 @@ export class PerformanceObserverEntryList {
56
57
  }
57
58
  }
58
59
 
60
+ export const PerformanceObserverEntryList_public: typeof PerformanceObserverEntryList =
61
+ /* eslint-disable no-shadow */
62
+ // $FlowExpectedError[incompatible-type]
63
+ function PerformanceObserverEntryList() {
64
+ throw new TypeError(
65
+ "Failed to construct 'PerformanceObserverEntryList': Illegal constructor",
66
+ );
67
+ };
68
+
69
+ // $FlowExpectedError[prop-missing]
70
+ PerformanceObserverEntryList_public.prototype =
71
+ PerformanceObserverEntryList.prototype;
72
+
59
73
  export type PerformanceObserverCallbackOptions = {
60
74
  droppedEntriesCount: number,
61
75
  };
@@ -75,13 +89,6 @@ export interface PerformanceObserverInit {
75
89
  }
76
90
 
77
91
  function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryType> {
78
- if (!NativePerformance) {
79
- return Object.freeze([]);
80
- }
81
- if (!NativePerformance.getSupportedPerformanceEntryTypes) {
82
- // fallback if getSupportedPerformanceEntryTypes is not defined on native side
83
- return Object.freeze(['mark', 'measure', 'event']);
84
- }
85
92
  return Object.freeze(
86
93
  NativePerformance.getSupportedPerformanceEntryTypes().map(
87
94
  rawToPerformanceEntryType,
@@ -120,11 +127,6 @@ export class PerformanceObserver {
120
127
  }
121
128
 
122
129
  observe(options: PerformanceObserverInit): void {
123
- if (!NativePerformance || NativePerformance.observe == null) {
124
- warnNoNativePerformance();
125
- return;
126
- }
127
-
128
130
  this.#validateObserveOptions(options);
129
131
 
130
132
  if (this.#nativeObserverHandle == null) {
@@ -135,12 +137,12 @@ export class PerformanceObserver {
135
137
 
136
138
  if (options.entryTypes) {
137
139
  this.#type = 'multiple';
138
- NativePerformance.observe?.(observerHandle, {
140
+ NativePerformance.observe(observerHandle, {
139
141
  entryTypes: options.entryTypes.map(performanceEntryTypeToRaw),
140
142
  });
141
143
  } else if (options.type) {
142
144
  this.#type = 'single';
143
- NativePerformance.observe?.(observerHandle, {
145
+ NativePerformance.observe(observerHandle, {
144
146
  type: performanceEntryTypeToRaw(options.type),
145
147
  buffered: options.buffered,
146
148
  durationThreshold: options.durationThreshold,
@@ -149,33 +151,39 @@ export class PerformanceObserver {
149
151
  }
150
152
 
151
153
  disconnect(): void {
152
- if (!NativePerformance) {
153
- warnNoNativePerformance();
154
- return;
155
- }
156
-
157
- if (this.#nativeObserverHandle == null || !NativePerformance.disconnect) {
154
+ if (this.#nativeObserverHandle == null) {
158
155
  return;
159
156
  }
160
157
 
161
158
  NativePerformance.disconnect(this.#nativeObserverHandle);
162
159
  }
163
160
 
164
- #createNativeObserver(): OpaqueNativeObserverHandle | null {
165
- if (!NativePerformance || !NativePerformance.createObserver) {
166
- warnNoNativePerformance();
167
- return null;
161
+ takeRecords(): PerformanceEntryList {
162
+ let entries: PerformanceEntryList = [];
163
+
164
+ if (this.#nativeObserverHandle != null) {
165
+ const rawEntries = NativePerformance.takeRecords(
166
+ this.#nativeObserverHandle,
167
+ true,
168
+ );
169
+ if (rawEntries && rawEntries.length > 0) {
170
+ entries = rawEntries.map(rawToPerformanceEntry);
171
+ }
168
172
  }
169
173
 
174
+ return entries;
175
+ }
176
+
177
+ #createNativeObserver(): OpaqueNativeObserverHandle | null {
170
178
  this.#calledAtLeastOnce = false;
171
179
 
172
180
  const observerHandle: OpaqueNativeObserverHandle =
173
181
  NativePerformance.createObserver(() => {
174
- const rawEntries = NativePerformance.takeRecords?.(
182
+ const rawEntries = NativePerformance.takeRecords(
175
183
  observerHandle,
176
184
  true, // sort records
177
185
  );
178
- if (!rawEntries) {
186
+ if (!rawEntries || rawEntries.length === 0) {
179
187
  return;
180
188
  }
181
189
 
@@ -185,7 +193,7 @@ export class PerformanceObserver {
185
193
  let droppedEntriesCount = 0;
186
194
  if (!this.#calledAtLeastOnce) {
187
195
  droppedEntriesCount =
188
- NativePerformance.getDroppedEntriesCount?.(observerHandle) ?? 0;
196
+ NativePerformance.getDroppedEntriesCount(observerHandle);
189
197
  this.#calledAtLeastOnce = true;
190
198
  }
191
199
 
@@ -16,9 +16,7 @@ type ReactNativeStartupTimingLike = {
16
16
  startTime: ?number,
17
17
  endTime: ?number,
18
18
  initializeRuntimeStart: ?number,
19
- initializeRuntimeEnd: ?number,
20
19
  executeJavaScriptBundleEntryPointStart: ?number,
21
- executeJavaScriptBundleEntryPointEnd: ?number,
22
20
  };
23
21
 
24
22
  // Read-only object with RN startup timing information.
@@ -29,22 +27,17 @@ export default class ReactNativeStartupTiming {
29
27
  // 1. The `ReactNativeStartupTiming` is non-standard API
30
28
  // 2. The timing information is relative to the time origin, which means `0` has valid meaning
31
29
  #startTime: ?number;
32
- #endTime: ?number;
33
30
  #initializeRuntimeStart: ?number;
34
- #initializeRuntimeEnd: ?number;
35
31
  #executeJavaScriptBundleEntryPointStart: ?number;
36
- #executeJavaScriptBundleEntryPointEnd: ?number;
32
+ #endTime: ?number;
37
33
 
38
34
  constructor(startUpTiming: ?ReactNativeStartupTimingLike) {
39
35
  if (startUpTiming != null) {
40
36
  this.#startTime = startUpTiming.startTime;
41
- this.#endTime = startUpTiming.endTime;
42
37
  this.#initializeRuntimeStart = startUpTiming.initializeRuntimeStart;
43
- this.#initializeRuntimeEnd = startUpTiming.initializeRuntimeEnd;
44
38
  this.#executeJavaScriptBundleEntryPointStart =
45
39
  startUpTiming.executeJavaScriptBundleEntryPointStart;
46
- this.#executeJavaScriptBundleEntryPointEnd =
47
- startUpTiming.executeJavaScriptBundleEntryPointEnd;
40
+ this.#endTime = startUpTiming.endTime;
48
41
  }
49
42
  }
50
43
 
@@ -56,7 +49,7 @@ export default class ReactNativeStartupTiming {
56
49
  }
57
50
 
58
51
  /**
59
- * End time of the RN app startup process. This is equal to `executeJavaScriptBundleEntryPointEnd`.
52
+ * End time of the RN app startup process.
60
53
  */
61
54
  get endTime(): ?number {
62
55
  return this.#endTime;
@@ -69,26 +62,12 @@ export default class ReactNativeStartupTiming {
69
62
  return this.#initializeRuntimeStart;
70
63
  }
71
64
 
72
- /**
73
- * End time when RN runtime get initialized. This is the last marker before ends of the app startup process.
74
- */
75
- get initializeRuntimeEnd(): ?number {
76
- return this.#initializeRuntimeEnd;
77
- }
78
-
79
65
  /**
80
66
  * Start time of JS bundle being executed. This indicates the RN JS bundle is loaded and start to be evaluated.
81
67
  */
82
68
  get executeJavaScriptBundleEntryPointStart(): ?number {
83
69
  return this.#executeJavaScriptBundleEntryPointStart;
84
70
  }
85
-
86
- /**
87
- * End time of JS bundle being executed. This indicates all the synchronous entry point jobs are finished.
88
- */
89
- get executeJavaScriptBundleEntryPointEnd(): ?number {
90
- return this.#executeJavaScriptBundleEntryPointEnd;
91
- }
92
71
  }
93
72
 
94
73
  setPlatformObject(ReactNativeStartupTiming);
@@ -29,6 +29,19 @@ export type PerformanceResourceTimingJSON = {
29
29
  ...
30
30
  };
31
31
 
32
+ export interface PerformanceResourceTimingInit {
33
+ +name: string;
34
+ +startTime: DOMHighResTimeStamp;
35
+ +duration: DOMHighResTimeStamp;
36
+ +fetchStart: DOMHighResTimeStamp;
37
+ +requestStart: DOMHighResTimeStamp;
38
+ +connectStart: DOMHighResTimeStamp;
39
+ +connectEnd: DOMHighResTimeStamp;
40
+ +responseStart: DOMHighResTimeStamp;
41
+ +responseEnd: DOMHighResTimeStamp;
42
+ +responseStatus?: number;
43
+ }
44
+
32
45
  export class PerformanceResourceTiming extends PerformanceEntry {
33
46
  #fetchStart: DOMHighResTimeStamp;
34
47
  #requestStart: DOMHighResTimeStamp;
@@ -38,24 +51,9 @@ export class PerformanceResourceTiming extends PerformanceEntry {
38
51
  #responseEnd: DOMHighResTimeStamp;
39
52
  #responseStatus: ?number;
40
53
 
41
- constructor(init: {
42
- name: string,
43
- startTime: DOMHighResTimeStamp,
44
- duration: DOMHighResTimeStamp,
45
- fetchStart: DOMHighResTimeStamp,
46
- requestStart: DOMHighResTimeStamp,
47
- connectStart: DOMHighResTimeStamp,
48
- connectEnd: DOMHighResTimeStamp,
49
- responseStart: DOMHighResTimeStamp,
50
- responseEnd: DOMHighResTimeStamp,
51
- responseStatus?: number,
52
- }) {
53
- super({
54
- name: init.name,
55
- entryType: 'resource',
56
- startTime: init.startTime,
57
- duration: init.duration,
58
- });
54
+ constructor(init: PerformanceResourceTimingInit) {
55
+ super('resource', init);
56
+
59
57
  this.#fetchStart = init.fetchStart;
60
58
  this.#requestStart = init.requestStart;
61
59
  this.#connectStart = init.connectStart;
@@ -106,3 +104,16 @@ export class PerformanceResourceTiming extends PerformanceEntry {
106
104
  };
107
105
  }
108
106
  }
107
+
108
+ export const PerformanceResourceTiming_public: typeof PerformanceResourceTiming =
109
+ /* eslint-disable no-shadow */
110
+ // $FlowExpectedError[incompatible-type]
111
+ function PerformanceResourceTiming() {
112
+ throw new TypeError(
113
+ "Failed to construct 'PerformanceResourceTiming': Illegal constructor",
114
+ );
115
+ };
116
+
117
+ // $FlowExpectedError[prop-missing]
118
+ PerformanceResourceTiming_public.prototype =
119
+ PerformanceResourceTiming.prototype;
@@ -9,64 +9,122 @@
9
9
  */
10
10
 
11
11
  // flowlint unsafe-getters-setters:off
12
+ import type {
13
+ DOMHighResTimeStamp,
14
+ PerformanceEntryInit,
15
+ } from './PerformanceEntry';
16
+ import type {
17
+ ExtensionMarkerPayload,
18
+ ExtensionTrackEntryPayload,
19
+ } from './UserTimingExtensibility';
12
20
 
13
- import type {DOMHighResTimeStamp} from './PerformanceEntry';
14
-
21
+ import {getCurrentTimeStamp} from './internals/Utilities';
15
22
  import {PerformanceEntry} from './PerformanceEntry';
16
23
 
17
- export type DetailType = mixed;
24
+ export type DetailType =
25
+ | mixed
26
+ // This will effectively ignored by Flow (mixed | anything = mixed)
27
+ // but we'll use it as documentation for how to use the extensibility API.
28
+ | {devtools?: ExtensionMarkerPayload | ExtensionTrackEntryPayload, ...};
18
29
 
19
- export type PerformanceMarkOptions = {
20
- detail?: DetailType,
21
- startTime?: DOMHighResTimeStamp,
22
- };
30
+ export interface PerformanceMarkOptions {
31
+ +detail?: DetailType;
32
+ +startTime?: DOMHighResTimeStamp;
33
+ }
23
34
 
24
35
  export type TimeStampOrName = DOMHighResTimeStamp | string;
25
36
 
26
- export type PerformanceMeasureInit = {
27
- detail?: DetailType,
28
- startTime: DOMHighResTimeStamp,
29
- duration: DOMHighResTimeStamp,
30
- };
37
+ export interface PerformanceMeasureInit extends PerformanceEntryInit {
38
+ +detail?: DetailType;
39
+ }
31
40
 
32
- export class PerformanceMark extends PerformanceEntry {
33
- #detail: DetailType;
41
+ class PerformanceMarkTemplate extends PerformanceEntry {
42
+ // We don't use private fields because they're significantly slower to
43
+ // initialize on construction and to access.
44
+ __detail: DetailType;
34
45
 
46
+ // This constructor isn't really used. See `PerformanceMark` below.
35
47
  constructor(markName: string, markOptions?: PerformanceMarkOptions) {
36
- super({
48
+ super('mark', {
37
49
  name: markName,
38
- entryType: 'mark',
39
- startTime: markOptions?.startTime ?? performance.now(),
50
+ startTime: markOptions?.startTime ?? getCurrentTimeStamp(),
40
51
  duration: 0,
41
52
  });
42
53
 
43
- if (markOptions) {
44
- this.#detail = markOptions.detail;
45
- }
54
+ this.__detail = markOptions?.detail ?? null;
46
55
  }
47
56
 
48
57
  get detail(): DetailType {
49
- return this.#detail;
58
+ return this.__detail;
50
59
  }
51
60
  }
52
61
 
53
- export class PerformanceMeasure extends PerformanceEntry {
54
- #detail: DetailType;
62
+ // This is the real value we're exporting where we define the class a function
63
+ // so we don't need to call `super()` and we can avoid the performance penalty
64
+ // of the current code transpiled with Babel.
65
+ // We should remove this when we have built-in support for classes in the
66
+ // runtime.
67
+ export const PerformanceMark: typeof PerformanceMarkTemplate =
68
+ // $FlowExpectedError[incompatible-type]
69
+ function PerformanceMark(
70
+ this: PerformanceMarkTemplate,
71
+ markName: string,
72
+ markOptions?: PerformanceMarkOptions,
73
+ ) {
74
+ this.__entryType = 'mark';
75
+ this.__name = markName;
76
+ this.__startTime = markOptions?.startTime ?? getCurrentTimeStamp();
77
+ this.__duration = 0;
55
78
 
56
- constructor(measureName: string, measureOptions: PerformanceMeasureInit) {
57
- super({
58
- name: measureName,
59
- entryType: 'measure',
60
- startTime: measureOptions.startTime,
61
- duration: measureOptions.duration,
62
- });
79
+ this.__detail = markOptions?.detail ?? null;
80
+ };
81
+
82
+ // $FlowExpectedError[prop-missing]
83
+ PerformanceMark.prototype = PerformanceMarkTemplate.prototype;
84
+
85
+ class PerformanceMeasureTemplate extends PerformanceEntry {
86
+ // We don't use private fields because they're significantly slower to
87
+ // initialize on construction and to access.
88
+ __detail: DetailType;
63
89
 
64
- if (measureOptions) {
65
- this.#detail = measureOptions.detail;
66
- }
90
+ // This constructor isn't really used. See `PerformanceMeasure` below.
91
+ constructor(init: PerformanceMeasureInit) {
92
+ super('measure', init);
93
+
94
+ this.__detail = init?.detail ?? null;
67
95
  }
68
96
 
69
97
  get detail(): DetailType {
70
- return this.#detail;
98
+ return this.__detail;
71
99
  }
72
100
  }
101
+
102
+ // We do the same here as we do for `PerformanceMark` for performance reasons.
103
+ export const PerformanceMeasure: typeof PerformanceMeasureTemplate =
104
+ // $FlowExpectedError[incompatible-type]
105
+ function PerformanceMeasure(
106
+ this: PerformanceMeasureTemplate,
107
+ init: PerformanceMeasureInit,
108
+ ) {
109
+ this.__entryType = 'measure';
110
+ this.__name = init.name;
111
+ this.__startTime = init.startTime;
112
+ this.__duration = init.duration;
113
+
114
+ this.__detail = init.detail ?? null;
115
+ };
116
+
117
+ // $FlowExpectedError[prop-missing]
118
+ PerformanceMeasure.prototype = PerformanceMeasureTemplate.prototype;
119
+
120
+ export const PerformanceMeasure_public: typeof PerformanceMeasure =
121
+ /* eslint-disable no-shadow */
122
+ // $FlowExpectedError[incompatible-type]
123
+ function PerformanceMeasure() {
124
+ throw new TypeError(
125
+ "Failed to construct 'PerformanceMeasure': Illegal constructor",
126
+ );
127
+ };
128
+
129
+ // $FlowExpectedError[prop-missing]
130
+ PerformanceMeasure_public.prototype = PerformanceMeasure.prototype;
@@ -0,0 +1,38 @@
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
+ export type DevToolsColor =
12
+ | 'primary'
13
+ | 'primary-light'
14
+ | 'primary-dark'
15
+ | 'secondary'
16
+ | 'secondary-light'
17
+ | 'secondary-dark'
18
+ | 'tertiary'
19
+ | 'tertiary-light'
20
+ | 'tertiary-dark'
21
+ | 'warning'
22
+ | 'error';
23
+
24
+ export interface ExtensionTrackEntryPayload {
25
+ dataType?: 'track-entry'; // Defaults to "track-entry"
26
+ color?: DevToolsColor; // Defaults to "primary"
27
+ track: string; // Required: Name of the custom track
28
+ trackGroup?: string; // Optional: Group for organizing tracks
29
+ properties?: Array<[string, string]>; // Key-value pairs for detailed view
30
+ tooltipText?: string; // Short description for tooltip
31
+ }
32
+
33
+ export interface ExtensionMarkerPayload {
34
+ dataType: 'marker'; // Required: Identifies as a marker
35
+ color?: DevToolsColor; // Defaults to "primary"
36
+ properties?: Array<[string, string]>; // Key-value pairs for detailed view
37
+ tooltipText?: string; // Short description for tooltip
38
+ }
@@ -44,7 +44,6 @@ export function rawToPerformanceEntry(
44
44
  case RawPerformanceEntryTypeValues.LONGTASK:
45
45
  return new PerformanceLongTaskTiming({
46
46
  name: entry.name,
47
- entryType: rawToPerformanceEntryType(entry.entryType),
48
47
  startTime: entry.startTime,
49
48
  duration: entry.duration,
50
49
  });
@@ -53,7 +52,8 @@ export function rawToPerformanceEntry(
53
52
  startTime: entry.startTime,
54
53
  });
55
54
  case RawPerformanceEntryTypeValues.MEASURE:
56
- return new PerformanceMeasure(entry.name, {
55
+ return new PerformanceMeasure({
56
+ name: entry.name,
57
57
  startTime: entry.startTime,
58
58
  duration: entry.duration,
59
59
  });
@@ -71,9 +71,8 @@ export function rawToPerformanceEntry(
71
71
  responseStatus: entry.responseStatus,
72
72
  });
73
73
  default:
74
- return new PerformanceEntry({
74
+ return new PerformanceEntry(rawToPerformanceEntryType(entry.entryType), {
75
75
  name: entry.name,
76
- entryType: rawToPerformanceEntryType(entry.entryType),
77
76
  startTime: entry.startTime,
78
77
  duration: entry.duration,
79
78
  });
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import warnOnce from '../../../../../Libraries/Utilities/warnOnce';
12
+ import NativePerformance from '../specs/NativePerformance';
12
13
 
13
14
  export function warnNoNativePerformance() {
14
15
  warnOnce(
@@ -16,3 +17,11 @@ export function warnNoNativePerformance() {
16
17
  'Missing native implementation of Performance',
17
18
  );
18
19
  }
20
+
21
+ declare var global: {
22
+ // This value is defined directly via JSI, if available.
23
+ +nativePerformanceNow?: ?() => number,
24
+ };
25
+
26
+ export const getCurrentTimeStamp: () => DOMHighResTimeStamp =
27
+ NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now());
@@ -53,49 +53,49 @@ export type PerformanceObserverInit = {
53
53
  };
54
54
 
55
55
  export interface Spec extends TurboModule {
56
- +now?: () => number;
57
- +markWithResult?: (
58
- name: string,
59
- startTime?: number,
60
- ) => NativePerformanceMarkResult;
61
- +measureWithResult?: (
56
+ +now: () => number;
57
+ +timeOrigin?: () => number;
58
+
59
+ +reportMark: (name: string, startTime: number, entry: mixed) => void;
60
+ +reportMeasure: (
62
61
  name: string,
63
62
  startTime: number,
64
- endTime: number,
65
- duration?: number,
66
- startMark?: string,
67
- endMark?: string,
68
- ) => NativePerformanceMeasureResult;
69
- +clearMarks?: (entryName?: string) => void;
70
- +clearMeasures?: (entryName?: string) => void;
71
- +getEntries?: () => $ReadOnlyArray<RawPerformanceEntry>;
72
- +getEntriesByName?: (
63
+ duration: number,
64
+ entry: mixed,
65
+ ) => void;
66
+ +getMarkTime: (name: string) => ?number;
67
+ +clearMarks: (entryName?: string) => void;
68
+ +clearMeasures: (entryName?: string) => void;
69
+ +getEntries: () => $ReadOnlyArray<RawPerformanceEntry>;
70
+ +getEntriesByName: (
73
71
  entryName: string,
74
72
  entryType?: ?RawPerformanceEntryType,
75
73
  ) => $ReadOnlyArray<RawPerformanceEntry>;
76
- +getEntriesByType?: (
74
+ +getEntriesByType: (
77
75
  entryType: RawPerformanceEntryType,
78
76
  ) => $ReadOnlyArray<RawPerformanceEntry>;
79
- +getEventCounts?: () => $ReadOnlyArray<[string, number]>;
77
+ +getEventCounts: () => $ReadOnlyArray<[string, number]>;
80
78
  +getSimpleMemoryInfo: () => NativeMemoryInfo;
81
79
  +getReactNativeStartupTiming: () => ReactNativeStartupTiming;
82
80
 
83
- +createObserver?: (
81
+ +createObserver: (
84
82
  callback: NativeBatchedObserverCallback,
85
83
  ) => OpaqueNativeObserverHandle;
86
- +getDroppedEntriesCount?: (observer: OpaqueNativeObserverHandle) => number;
84
+ +getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle) => number;
87
85
 
88
- +observe?: (
86
+ +observe: (
89
87
  observer: OpaqueNativeObserverHandle,
90
88
  options: PerformanceObserverInit,
91
89
  ) => void;
92
- +disconnect?: (observer: OpaqueNativeObserverHandle) => void;
93
- +takeRecords?: (
90
+ +disconnect: (observer: OpaqueNativeObserverHandle) => void;
91
+ +takeRecords: (
94
92
  observer: OpaqueNativeObserverHandle,
95
93
  sort: boolean,
96
94
  ) => $ReadOnlyArray<RawPerformanceEntry>;
97
95
 
98
- +getSupportedPerformanceEntryTypes?: () => $ReadOnlyArray<RawPerformanceEntryType>;
96
+ +getSupportedPerformanceEntryTypes: () => $ReadOnlyArray<RawPerformanceEntryType>;
97
+
98
+ +clearEventCountsForTesting: () => void;
99
99
  }
100
100
 
101
101
  export default (TurboModuleRegistry.get<Spec>('NativePerformanceCxx'): ?Spec);