@office-iss/react-native-win32 0.0.0-canary.266 → 0.0.0-canary.268
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.
- package/.flowconfig +1 -1
- package/CHANGELOG.json +55 -1
- package/CHANGELOG.md +24 -4
- package/Libraries/Animated/animations/Animation.js +4 -1
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +15 -15
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +3 -1
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.js +17 -0
- package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js +1 -0
- package/Libraries/Components/TextInput/TextInput.win32.js +17 -12
- package/Libraries/Components/Touchable/BoundingDimensions.js +11 -3
- package/Libraries/Components/Touchable/Position.js +7 -2
- package/Libraries/Components/Touchable/Touchable.js +4 -0
- package/Libraries/Components/Touchable/Touchable.win32.js +6 -2
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -1
- package/Libraries/Components/View/ViewWin32.js +3 -3
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Core/setUpReactDevTools.js +33 -7
- package/Libraries/Inspector/NetworkOverlay.js +4 -0
- package/Libraries/Inspector/ReactDevToolsOverlay.js +8 -13
- package/Libraries/Interaction/TouchHistoryMath.js +22 -19
- package/Libraries/LogBox/Data/LogBoxData.js +2 -2
- package/Libraries/NativeComponent/BaseViewConfig.android.js +1 -1
- package/Libraries/NativeComponent/BaseViewConfig.ios.js +1 -1
- package/Libraries/NativeComponent/BaseViewConfig.win32.js +1 -1
- package/Libraries/Network/XHRInterceptor.js +63 -14
- package/Libraries/Renderer/shims/ReactNativeTypes.js +2 -1
- package/Libraries/StyleSheet/StyleSheetTypes.js +1 -1
- package/Libraries/Text/Text.win32.js +11 -7
- package/Libraries/Utilities/Platform.win32.js +4 -4
- package/Libraries/WebSocket/WebSocketEvent.js +4 -1
- package/Libraries/WebSocket/WebSocketInterceptor.js +31 -13
- package/index.js +4 -0
- package/index.win32.js +4 -0
- package/just-task.js +1 -1
- package/overrides.json +12 -12
- package/package.json +16 -16
- package/src/private/devmenu/DevMenu.d.ts +20 -0
- package/src/private/devmenu/DevMenu.js +31 -0
- package/src/private/featureflags/ReactNativeFeatureFlags.js +22 -11
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +4 -3
- package/src/private/reactdevtools/ReactDevToolsSettingsManager.android.js +20 -0
- package/src/private/reactdevtools/ReactDevToolsSettingsManager.ios.js +30 -0
- package/src/private/reactdevtools/ReactDevToolsSettingsManager.win32.js +20 -0
- package/src/private/specs/components/AndroidHorizontalScrollContentViewNativeComponent.js +1 -0
- package/src/private/specs/modules/{NativeDevToolsSettingsManager.js → NativeReactDevToolsSettingsManager.js} +3 -5
- package/src/private/webapis/performance/EventTiming.js +1 -1
- package/src/private/webapis/performance/Performance.js +3 -21
- package/src/private/webapis/performance/PerformanceObserver.js +68 -155
- package/src/private/webapis/performance/Utilities.js +25 -0
- package/src/private/webapis/performance/specs/NativePerformanceObserver.js +24 -16
- package/src/private/webapis/performance/specs/__mocks__/NativePerformance.js +11 -9
- package/src/private/webapis/performance/specs/__mocks__/NativePerformanceObserver.js +85 -58
- package/types/experimental.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/public/ReactNativeTypes.d.ts +0 -4
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.android.js +0 -35
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.d.ts +0 -20
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.ios.js +0 -49
- package/Libraries/DevToolsSettings/DevToolsSettingsManager.win32.js +0 -35
- package/Libraries/DevToolsSettings/NativeDevToolsSettingsManager.js +0 -13
|
@@ -13,7 +13,6 @@ import type {
|
|
|
13
13
|
PerformanceEntryType,
|
|
14
14
|
} from './PerformanceEntry';
|
|
15
15
|
|
|
16
|
-
import warnOnce from '../../../../Libraries/Utilities/warnOnce';
|
|
17
16
|
import {PerformanceEventTiming} from './EventTiming';
|
|
18
17
|
import {PerformanceEntry} from './PerformanceEntry';
|
|
19
18
|
import {
|
|
@@ -22,6 +21,8 @@ import {
|
|
|
22
21
|
rawToPerformanceEntryType,
|
|
23
22
|
} from './RawPerformanceEntry';
|
|
24
23
|
import NativePerformanceObserver from './specs/NativePerformanceObserver';
|
|
24
|
+
import type {OpaqueNativeObserverHandle} from './specs/NativePerformanceObserver';
|
|
25
|
+
import {warnNoNativePerformanceObserver} from './Utilities';
|
|
25
26
|
|
|
26
27
|
export type PerformanceEntryList = $ReadOnlyArray<PerformanceEntry>;
|
|
27
28
|
|
|
@@ -56,89 +57,24 @@ export class PerformanceObserverEntryList {
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
export type PerformanceObserverCallbackOptions = {
|
|
61
|
+
droppedEntriesCount: number,
|
|
62
|
+
};
|
|
63
|
+
|
|
59
64
|
export type PerformanceObserverCallback = (
|
|
60
65
|
list: PerformanceObserverEntryList,
|
|
61
66
|
observer: PerformanceObserver,
|
|
62
67
|
// The number of buffered entries which got dropped from the buffer due to the buffer being full:
|
|
63
|
-
|
|
68
|
+
options?: PerformanceObserverCallbackOptions,
|
|
64
69
|
) => void;
|
|
65
70
|
|
|
66
|
-
export type PerformanceObserverInit =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
type: PerformanceEntryType,
|
|
72
|
-
durationThreshold?: DOMHighResTimeStamp,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type PerformanceObserverConfig = {|
|
|
76
|
-
callback: PerformanceObserverCallback,
|
|
77
|
-
entryTypes: $ReadOnlySet<PerformanceEntryType>,
|
|
78
|
-
durationThreshold: ?number,
|
|
79
|
-
|};
|
|
80
|
-
|
|
81
|
-
const observerCountPerEntryType: Map<PerformanceEntryType, number> = new Map();
|
|
82
|
-
const registeredObservers: Map<PerformanceObserver, PerformanceObserverConfig> =
|
|
83
|
-
new Map();
|
|
84
|
-
let isOnPerformanceEntryCallbackSet: boolean = false;
|
|
85
|
-
|
|
86
|
-
// This is a callback that gets scheduled and periodically called from the native side
|
|
87
|
-
const onPerformanceEntry = () => {
|
|
88
|
-
if (!NativePerformanceObserver) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const entryResult = NativePerformanceObserver.popPendingEntries();
|
|
92
|
-
const rawEntries = entryResult?.entries ?? [];
|
|
93
|
-
const droppedEntriesCount = entryResult?.droppedEntriesCount;
|
|
94
|
-
if (rawEntries.length === 0) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const entries = rawEntries.map(rawToPerformanceEntry);
|
|
98
|
-
for (const [observer, observerConfig] of registeredObservers.entries()) {
|
|
99
|
-
const entriesForObserver: PerformanceEntryList = entries.filter(entry => {
|
|
100
|
-
if (!observerConfig.entryTypes.has(entry.entryType)) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
entry.entryType === 'event' &&
|
|
106
|
-
observerConfig.durationThreshold != null
|
|
107
|
-
) {
|
|
108
|
-
return entry.duration >= observerConfig.durationThreshold;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return true;
|
|
112
|
-
});
|
|
113
|
-
if (entriesForObserver.length !== 0) {
|
|
114
|
-
try {
|
|
115
|
-
observerConfig.callback(
|
|
116
|
-
new PerformanceObserverEntryList(entriesForObserver),
|
|
117
|
-
observer,
|
|
118
|
-
droppedEntriesCount,
|
|
119
|
-
);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error(error);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
71
|
+
export type PerformanceObserverInit = {
|
|
72
|
+
entryTypes?: Array<PerformanceEntryType>,
|
|
73
|
+
type?: PerformanceEntryType,
|
|
74
|
+
buffered?: boolean,
|
|
75
|
+
durationThreshold?: DOMHighResTimeStamp,
|
|
125
76
|
};
|
|
126
77
|
|
|
127
|
-
export function warnNoNativePerformanceObserver() {
|
|
128
|
-
warnOnce(
|
|
129
|
-
'missing-native-performance-observer',
|
|
130
|
-
'Missing native implementation of PerformanceObserver',
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function applyDurationThresholds() {
|
|
135
|
-
const durationThresholds = Array.from(registeredObservers.values())
|
|
136
|
-
.map(observerConfig => observerConfig.durationThreshold)
|
|
137
|
-
.filter(Boolean);
|
|
138
|
-
|
|
139
|
-
return Math.min(...durationThresholds);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
78
|
function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryType> {
|
|
143
79
|
if (!NativePerformanceObserver) {
|
|
144
80
|
return Object.freeze([]);
|
|
@@ -175,111 +111,96 @@ function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryTyp
|
|
|
175
111
|
* observer.observe({ type: "event" });
|
|
176
112
|
*/
|
|
177
113
|
export class PerformanceObserver {
|
|
114
|
+
#nativeObserverHandle: OpaqueNativeObserverHandle | null = null;
|
|
178
115
|
#callback: PerformanceObserverCallback;
|
|
179
116
|
#type: 'single' | 'multiple' | void;
|
|
117
|
+
#calledAtLeastOnce = false;
|
|
180
118
|
|
|
181
119
|
constructor(callback: PerformanceObserverCallback) {
|
|
182
120
|
this.#callback = callback;
|
|
183
121
|
}
|
|
184
122
|
|
|
185
123
|
observe(options: PerformanceObserverInit): void {
|
|
186
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
!NativePerformanceObserver ||
|
|
126
|
+
NativePerformanceObserver.observe == null
|
|
127
|
+
) {
|
|
187
128
|
warnNoNativePerformanceObserver();
|
|
188
129
|
return;
|
|
189
130
|
}
|
|
190
131
|
|
|
191
132
|
this.#validateObserveOptions(options);
|
|
192
133
|
|
|
193
|
-
|
|
134
|
+
if (this.#nativeObserverHandle == null) {
|
|
135
|
+
this.#nativeObserverHandle = this.#createNativeObserver();
|
|
136
|
+
}
|
|
194
137
|
|
|
195
138
|
if (options.entryTypes) {
|
|
196
139
|
this.#type = 'multiple';
|
|
197
|
-
|
|
198
|
-
|
|
140
|
+
NativePerformanceObserver.observe?.(this.#nativeObserverHandle, {
|
|
141
|
+
entryTypes: options.entryTypes.map(performanceEntryTypeToRaw),
|
|
142
|
+
});
|
|
143
|
+
} else if (options.type) {
|
|
199
144
|
this.#type = 'single';
|
|
200
|
-
|
|
145
|
+
NativePerformanceObserver.observe?.(this.#nativeObserverHandle, {
|
|
146
|
+
type: performanceEntryTypeToRaw(options.type),
|
|
147
|
+
buffered: options.buffered,
|
|
148
|
+
durationThreshold: options.durationThreshold,
|
|
149
|
+
});
|
|
201
150
|
}
|
|
151
|
+
}
|
|
202
152
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const nextEntryTypes = currentEntryTypes
|
|
207
|
-
? union(requestedEntryTypes, currentEntryTypes)
|
|
208
|
-
: requestedEntryTypes;
|
|
209
|
-
|
|
210
|
-
// This `observe` call is a no-op because there are no new things to observe.
|
|
211
|
-
if (currentEntryTypes && currentEntryTypes.size === nextEntryTypes.size) {
|
|
153
|
+
disconnect(): void {
|
|
154
|
+
if (!NativePerformanceObserver) {
|
|
155
|
+
warnNoNativePerformanceObserver();
|
|
212
156
|
return;
|
|
213
157
|
}
|
|
214
158
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
if (!isOnPerformanceEntryCallbackSet) {
|
|
223
|
-
NativePerformanceObserver.setOnPerformanceEntryCallback(
|
|
224
|
-
onPerformanceEntry,
|
|
225
|
-
);
|
|
226
|
-
isOnPerformanceEntryCallbackSet = true;
|
|
159
|
+
if (
|
|
160
|
+
this.#nativeObserverHandle == null ||
|
|
161
|
+
!NativePerformanceObserver.disconnect
|
|
162
|
+
) {
|
|
163
|
+
return;
|
|
227
164
|
}
|
|
228
165
|
|
|
229
|
-
|
|
230
|
-
// this observer.
|
|
231
|
-
const newEntryTypes = currentEntryTypes
|
|
232
|
-
? difference(
|
|
233
|
-
new Set(requestedEntryTypes.keys()),
|
|
234
|
-
new Set(currentEntryTypes.keys()),
|
|
235
|
-
)
|
|
236
|
-
: new Set(requestedEntryTypes.keys());
|
|
237
|
-
for (const type of newEntryTypes) {
|
|
238
|
-
if (!observerCountPerEntryType.has(type)) {
|
|
239
|
-
const rawType = performanceEntryTypeToRaw(type);
|
|
240
|
-
NativePerformanceObserver.startReporting(rawType);
|
|
241
|
-
}
|
|
242
|
-
observerCountPerEntryType.set(
|
|
243
|
-
type,
|
|
244
|
-
(observerCountPerEntryType.get(type) ?? 0) + 1,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
applyDurationThresholds();
|
|
166
|
+
NativePerformanceObserver.disconnect(this.#nativeObserverHandle);
|
|
248
167
|
}
|
|
249
168
|
|
|
250
|
-
|
|
251
|
-
if (
|
|
169
|
+
#createNativeObserver(): OpaqueNativeObserverHandle {
|
|
170
|
+
if (
|
|
171
|
+
!NativePerformanceObserver ||
|
|
172
|
+
!NativePerformanceObserver.createObserver
|
|
173
|
+
) {
|
|
252
174
|
warnNoNativePerformanceObserver();
|
|
253
175
|
return;
|
|
254
176
|
}
|
|
255
177
|
|
|
256
|
-
|
|
257
|
-
if (!observerConfig) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
178
|
+
this.#calledAtLeastOnce = false;
|
|
260
179
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
);
|
|
270
|
-
} else if (numberOfObserversForThisType !== 0) {
|
|
271
|
-
observerCountPerEntryType.set(type, numberOfObserversForThisType - 1);
|
|
180
|
+
return NativePerformanceObserver.createObserver(() => {
|
|
181
|
+
// $FlowNotNull
|
|
182
|
+
const rawEntries = NativePerformanceObserver.takeRecords?.(
|
|
183
|
+
this.#nativeObserverHandle,
|
|
184
|
+
true, // sort records
|
|
185
|
+
);
|
|
186
|
+
if (!rawEntries) {
|
|
187
|
+
return;
|
|
272
188
|
}
|
|
273
|
-
}
|
|
274
189
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
190
|
+
const entries = rawEntries.map(rawToPerformanceEntry);
|
|
191
|
+
const entryList = new PerformanceObserverEntryList(entries);
|
|
192
|
+
|
|
193
|
+
let droppedEntriesCount = 0;
|
|
194
|
+
if (!this.#calledAtLeastOnce) {
|
|
195
|
+
droppedEntriesCount =
|
|
196
|
+
NativePerformanceObserver.getDroppedEntriesCount?.(
|
|
197
|
+
this.#nativeObserverHandle,
|
|
198
|
+
) ?? 0;
|
|
199
|
+
this.#calledAtLeastOnce = true;
|
|
200
|
+
}
|
|
281
201
|
|
|
282
|
-
|
|
202
|
+
this.#callback(entryList, this, {droppedEntriesCount});
|
|
203
|
+
});
|
|
283
204
|
}
|
|
284
205
|
|
|
285
206
|
#validateObserveOptions(options: PerformanceObserverInit): void {
|
|
@@ -309,7 +230,7 @@ export class PerformanceObserver {
|
|
|
309
230
|
);
|
|
310
231
|
}
|
|
311
232
|
|
|
312
|
-
if (entryTypes && durationThreshold
|
|
233
|
+
if (entryTypes && durationThreshold != null) {
|
|
313
234
|
throw new TypeError(
|
|
314
235
|
"Failed to execute 'observe' on 'PerformanceObserver': An observe() call must not include both entryTypes and durationThreshold arguments.",
|
|
315
236
|
);
|
|
@@ -320,12 +241,4 @@ export class PerformanceObserver {
|
|
|
320
241
|
getSupportedPerformanceEntryTypes();
|
|
321
242
|
}
|
|
322
243
|
|
|
323
|
-
function union<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): Set<T> {
|
|
324
|
-
return new Set([...a, ...b]);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function difference<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): Set<T> {
|
|
328
|
-
return new Set([...a].filter(x => !b.has(x)));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
244
|
export {PerformanceEventTiming};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* @format
|
|
8
|
+
* @flow strict
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import warnOnce from '../../../../Libraries/Utilities/warnOnce';
|
|
12
|
+
|
|
13
|
+
export function warnNoNativePerformance() {
|
|
14
|
+
warnOnce(
|
|
15
|
+
'missing-native-performance',
|
|
16
|
+
'Missing native implementation of Performance',
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function warnNoNativePerformanceObserver() {
|
|
21
|
+
warnOnce(
|
|
22
|
+
'missing-native-performance-observer',
|
|
23
|
+
'Missing native implementation of PerformanceObserver',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -14,6 +14,10 @@ import * as TurboModuleRegistry from '../../../../../Libraries/TurboModule/Turbo
|
|
|
14
14
|
|
|
15
15
|
export type RawPerformanceEntryType = number;
|
|
16
16
|
|
|
17
|
+
export type OpaqueNativeObserverHandle = mixed;
|
|
18
|
+
|
|
19
|
+
export type NativeBatchedObserverCallback = () => void;
|
|
20
|
+
|
|
17
21
|
export type RawPerformanceEntry = {|
|
|
18
22
|
name: string,
|
|
19
23
|
entryType: RawPerformanceEntryType,
|
|
@@ -25,26 +29,30 @@ export type RawPerformanceEntry = {|
|
|
|
25
29
|
interactionId?: number,
|
|
26
30
|
|};
|
|
27
31
|
|
|
28
|
-
export type
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
export type PerformanceObserverInit = {
|
|
33
|
+
entryTypes?: $ReadOnlyArray<number>,
|
|
34
|
+
type?: number,
|
|
35
|
+
buffered?: boolean,
|
|
36
|
+
durationThreshold?: number,
|
|
37
|
+
};
|
|
32
38
|
|
|
33
39
|
export interface Spec extends TurboModule {
|
|
34
|
-
+startReporting: (entryType: RawPerformanceEntryType) => void;
|
|
35
|
-
+stopReporting: (entryType: RawPerformanceEntryType) => void;
|
|
36
|
-
+setIsBuffered: (
|
|
37
|
-
entryTypes: $ReadOnlyArray<RawPerformanceEntryType>,
|
|
38
|
-
isBuffered: boolean,
|
|
39
|
-
) => void;
|
|
40
|
-
+popPendingEntries: () => GetPendingEntriesResult;
|
|
41
|
-
+setOnPerformanceEntryCallback: (callback?: () => void) => void;
|
|
42
|
-
+logRawEntry: (entry: RawPerformanceEntry) => void;
|
|
43
40
|
+getEventCounts: () => $ReadOnlyArray<[string, number]>;
|
|
44
|
-
+
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
+createObserver?: (
|
|
42
|
+
callback: NativeBatchedObserverCallback,
|
|
43
|
+
) => OpaqueNativeObserverHandle;
|
|
44
|
+
+getDroppedEntriesCount?: (observer: OpaqueNativeObserverHandle) => number;
|
|
45
|
+
|
|
46
|
+
+observe?: (
|
|
47
|
+
observer: OpaqueNativeObserverHandle,
|
|
48
|
+
options: PerformanceObserverInit,
|
|
47
49
|
) => void;
|
|
50
|
+
+disconnect?: (observer: OpaqueNativeObserverHandle) => void;
|
|
51
|
+
+takeRecords?: (
|
|
52
|
+
observer: OpaqueNativeObserverHandle,
|
|
53
|
+
sort: boolean,
|
|
54
|
+
) => $ReadOnlyArray<RawPerformanceEntry>;
|
|
55
|
+
|
|
48
56
|
+clearEntries: (
|
|
49
57
|
entryType?: RawPerformanceEntryType,
|
|
50
58
|
entryName?: string,
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
import type {
|
|
12
12
|
NativeMemoryInfo,
|
|
13
13
|
ReactNativeStartupTiming,
|
|
14
|
-
Spec as NativePerformance,
|
|
15
14
|
} from '../NativePerformance';
|
|
16
15
|
|
|
17
16
|
import {RawPerformanceEntryTypeValues} from '../../RawPerformanceEntry';
|
|
18
|
-
import
|
|
17
|
+
import NativePerformance from '../NativePerformance';
|
|
18
|
+
import {logMockEntry} from './NativePerformanceObserver';
|
|
19
19
|
|
|
20
20
|
const marks: Map<string, number> = new Map();
|
|
21
21
|
|
|
22
|
-
const NativePerformanceMock: NativePerformance = {
|
|
22
|
+
const NativePerformanceMock: typeof NativePerformance = {
|
|
23
23
|
mark: (name: string, startTime: number): void => {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
NativePerformance?.mark(name, startTime);
|
|
25
|
+
marks.set(name, startTime);
|
|
26
|
+
logMockEntry({
|
|
26
27
|
entryType: RawPerformanceEntryTypeValues.MARK,
|
|
28
|
+
name,
|
|
27
29
|
startTime,
|
|
28
30
|
duration: 0,
|
|
29
31
|
});
|
|
30
|
-
marks.set(name, startTime);
|
|
31
32
|
},
|
|
32
33
|
|
|
33
34
|
measure: (
|
|
@@ -40,11 +41,12 @@ const NativePerformanceMock: NativePerformance = {
|
|
|
40
41
|
): void => {
|
|
41
42
|
const start = startMark != null ? marks.get(startMark) ?? 0 : startTime;
|
|
42
43
|
const end = endMark != null ? marks.get(endMark) ?? 0 : endTime;
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
NativePerformance?.measure(name, start, end);
|
|
45
|
+
logMockEntry({
|
|
45
46
|
entryType: RawPerformanceEntryTypeValues.MEASURE,
|
|
47
|
+
name,
|
|
46
48
|
startTime: start,
|
|
47
|
-
duration: duration ??
|
|
49
|
+
duration: duration ?? end - start,
|
|
48
50
|
});
|
|
49
51
|
},
|
|
50
52
|
|
|
@@ -9,90 +9,117 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type {
|
|
12
|
-
|
|
12
|
+
NativeBatchedObserverCallback,
|
|
13
13
|
RawPerformanceEntry,
|
|
14
14
|
RawPerformanceEntryType,
|
|
15
|
+
OpaqueNativeObserverHandle,
|
|
16
|
+
PerformanceObserverInit,
|
|
15
17
|
Spec as NativePerformanceObserver,
|
|
16
18
|
} from '../NativePerformanceObserver';
|
|
17
19
|
|
|
18
20
|
import {RawPerformanceEntryTypeValues} from '../../RawPerformanceEntry';
|
|
19
21
|
|
|
20
|
-
|
|
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
|
+
|
|
22
32
|
const eventCounts: Map<string, number> = new Map();
|
|
23
|
-
|
|
33
|
+
let observers: MockObserver[] = [];
|
|
24
34
|
let entries: Array<RawPerformanceEntry> = [];
|
|
25
|
-
let onPerformanceEntryCallback: ?() => void;
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
reportingType.add(entryType);
|
|
30
|
-
},
|
|
36
|
+
export function logMockEntry(entry: RawPerformanceEntry) {
|
|
37
|
+
entries.push(entry);
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
36
50
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
for (const entryType of entryTypes) {
|
|
42
|
-
if (isBuffered) {
|
|
43
|
-
isAlwaysLogged.add(entryType);
|
|
44
|
-
} else {
|
|
45
|
-
isAlwaysLogged.delete(entryType);
|
|
51
|
+
if (entry.entryType === RawPerformanceEntryTypeValues.EVENT) {
|
|
52
|
+
const {durationThreshold = 0} = observer.options;
|
|
53
|
+
if (durationThreshold > 0 && entry.duration < durationThreshold) {
|
|
54
|
+
continue;
|
|
46
55
|
}
|
|
47
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());
|
|
48
78
|
},
|
|
49
79
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
createObserver: (
|
|
81
|
+
callback: NativeBatchedObserverCallback,
|
|
82
|
+
): OpaqueNativeObserverHandle => {
|
|
83
|
+
const observer: MockObserver = {
|
|
84
|
+
callback,
|
|
85
|
+
entries: [],
|
|
86
|
+
options: {},
|
|
54
87
|
droppedEntriesCount: 0,
|
|
55
|
-
entries: res,
|
|
56
88
|
};
|
|
89
|
+
|
|
90
|
+
return observer;
|
|
57
91
|
},
|
|
58
92
|
|
|
59
|
-
|
|
60
|
-
|
|
93
|
+
getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle): number => {
|
|
94
|
+
// $FlowFixMe
|
|
95
|
+
const mockObserver = (observer: any) as MockObserver;
|
|
96
|
+
return mockObserver.droppedEntriesCount;
|
|
61
97
|
},
|
|
62
98
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
entry.duration < durationThreshold
|
|
72
|
-
) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
entries.push(entry);
|
|
76
|
-
// $FlowFixMe[incompatible-call]
|
|
77
|
-
global.queueMicrotask(() => {
|
|
78
|
-
// We want to emulate the way it's done in native (i.e. async/batched)
|
|
79
|
-
onPerformanceEntryCallback?.();
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (entry.entryType === RawPerformanceEntryTypeValues.EVENT) {
|
|
83
|
-
eventCounts.set(entry.name, (eventCounts.get(entry.name) ?? 0) + 1);
|
|
84
|
-
}
|
|
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);
|
|
85
107
|
},
|
|
86
108
|
|
|
87
|
-
|
|
88
|
-
|
|
109
|
+
disconnect: (observer: OpaqueNativeObserverHandle): void => {
|
|
110
|
+
// $FlowFixMe
|
|
111
|
+
const mockObserver = (observer: any) as MockObserver;
|
|
112
|
+
observers = observers.filter(e => e !== mockObserver);
|
|
89
113
|
},
|
|
90
114
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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;
|
|
96
123
|
},
|
|
97
124
|
|
|
98
125
|
clearEntries: (entryType?: RawPerformanceEntryType, entryName?: string) => {
|
package/types/experimental.d.ts
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -104,7 +104,6 @@ export * from '../Libraries/Components/View/ViewAccessibility';
|
|
|
104
104
|
export * from '../Libraries/Components/View/ViewPropTypes';
|
|
105
105
|
export * from '../Libraries/Components/Button';
|
|
106
106
|
export * from '../Libraries/Core/registerCallableModule';
|
|
107
|
-
export * from '../Libraries/DevToolsSettings/DevToolsSettingsManager';
|
|
108
107
|
export * from '../Libraries/EventEmitter/NativeEventEmitter';
|
|
109
108
|
export * from '../Libraries/EventEmitter/RCTDeviceEventEmitter';
|
|
110
109
|
export * from '../Libraries/EventEmitter/RCTNativeAppEventEmitter';
|
|
@@ -142,6 +141,7 @@ export * as TurboModuleRegistry from '../Libraries/TurboModule/TurboModuleRegist
|
|
|
142
141
|
export * from '../Libraries/Types/CoreEventTypes';
|
|
143
142
|
export * from '../Libraries/Utilities/Appearance';
|
|
144
143
|
export * from '../Libraries/Utilities/BackHandler';
|
|
144
|
+
export * from '../src/private/devmenu/DevMenu';
|
|
145
145
|
export * from '../Libraries/Utilities/DevSettings';
|
|
146
146
|
export * from '../Libraries/Utilities/Dimensions';
|
|
147
147
|
export * from '../Libraries/Utilities/PixelRatio';
|