@office-iss/react-native-win32 0.0.0-canary.270 → 0.0.0-canary.271

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 (96) hide show
  1. package/CHANGELOG.json +16 -1
  2. package/CHANGELOG.md +12 -4
  3. package/Libraries/Animated/animations/Animation.js +63 -24
  4. package/Libraries/Animated/animations/DecayAnimation.js +26 -38
  5. package/Libraries/Animated/animations/SpringAnimation.js +33 -39
  6. package/Libraries/Animated/animations/TimingAnimation.js +34 -42
  7. package/Libraries/Animated/createAnimatedComponent.js +46 -32
  8. package/Libraries/Animated/nodes/AnimatedProps.js +16 -10
  9. package/Libraries/Animated/nodes/AnimatedStyle.js +4 -0
  10. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +19 -3
  11. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +61 -3
  12. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +61 -3
  13. package/Libraries/Components/Button.js +6 -4
  14. package/Libraries/Components/Button.win32.js +9 -4
  15. package/Libraries/Components/ScrollView/ScrollView.js +5 -5
  16. package/Libraries/Components/Switch/Switch.js +8 -6
  17. package/Libraries/Components/TextInput/TextInput.d.ts +4 -4
  18. package/Libraries/Components/TextInput/TextInput.flow.js +7 -10
  19. package/Libraries/Components/TextInput/TextInput.js +7 -7
  20. package/Libraries/Components/TextInput/TextInput.win32.js +7 -7
  21. package/Libraries/Components/TextInput/TextInputState.js +11 -13
  22. package/Libraries/Components/TextInput/TextInputState.win32.js +13 -16
  23. package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
  24. package/Libraries/Components/View/ViewNativeComponent.js +3 -10
  25. package/Libraries/Core/ReactNativeVersion.js +1 -1
  26. package/Libraries/Core/setUpBatchedBridge.js +1 -10
  27. package/Libraries/Core/setUpReactDevTools.js +3 -3
  28. package/Libraries/Core/setUpSegmentFetcher.js +1 -0
  29. package/Libraries/Core/setUpTimers.js +8 -8
  30. package/Libraries/Image/ImageBackground.js +2 -5
  31. package/Libraries/Image/ImageProps.js +1 -1
  32. package/Libraries/Image/ImageViewNativeComponent.js +2 -2
  33. package/Libraries/Inspector/ReactDevToolsOverlay.js +0 -1
  34. package/Libraries/Inspector/getInspectorDataForViewAtPoint.js +3 -5
  35. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  36. package/Libraries/Lists/FlatList.d.ts +1 -2
  37. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +2 -2
  38. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +1 -1
  39. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  40. package/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +1 -1
  41. package/Libraries/LogBox/UI/LogBoxMessage.js +2 -2
  42. package/Libraries/NativeComponent/BaseViewConfig.android.js +1 -0
  43. package/Libraries/NativeComponent/BaseViewConfig.ios.js +1 -0
  44. package/Libraries/NativeComponent/BaseViewConfig.win32.js +1 -0
  45. package/Libraries/Network/XMLHttpRequest.js +26 -1
  46. package/Libraries/Pressability/HoverState.js +2 -0
  47. package/Libraries/Pressability/HoverState.win32.js +2 -0
  48. package/Libraries/Pressability/Pressability.js +2 -3
  49. package/Libraries/Pressability/Pressability.win32.js +2 -3
  50. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -3
  51. package/Libraries/ReactNative/RendererImplementation.js +4 -3
  52. package/Libraries/Renderer/shims/ReactNativeTypes.js +13 -18
  53. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -0
  54. package/Libraries/StyleSheet/StyleSheetTypes.js +13 -0
  55. package/Libraries/StyleSheet/processTransform.js +3 -34
  56. package/Libraries/Text/Text.js +251 -249
  57. package/Libraries/Text/Text.win32.js +285 -295
  58. package/Libraries/Types/CoreEventTypes.d.ts +3 -10
  59. package/Libraries/Types/CoreEventTypes.js +4 -6
  60. package/Libraries/Types/CoreEventTypes.win32.js +4 -6
  61. package/Libraries/Utilities/Platform.flow.js +2 -2
  62. package/Libraries/Utilities/Platform.flow.win32.js +2 -2
  63. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +5 -4
  64. package/index.js +5 -2
  65. package/index.win32.js +5 -2
  66. package/jest/setup.js +30 -0
  67. package/overrides.json +18 -17
  68. package/package.json +13 -13
  69. package/src/private/animated/NativeAnimatedHelper.js +2 -4
  70. package/src/private/animated/NativeAnimatedHelper.win32.js +2 -3
  71. package/src/private/components/HScrollViewNativeComponents.js +4 -5
  72. package/src/private/{fusebox → debugging}/setUpFuseboxReactDevToolsDispatcher.js +6 -0
  73. package/src/private/featureflags/ReactNativeFeatureFlags.js +14 -23
  74. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +2 -5
  75. package/src/private/specs/modules/NativeAccessibilityInfo.js +3 -0
  76. package/src/private/specs/modules/NativeAccessibilityInfoWin32.js +3 -0
  77. package/src/private/specs/modules/NativeAccessibilityManager.js +4 -0
  78. package/src/private/webapis/dom/nodes/ReactNativeElement.js +2 -3
  79. package/src/private/webapis/performance/EventTiming.js +13 -8
  80. package/src/private/webapis/performance/Performance.js +30 -40
  81. package/src/private/webapis/performance/PerformanceEntry.js +2 -5
  82. package/src/private/webapis/performance/PerformanceObserver.js +20 -32
  83. package/src/private/webapis/performance/RawPerformanceEntry.js +1 -1
  84. package/src/private/webapis/performance/UserTiming.js +6 -2
  85. package/src/private/webapis/performance/Utilities.js +0 -7
  86. package/src/private/webapis/performance/specs/NativePerformance.js +53 -0
  87. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +247 -0
  88. package/src-win/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts +19 -3
  89. package/types/public/ReactNativeTypes.d.ts +4 -4
  90. package/src/private/webapis/performance/specs/NativePerformanceObserver.js +0 -69
  91. package/src/private/webapis/performance/specs/__mocks__/NativePerformance.js +0 -69
  92. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceObserver.js +0 -154
  93. /package/src/private/{fusebox → debugging}/FuseboxSessionObserver.js +0 -0
  94. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.android.js +0 -0
  95. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.ios.js +0 -0
  96. /package/src/private/{reactdevtools → debugging}/ReactDevToolsSettingsManager.win32.js +0 -0
@@ -0,0 +1,247 @@
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 type {
12
+ NativeBatchedObserverCallback,
13
+ NativeMemoryInfo,
14
+ RawPerformanceEntry,
15
+ ReactNativeStartupTiming,
16
+ PerformanceObserverInit,
17
+ OpaqueNativeObserverHandle,
18
+ RawPerformanceEntryType,
19
+ } from '../NativePerformance';
20
+
21
+ import typeof NativePerformance from '../NativePerformance';
22
+
23
+ import {RawPerformanceEntryTypeValues} from '../../RawPerformanceEntry';
24
+
25
+ type MockObserver = {
26
+ handleEntry: (entry: RawPerformanceEntry) => void,
27
+ callback: NativeBatchedObserverCallback,
28
+ didScheduleFlushBuffer: boolean,
29
+ entries: Array<RawPerformanceEntry>,
30
+ options: PerformanceObserverInit,
31
+ droppedEntriesCount: number,
32
+ };
33
+
34
+ const eventCounts: Map<string, number> = new Map();
35
+ const observers: Set<MockObserver> = new Set();
36
+ const marks: Map<string, number> = new Map();
37
+ let entries: Array<RawPerformanceEntry> = [];
38
+
39
+ function getMockObserver(
40
+ opaqueNativeObserverHandle: OpaqueNativeObserverHandle,
41
+ ): MockObserver {
42
+ return opaqueNativeObserverHandle as $FlowFixMe as MockObserver;
43
+ }
44
+
45
+ function createMockObserver(callback: NativeBatchedObserverCallback) {
46
+ const observer: MockObserver = {
47
+ callback,
48
+ didScheduleFlushBuffer: false,
49
+ entries: [],
50
+ options: {},
51
+ droppedEntriesCount: 0,
52
+ handleEntry: (entry: RawPerformanceEntry) => {
53
+ if (
54
+ observer.options.type !== entry.entryType &&
55
+ !observer.options.entryTypes?.includes(entry.entryType)
56
+ ) {
57
+ return;
58
+ }
59
+
60
+ if (
61
+ entry.entryType === RawPerformanceEntryTypeValues.EVENT &&
62
+ entry.duration < (observer.options?.durationThreshold ?? 0)
63
+ ) {
64
+ return;
65
+ }
66
+
67
+ observer.entries.push(entry);
68
+
69
+ if (!observer.didScheduleFlushBuffer) {
70
+ observer.didScheduleFlushBuffer = true;
71
+ // $FlowFixMe[incompatible-call]
72
+ global.queueMicrotask(() => {
73
+ observer.didScheduleFlushBuffer = false;
74
+ // We want to emulate the way it's done in native (i.e. async/batched)
75
+ observer.callback();
76
+ });
77
+ }
78
+ },
79
+ };
80
+
81
+ return observer;
82
+ }
83
+
84
+ export function reportEntry(entry: RawPerformanceEntry) {
85
+ entries.push(entry);
86
+
87
+ switch (entry.entryType) {
88
+ case RawPerformanceEntryTypeValues.MARK:
89
+ marks.set(entry.name, entry.startTime);
90
+ break;
91
+ case RawPerformanceEntryTypeValues.MEASURE:
92
+ break;
93
+ case RawPerformanceEntryTypeValues.EVENT:
94
+ eventCounts.set(entry.name, (eventCounts.get(entry.name) ?? 0) + 1);
95
+ break;
96
+ }
97
+
98
+ for (const observer of observers) {
99
+ observer.handleEntry(entry);
100
+ }
101
+ }
102
+
103
+ let currentTime: number = 12;
104
+
105
+ const NativePerformanceMock = {
106
+ setCurrentTime: (time: number): void => {
107
+ currentTime = time;
108
+ },
109
+
110
+ now: (): number => currentTime,
111
+
112
+ mark: (name: string, startTime: number): void => {
113
+ marks.set(name, startTime);
114
+ reportEntry({
115
+ entryType: RawPerformanceEntryTypeValues.MARK,
116
+ name,
117
+ startTime,
118
+ duration: 0,
119
+ });
120
+ },
121
+
122
+ measure: (
123
+ name: string,
124
+ startTime: number,
125
+ endTime: number,
126
+ duration?: number,
127
+ startMark?: string,
128
+ endMark?: string,
129
+ ): void => {
130
+ const start = startMark != null ? marks.get(startMark) ?? 0 : startTime;
131
+ const end = endMark != null ? marks.get(endMark) ?? 0 : endTime;
132
+ reportEntry({
133
+ entryType: RawPerformanceEntryTypeValues.MEASURE,
134
+ name,
135
+ startTime: start,
136
+ duration: duration ?? end - start,
137
+ });
138
+ },
139
+
140
+ getSimpleMemoryInfo: (): NativeMemoryInfo => {
141
+ return {};
142
+ },
143
+
144
+ getReactNativeStartupTiming: (): ReactNativeStartupTiming => {
145
+ return {
146
+ startTime: 0,
147
+ endTime: 0,
148
+ executeJavaScriptBundleEntryPointStart: 0,
149
+ executeJavaScriptBundleEntryPointEnd: 0,
150
+ initializeRuntimeStart: 0,
151
+ initializeRuntimeEnd: 0,
152
+ };
153
+ },
154
+
155
+ getEventCounts: (): $ReadOnlyArray<[string, number]> => {
156
+ return Array.from(eventCounts.entries());
157
+ },
158
+
159
+ createObserver: (
160
+ callback: NativeBatchedObserverCallback,
161
+ ): OpaqueNativeObserverHandle => {
162
+ return createMockObserver(callback);
163
+ },
164
+
165
+ getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle): number => {
166
+ return getMockObserver(observer).droppedEntriesCount;
167
+ },
168
+
169
+ observe: (
170
+ observer: OpaqueNativeObserverHandle,
171
+ options: PerformanceObserverInit,
172
+ ): void => {
173
+ const mockObserver = getMockObserver(observer);
174
+ mockObserver.options = options;
175
+ observers.add(mockObserver);
176
+ },
177
+
178
+ disconnect: (observer: OpaqueNativeObserverHandle): void => {
179
+ const mockObserver = getMockObserver(observer);
180
+ observers.delete(mockObserver);
181
+ },
182
+
183
+ takeRecords: (
184
+ observer: OpaqueNativeObserverHandle,
185
+ ): $ReadOnlyArray<RawPerformanceEntry> => {
186
+ const mockObserver = getMockObserver(observer);
187
+ const observerEntries = mockObserver.entries;
188
+ mockObserver.entries = [];
189
+ return observerEntries.sort((a, b) => a.startTime - b.startTime);
190
+ },
191
+
192
+ clearMarks: (entryName?: string) => {
193
+ if (entryName != null) {
194
+ marks.delete(entryName);
195
+ } else {
196
+ marks.clear();
197
+ }
198
+
199
+ entries = entries.filter(
200
+ entry =>
201
+ entry.entryType !== RawPerformanceEntryTypeValues.MARK ||
202
+ (entryName != null && entry.name !== entryName),
203
+ );
204
+ },
205
+
206
+ clearMeasures: (entryName?: string) => {
207
+ entries = entries.filter(
208
+ entry =>
209
+ entry.entryType !== RawPerformanceEntryTypeValues.MEASURE ||
210
+ (entryName != null && entry.name !== entryName),
211
+ );
212
+ },
213
+
214
+ getEntries: (): $ReadOnlyArray<RawPerformanceEntry> => {
215
+ return [...entries].sort((a, b) => a.startTime - b.startTime);
216
+ },
217
+
218
+ getEntriesByName: (
219
+ entryName: string,
220
+ entryType?: ?RawPerformanceEntryType,
221
+ ): $ReadOnlyArray<RawPerformanceEntry> => {
222
+ return NativePerformanceMock.getEntries().filter(
223
+ entry =>
224
+ (entryType == null || entry.entryType === entryType) &&
225
+ entry.name === entryName,
226
+ );
227
+ },
228
+
229
+ getEntriesByType: (
230
+ entryType: RawPerformanceEntryType,
231
+ ): $ReadOnlyArray<RawPerformanceEntry> => {
232
+ return entries.filter(entry => entry.entryType === entryType);
233
+ },
234
+
235
+ getSupportedPerformanceEntryTypes:
236
+ (): $ReadOnlyArray<RawPerformanceEntryType> => {
237
+ return [
238
+ RawPerformanceEntryTypeValues.MARK,
239
+ RawPerformanceEntryTypeValues.MEASURE,
240
+ RawPerformanceEntryTypeValues.EVENT,
241
+ ];
242
+ },
243
+ };
244
+
245
+ (NativePerformanceMock: NativePerformance);
246
+
247
+ export default NativePerformanceMock;
@@ -7,8 +7,7 @@
7
7
  * @format
8
8
  */
9
9
 
10
- import type * as React from 'react';
11
- import {HostComponent} from '../../../types/public/ReactNativeTypes';
10
+ import {HostInstance} from '../../../types/public/ReactNativeTypes';
12
11
  import {EmitterSubscription} from '../../vendor/emitter/EventEmitter';
13
12
 
14
13
  type AccessibilityChangeEventName =
@@ -17,6 +16,8 @@ type AccessibilityChangeEventName =
17
16
  | 'grayscaleChanged' // iOS-only Event
18
17
  | 'invertColorsChanged' // iOS-only Event
19
18
  | 'reduceMotionChanged'
19
+ | 'highTextContrastChanged' // Android-only Event
20
+ | 'darkerSystemColorsChanged' // iOS-only Event
20
21
  | 'screenReaderChanged'
21
22
  | 'reduceTransparencyChanged'; // iOS-only Event
22
23
 
@@ -69,6 +70,21 @@ export interface AccessibilityInfoStatic {
69
70
  */
70
71
  isReduceMotionEnabled: () => Promise<boolean>;
71
72
 
73
+ /**
74
+ *
75
+ * Query whether high text contrast is currently enabled.
76
+ *
77
+ * @platform android
78
+ */
79
+ isHighTextContrastEnabled: () => Promise<boolean>;
80
+
81
+ /**
82
+ * Query whether darker system colors is currently enabled.
83
+ *
84
+ * @platform ios
85
+ */
86
+ isDarkerSystemColorsEnabled: () => Promise<boolean>;
87
+
72
88
  /**
73
89
  * Query whether reduce motion and prefer cross-fade transitions settings are currently enabled.
74
90
  *
@@ -152,7 +168,7 @@ export interface AccessibilityInfoStatic {
152
168
  */
153
169
  getRecommendedTimeoutMillis: (originalTimeout: number) => Promise<number>;
154
170
  sendAccessibilityEvent: (
155
- handle: React.ElementRef<HostComponent<unknown>>,
171
+ handle: HostInstance,
156
172
  eventType: AccessibilityEventTypes,
157
173
  ) => void;
158
174
  }
@@ -86,9 +86,7 @@ export interface NativeMethods {
86
86
  * _Can also be called with a relativeNativeNodeHandle but is deprecated._
87
87
  */
88
88
  measureLayout(
89
- relativeToNativeComponentRef:
90
- | React.ElementRef<HostComponent<unknown>>
91
- | number,
89
+ relativeToNativeComponentRef: HostInstance | number,
92
90
  onSuccess: MeasureLayoutOnSuccessCallback,
93
91
  onFail?: () => void,
94
92
  ): void;
@@ -122,6 +120,8 @@ export type NativeMethodsMixin = NativeMethods;
122
120
  */
123
121
  export type NativeMethodsMixinType = NativeMethods;
124
122
 
123
+ export type HostInstance = NativeMethods;
124
+
125
125
  /**
126
126
  * Represents a native component, such as those returned from `requireNativeComponent`.
127
127
  *
@@ -135,5 +135,5 @@ export interface HostComponent<P>
135
135
  React.ComponentClass<P>,
136
136
  Exclude<keyof React.ComponentClass<P>, 'new'>
137
137
  > {
138
- new (props: P, context?: any): React.Component<P> & Readonly<NativeMethods>;
138
+ new (props: P, context?: any): React.Component<P> & HostInstance;
139
139
  }
@@ -1,69 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {TurboModule} from '../../../../../Libraries/TurboModule/RCTExport';
12
-
13
- import * as TurboModuleRegistry from '../../../../../Libraries/TurboModule/TurboModuleRegistry';
14
-
15
- export type RawPerformanceEntryType = number;
16
-
17
- export type OpaqueNativeObserverHandle = mixed;
18
-
19
- export type NativeBatchedObserverCallback = () => void;
20
-
21
- export type RawPerformanceEntry = {|
22
- name: string,
23
- entryType: RawPerformanceEntryType,
24
- startTime: number,
25
- duration: number,
26
- // For "event" entries only:
27
- processingStart?: number,
28
- processingEnd?: number,
29
- interactionId?: number,
30
- |};
31
-
32
- export type PerformanceObserverInit = {
33
- entryTypes?: $ReadOnlyArray<number>,
34
- type?: number,
35
- buffered?: boolean,
36
- durationThreshold?: number,
37
- };
38
-
39
- export interface Spec extends TurboModule {
40
- +getEventCounts: () => $ReadOnlyArray<[string, number]>;
41
- +createObserver?: (
42
- callback: NativeBatchedObserverCallback,
43
- ) => OpaqueNativeObserverHandle;
44
- +getDroppedEntriesCount?: (observer: OpaqueNativeObserverHandle) => number;
45
-
46
- +observe?: (
47
- observer: OpaqueNativeObserverHandle,
48
- options: PerformanceObserverInit,
49
- ) => void;
50
- +disconnect?: (observer: OpaqueNativeObserverHandle) => void;
51
- +takeRecords?: (
52
- observer: OpaqueNativeObserverHandle,
53
- sort: boolean,
54
- ) => $ReadOnlyArray<RawPerformanceEntry>;
55
-
56
- +clearEntries: (
57
- entryType?: RawPerformanceEntryType,
58
- entryName?: string,
59
- ) => void;
60
- +getEntries: (
61
- entryType?: RawPerformanceEntryType,
62
- entryName?: string,
63
- ) => $ReadOnlyArray<RawPerformanceEntry>;
64
- +getSupportedPerformanceEntryTypes: () => $ReadOnlyArray<RawPerformanceEntryType>;
65
- }
66
-
67
- export default (TurboModuleRegistry.get<Spec>(
68
- 'NativePerformanceObserverCxx',
69
- ): ?Spec);
@@ -1,69 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {
12
- NativeMemoryInfo,
13
- ReactNativeStartupTiming,
14
- } from '../NativePerformance';
15
-
16
- import {RawPerformanceEntryTypeValues} from '../../RawPerformanceEntry';
17
- import NativePerformance from '../NativePerformance';
18
- import {logMockEntry} from './NativePerformanceObserver';
19
-
20
- const marks: Map<string, number> = new Map();
21
-
22
- const NativePerformanceMock: typeof NativePerformance = {
23
- mark: (name: string, startTime: number): void => {
24
- NativePerformance?.mark(name, startTime);
25
- marks.set(name, startTime);
26
- logMockEntry({
27
- entryType: RawPerformanceEntryTypeValues.MARK,
28
- name,
29
- startTime,
30
- duration: 0,
31
- });
32
- },
33
-
34
- measure: (
35
- name: string,
36
- startTime: number,
37
- endTime: number,
38
- duration?: number,
39
- startMark?: string,
40
- endMark?: string,
41
- ): void => {
42
- const start = startMark != null ? marks.get(startMark) ?? 0 : startTime;
43
- const end = endMark != null ? marks.get(endMark) ?? 0 : endTime;
44
- NativePerformance?.measure(name, start, end);
45
- logMockEntry({
46
- entryType: RawPerformanceEntryTypeValues.MEASURE,
47
- name,
48
- startTime: start,
49
- duration: duration ?? end - start,
50
- });
51
- },
52
-
53
- getSimpleMemoryInfo: (): NativeMemoryInfo => {
54
- return {};
55
- },
56
-
57
- getReactNativeStartupTiming: (): ReactNativeStartupTiming => {
58
- return {
59
- startTime: 0,
60
- endTime: 0,
61
- executeJavaScriptBundleEntryPointStart: 0,
62
- executeJavaScriptBundleEntryPointEnd: 0,
63
- initializeRuntimeStart: 0,
64
- initializeRuntimeEnd: 0,
65
- };
66
- },
67
- };
68
-
69
- export default NativePerformanceMock;
@@ -1,154 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict
8
- * @format
9
- */
10
-
11
- import type {
12
- NativeBatchedObserverCallback,
13
- RawPerformanceEntry,
14
- RawPerformanceEntryType,
15
- OpaqueNativeObserverHandle,
16
- PerformanceObserverInit,
17
- Spec as NativePerformanceObserver,
18
- } from '../NativePerformanceObserver';
19
-
20
- import {RawPerformanceEntryTypeValues} from '../../RawPerformanceEntry';
21
-
22
- jest.mock(
23
- '../NativePerformance',
24
- () => require('../__mocks__/NativePerformance').default,
25
- );
26
-
27
- jest.mock(
28
- '../NativePerformanceObserver',
29
- () => require('../__mocks__/NativePerformanceObserver').default,
30
- );
31
-
32
- const eventCounts: Map<string, number> = new Map();
33
- let observers: MockObserver[] = [];
34
- let entries: Array<RawPerformanceEntry> = [];
35
-
36
- export function logMockEntry(entry: RawPerformanceEntry) {
37
- entries.push(entry);
38
-
39
- if (entry.entryType === RawPerformanceEntryTypeValues.EVENT) {
40
- eventCounts.set(entry.name, (eventCounts.get(entry.name) ?? 0) + 1);
41
- }
42
-
43
- for (const observer of observers) {
44
- if (
45
- observer.options.type !== entry.entryType &&
46
- !observer.options.entryTypes?.includes(entry.entryType)
47
- ) {
48
- continue;
49
- }
50
-
51
- if (entry.entryType === RawPerformanceEntryTypeValues.EVENT) {
52
- const {durationThreshold = 0} = observer.options;
53
- if (durationThreshold > 0 && entry.duration < durationThreshold) {
54
- continue;
55
- }
56
- }
57
-
58
- observer.entries.push(entry);
59
-
60
- // $FlowFixMe[incompatible-call]
61
- global.queueMicrotask(() => {
62
- // We want to emulate the way it's done in native (i.e. async/batched)
63
- observer.callback();
64
- });
65
- }
66
- }
67
-
68
- type MockObserver = {
69
- callback: NativeBatchedObserverCallback,
70
- entries: Array<RawPerformanceEntry>,
71
- options: PerformanceObserverInit,
72
- droppedEntriesCount: number,
73
- };
74
-
75
- const NativePerformanceObserverMock: NativePerformanceObserver = {
76
- getEventCounts: (): $ReadOnlyArray<[string, number]> => {
77
- return Array.from(eventCounts.entries());
78
- },
79
-
80
- createObserver: (
81
- callback: NativeBatchedObserverCallback,
82
- ): OpaqueNativeObserverHandle => {
83
- const observer: MockObserver = {
84
- callback,
85
- entries: [],
86
- options: {},
87
- droppedEntriesCount: 0,
88
- };
89
-
90
- return observer;
91
- },
92
-
93
- getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle): number => {
94
- // $FlowFixMe
95
- const mockObserver = (observer: any) as MockObserver;
96
- return mockObserver.droppedEntriesCount;
97
- },
98
-
99
- observe: (
100
- observer: OpaqueNativeObserverHandle,
101
- options: PerformanceObserverInit,
102
- ): void => {
103
- // $FlowFixMe
104
- const mockObserver = (observer: any) as MockObserver;
105
- mockObserver.options = options;
106
- observers.push(mockObserver);
107
- },
108
-
109
- disconnect: (observer: OpaqueNativeObserverHandle): void => {
110
- // $FlowFixMe
111
- const mockObserver = (observer: any) as MockObserver;
112
- observers = observers.filter(e => e !== mockObserver);
113
- },
114
-
115
- takeRecords: (
116
- observer: OpaqueNativeObserverHandle,
117
- ): $ReadOnlyArray<RawPerformanceEntry> => {
118
- // $FlowFixMe
119
- const mockObserver = (observer: any) as MockObserver;
120
- const observerEntries = mockObserver.entries;
121
- mockObserver.entries = [];
122
- return observerEntries;
123
- },
124
-
125
- clearEntries: (entryType?: RawPerformanceEntryType, entryName?: string) => {
126
- entries = entries.filter(
127
- e =>
128
- (entryType != null && e.entryType !== entryType) ||
129
- (entryName != null && e.name !== entryName),
130
- );
131
- },
132
-
133
- getEntries: (
134
- entryType?: RawPerformanceEntryType,
135
- entryName?: string,
136
- ): $ReadOnlyArray<RawPerformanceEntry> => {
137
- return entries.filter(
138
- e =>
139
- (entryType == null || e.entryType === entryType) &&
140
- (entryName == null || e.name === entryName),
141
- );
142
- },
143
-
144
- getSupportedPerformanceEntryTypes:
145
- (): $ReadOnlyArray<RawPerformanceEntryType> => {
146
- return [
147
- RawPerformanceEntryTypeValues.MARK,
148
- RawPerformanceEntryTypeValues.MEASURE,
149
- RawPerformanceEntryTypeValues.EVENT,
150
- ];
151
- },
152
- };
153
-
154
- export default NativePerformanceObserverMock;