@office-iss/react-native-win32 0.0.0-canary.292 → 0.0.0-canary.293

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 (97) hide show
  1. package/.flowconfig +1 -1
  2. package/CHANGELOG.json +28 -1
  3. package/CHANGELOG.md +14 -4
  4. package/Libraries/Blob/URL.js +13 -1
  5. package/Libraries/Components/Pressable/Pressable.js +4 -1
  6. package/Libraries/Components/Pressable/Pressable.win32.js +4 -1
  7. package/Libraries/Components/ScrollView/ScrollView.d.ts +1 -1
  8. package/Libraries/Components/Switch/Switch.js +7 -3
  9. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +1 -0
  10. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  11. package/Libraries/Components/TextInput/TextInput.flow.js +25 -0
  12. package/Libraries/Components/TextInput/TextInput.flow.win32.js +25 -1
  13. package/Libraries/Components/TextInput/TextInput.js +2 -0
  14. package/Libraries/Components/TextInput/TextInput.win32.js +2 -0
  15. package/Libraries/Components/View/View.js +18 -21
  16. package/Libraries/Components/View/View.win32.js +21 -24
  17. package/Libraries/Core/ReactNativeVersion.js +1 -1
  18. package/Libraries/Core/setUpReactDevTools.js +5 -5
  19. package/Libraries/Image/ImageProps.js +2 -3
  20. package/Libraries/Image/ImageSource.js +3 -1
  21. package/Libraries/Image/ImageSourceUtils.js +4 -2
  22. package/Libraries/Lists/FlatList.d.ts +2 -2
  23. package/Libraries/Lists/SectionListModern.js +1 -2
  24. package/Libraries/LogBox/Data/LogBoxData.js +1 -1
  25. package/Libraries/NativeModules/specs/NativeDevMenu.js +2 -2
  26. package/Libraries/ReactNative/AppContainer-dev.js +3 -2
  27. package/Libraries/ReactNative/RendererImplementation.js +6 -5
  28. package/Libraries/ReactNative/renderApplication.js +9 -0
  29. package/Libraries/Renderer/implementations/ReactFabric-dev.js +4840 -4748
  30. package/Libraries/Renderer/implementations/ReactFabric-prod.js +4947 -4829
  31. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3998 -3888
  32. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +5005 -4948
  33. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +2744 -2652
  34. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5020 -4933
  35. package/Libraries/Renderer/shims/ReactFabric.js +3 -1
  36. package/Libraries/Renderer/shims/ReactFeatureFlags.js +3 -1
  37. package/Libraries/Renderer/shims/ReactNative.js +3 -1
  38. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  39. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +3 -1
  40. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
  41. package/Libraries/StyleSheet/StyleSheetTypes.js +47 -3
  42. package/Libraries/StyleSheet/processBackgroundImage.js +670 -214
  43. package/Libraries/Text/TextNativeComponent.js +0 -4
  44. package/Libraries/Text/TextNativeComponent.win32.js +0 -4
  45. package/index.js +1 -288
  46. package/index.win32.js +3 -292
  47. package/overrides.json +11 -11
  48. package/package.json +15 -15
  49. package/src/private/{devmenu → devsupport/devmenu}/DevMenu.js +1 -1
  50. package/src/private/{inspector → devsupport/devmenu/elementinspector}/BorderBox.js +2 -2
  51. package/src/private/{inspector → devsupport/devmenu/elementinspector}/BoxInspector.js +5 -4
  52. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementBox.js +7 -5
  53. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ElementProperties.js +10 -9
  54. package/src/private/{inspector → devsupport/devmenu/elementinspector}/Inspector.js +13 -11
  55. package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorOverlay.js +4 -3
  56. package/src/private/{inspector → devsupport/devmenu/elementinspector}/InspectorPanel.js +8 -7
  57. package/src/private/{inspector → devsupport/devmenu/elementinspector}/NetworkOverlay.js +9 -8
  58. package/src/private/{inspector → devsupport/devmenu/elementinspector}/ReactDevToolsOverlay.js +7 -7
  59. package/src/private/{inspector → devsupport/devmenu/elementinspector}/StyleInspector.js +6 -5
  60. package/src/private/{inspector → devsupport/devmenu/elementinspector}/XHRInterceptor.js +2 -2
  61. package/src/private/{inspector → devsupport/devmenu/elementinspector}/getInspectorDataForViewAtPoint.js +2 -2
  62. package/src/private/{inspector → devsupport/devmenu/elementinspector}/resolveBoxStyle.js +1 -1
  63. package/src/private/{inspector → devsupport/devmenu/perfmonitor}/PerformanceOverlay.js +5 -4
  64. package/src/private/{specs_DEPRECATED/modules → devsupport/devmenu/specs}/NativeDevMenu.js +2 -2
  65. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.android.js +1 -1
  66. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.ios.js +1 -1
  67. package/src/private/{debugging → devsupport/rndevtools}/ReactDevToolsSettingsManager.win32.js +1 -1
  68. package/src/private/{debugging → devsupport/rndevtools}/setUpFuseboxReactDevToolsDispatcher.js +1 -1
  69. package/src/private/{fusebox → devsupport/rndevtools}/specs/NativeReactDevToolsRuntimeSettingsModule.js +2 -2
  70. package/src/private/{specs_DEPRECATED/modules → devsupport/rndevtools/specs}/NativeReactDevToolsSettingsManager.js +2 -2
  71. package/src/private/featureflags/ReactNativeFeatureFlags.js +22 -17
  72. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +5 -4
  73. package/src/private/renderer/errorhandling/ErrorHandlers.js +2 -2
  74. package/src/private/specs_DEPRECATED/modules/NativeSampleTurboModule.js +3 -0
  75. package/src/private/types/HostInstance.js +2 -2
  76. package/types/index.d.ts +1 -1
  77. package/types/public/ReactNativeTypes.d.ts +2 -2
  78. package/Libraries/BatchedBridge/__mocks__/MessageQueueTestConfig.js +0 -38
  79. package/Libraries/BatchedBridge/__mocks__/MessageQueueTestModule.js +0 -22
  80. package/Libraries/Blob/__mocks__/BlobModule.js +0 -16
  81. package/Libraries/Blob/__mocks__/FileReaderModule.js +0 -20
  82. package/Libraries/Components/RefreshControl/__mocks__/RefreshControlMock.js +0 -32
  83. package/Libraries/Core/__mocks__/ErrorUtils.js +0 -33
  84. package/Libraries/Core/__mocks__/NativeExceptionsManager.js +0 -19
  85. package/Libraries/EventEmitter/__mocks__/NativeEventEmitter.js +0 -49
  86. package/Libraries/Lists/__flowtests__/FlatList-flowtest.js +0 -118
  87. package/Libraries/Lists/__flowtests__/SectionList-flowtest.js +0 -134
  88. package/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +0 -58
  89. package/Libraries/Utilities/__mocks__/BackHandler.js +0 -45
  90. package/Libraries/Utilities/__mocks__/GlobalPerformanceLogger.js +0 -16
  91. package/Libraries/Utilities/__mocks__/PixelRatio.js +0 -25
  92. package/Libraries/__flowtests__/ReactNativeTypes-flowtest.js +0 -30
  93. package/Libraries/vendor/emitter/__flowtests__/EventEmitter-flowtest.js +0 -81
  94. package/jest/__tests__/setup-test.js +0 -18
  95. package/src/private/webapis/performance/specs/__mocks__/NativePerformanceMock.js +0 -267
  96. /package/src/private/{devmenu → devsupport/devmenu}/DevMenu.d.ts +0 -0
  97. /package/src/private/{debugging → devsupport/rndevtools}/FuseboxSessionObserver.js +0 -0
@@ -1,134 +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
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- import SectionList from '../SectionList';
14
- import * as React from 'react';
15
-
16
- function renderMyListItem(info: {
17
- item: {title: string, ...},
18
- index: number,
19
- ...
20
- }) {
21
- return <span />;
22
- }
23
-
24
- const renderMyHeader = ({
25
- section,
26
- }: {
27
- section: {fooNumber: number, ...} & Object,
28
- ...
29
- }) => <span />;
30
-
31
- module.exports = {
32
- testGoodDataWithGoodItem(): React.Node {
33
- const sections = [
34
- {
35
- key: 'a',
36
- data: [
37
- {
38
- title: 'foo',
39
- key: 1,
40
- },
41
- ],
42
- },
43
- ];
44
- return <SectionList renderItem={renderMyListItem} sections={sections} />;
45
- },
46
-
47
- testBadRenderItemFunction(): $ReadOnlyArray<React.Node> {
48
- const sections = [
49
- {
50
- key: 'a',
51
- data: [
52
- {
53
- title: 'foo',
54
- key: 1,
55
- },
56
- ],
57
- },
58
- ];
59
- return [
60
- <SectionList
61
- // $FlowExpectedError - title should be inside `item`
62
- renderItem={(info: {title: string, ...}) => <span />}
63
- sections={sections}
64
- />,
65
- <SectionList
66
- // $FlowExpectedError - bad index type string, should be number
67
- renderItem={(info: {index: string}) => <span />}
68
- sections={sections}
69
- />,
70
- // EverythingIsFine
71
- <SectionList
72
- renderItem={(info: {item: {title: string, ...}, ...}) => <span />}
73
- sections={sections}
74
- />,
75
- ];
76
- },
77
-
78
- testBadInheritedDefaultProp(): React.MixedElement {
79
- const sections: $FlowFixMe = [];
80
- return (
81
- <SectionList
82
- renderItem={renderMyListItem}
83
- sections={sections}
84
- // $FlowExpectedError - bad windowSize type "big"
85
- windowSize="big"
86
- />
87
- );
88
- },
89
-
90
- testMissingData(): React.MixedElement {
91
- // $FlowExpectedError - missing `sections` prop
92
- return <SectionList renderItem={renderMyListItem} />;
93
- },
94
-
95
- testBadSectionsShape(): React.MixedElement {
96
- const sections = [
97
- {
98
- key: 'a',
99
- items: [
100
- {
101
- title: 'foo',
102
- key: 1,
103
- },
104
- ],
105
- },
106
- ];
107
- // $FlowExpectedError - section missing `data` field
108
- return <SectionList renderItem={renderMyListItem} sections={sections} />;
109
- },
110
-
111
- testBadSectionsMetadata(): React.MixedElement {
112
- const sections = [
113
- {
114
- key: 'a',
115
- fooNumber: 'string',
116
- data: [
117
- {
118
- title: 'foo',
119
- key: 1,
120
- },
121
- ],
122
- },
123
- ];
124
- return (
125
- <SectionList
126
- renderSectionHeader={renderMyHeader}
127
- renderItem={renderMyListItem}
128
- /* $FlowExpectedError - section has bad meta data `fooNumber` field of
129
- * type string */
130
- sections={sections}
131
- />
132
- );
133
- },
134
- };
@@ -1,58 +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-local
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- import type {ImageStyleProp, TextStyleProp} from '../StyleSheet';
14
-
15
- const StyleSheet = require('../StyleSheet').default;
16
- const imageStyle = {tintColor: 'rgb(0, 0, 0)'};
17
- const textStyle = {color: 'rgb(0, 0, 0)'};
18
-
19
- module.exports = {
20
- testGoodCompose() {
21
- (StyleSheet.compose(imageStyle, imageStyle): ImageStyleProp);
22
-
23
- (StyleSheet.compose(textStyle, textStyle): TextStyleProp);
24
-
25
- (StyleSheet.compose(null, null): TextStyleProp);
26
-
27
- (StyleSheet.compose(textStyle, null): TextStyleProp);
28
-
29
- (StyleSheet.compose(
30
- textStyle,
31
- Math.random() < 0.5 ? textStyle : null,
32
- ): TextStyleProp);
33
-
34
- (StyleSheet.compose([textStyle], null): TextStyleProp);
35
-
36
- (StyleSheet.compose([textStyle], null): TextStyleProp);
37
-
38
- (StyleSheet.compose([textStyle], [textStyle]): TextStyleProp);
39
- },
40
-
41
- testBadCompose() {
42
- // $FlowExpectedError - Incompatible type.
43
- (StyleSheet.compose(textStyle, textStyle): ImageStyleProp);
44
-
45
- // $FlowExpectedError - Incompatible type.
46
- (StyleSheet.compose(
47
- // $FlowExpectedError - Incompatible type.
48
- [textStyle],
49
- null,
50
- ): ImageStyleProp);
51
-
52
- // $FlowExpectedError - Incompatible type.
53
- (StyleSheet.compose(
54
- Math.random() < 0.5 ? textStyle : null,
55
- null,
56
- ): ImageStyleProp);
57
- },
58
- };
@@ -1,45 +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
- * @format
8
- */
9
-
10
- 'use strict';
11
-
12
- const _backPressSubscriptions = new Set();
13
-
14
- const BackHandler = {
15
- exitApp: jest.fn(),
16
-
17
- addEventListener: function (
18
- eventName: BackPressEventName,
19
- handler: () => ?boolean,
20
- ): {remove: () => void} {
21
- _backPressSubscriptions.add(handler);
22
- return {
23
- remove: () => {
24
- _backPressSubscriptions.delete(handler);
25
- },
26
- };
27
- },
28
-
29
- mockPressBack: function () {
30
- let invokeDefault = true;
31
- const subscriptions = [..._backPressSubscriptions].reverse();
32
- for (let i = 0; i < subscriptions.length; ++i) {
33
- if (subscriptions[i]()) {
34
- invokeDefault = false;
35
- break;
36
- }
37
- }
38
-
39
- if (invokeDefault) {
40
- BackHandler.exitApp();
41
- }
42
- },
43
- };
44
-
45
- module.exports = BackHandler;
@@ -1,16 +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
- * @format
8
- */
9
-
10
- 'use strict';
11
-
12
- const GlobalPerformanceLogger = jest
13
- .unmock('../createPerformanceLogger')
14
- .genMockFromModule('../GlobalPerformanceLogger').default;
15
-
16
- export default GlobalPerformanceLogger;
@@ -1,25 +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
- * @format
8
- */
9
-
10
- 'use strict';
11
-
12
- const PixelRatio = {
13
- get: jest.fn().mockReturnValue(2),
14
- getFontScale: jest.fn(() => PixelRatio.get()),
15
- getPixelSizeForLayoutSize: jest.fn(layoutSize =>
16
- Math.round(layoutSize * PixelRatio.get()),
17
- ),
18
- roundToNearestPixel: jest.fn(layoutSize => {
19
- const ratio = PixelRatio.get();
20
- return Math.round(layoutSize * ratio) / ratio;
21
- }),
22
- startDetecting: jest.fn(),
23
- };
24
-
25
- export default PixelRatio;
@@ -1,30 +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
8
- * @format
9
- */
10
-
11
- import type {HostComponent} from '../../src/private/types/HostComponent';
12
- import type {HostInstance} from '../../src/private/types/HostInstance';
13
-
14
- import * as React from 'react';
15
-
16
- function takesHostComponentInstance(instance: HostInstance | null): void {}
17
-
18
- const MyHostComponent = (('Host': any): HostComponent<{...}>);
19
-
20
- <MyHostComponent
21
- ref={hostComponentRef => {
22
- takesHostComponentInstance(hostComponentRef);
23
-
24
- if (hostComponentRef == null) {
25
- return;
26
- }
27
-
28
- hostComponentRef.measureLayout(hostComponentRef, () => {});
29
- }}
30
- />;
@@ -1,81 +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 EventEmitter from '../EventEmitter';
12
-
13
- const emitter = new EventEmitter<{
14
- void: [],
15
- string: [string],
16
- strings: [string, string],
17
- error: [Error],
18
- }>();
19
-
20
- const subscription = emitter.addListener('void', unknown => {
21
- (unknown: void);
22
- });
23
- subscription.remove();
24
-
25
- emitter.addListener('string', foo => {
26
- (foo: string);
27
- });
28
- emitter.addListener('strings', (foo, bar) => {
29
- (foo: string);
30
- (bar: string);
31
- });
32
- emitter.addListener('error', error => {
33
- (error: Error);
34
- });
35
-
36
- emitter.emit('void');
37
- emitter.emit('string', 'foo');
38
- emitter.emit('strings', 'foo', 'bar');
39
- emitter.emit('error', new Error());
40
-
41
- emitter.removeAllListeners('void');
42
- emitter.removeAllListeners('string');
43
- emitter.removeAllListeners('strings');
44
- emitter.removeAllListeners('error');
45
- emitter.removeAllListeners();
46
-
47
- emitter.listenerCount('void');
48
- emitter.listenerCount('string');
49
- emitter.listenerCount('strings');
50
- emitter.listenerCount('error');
51
-
52
- // $FlowExpectedError[prop-missing]
53
- emitter.addListener('does-not-exist', () => {
54
- // ...
55
- });
56
-
57
- // $FlowExpectedError[prop-missing]
58
- subscription.context;
59
- // $FlowExpectedError[prop-missing]
60
- subscription.listener;
61
- // $FlowExpectedError[prop-missing]
62
- subscription.once;
63
-
64
- // $FlowExpectedError[invalid-tuple-arity]
65
- emitter.emit('void', undefined);
66
- // $FlowExpectedError[incompatible-call]
67
- emitter.emit('string', 123);
68
- // $FlowExpectedError[invalid-tuple-arity]
69
- emitter.emit('strings', 'foo');
70
- // $FlowExpectedError[invalid-tuple-arity]
71
- emitter.emit('strings', 'foo', 'bar', 'baz');
72
- // $FlowExpectedError[invalid-tuple-arity]
73
- emitter.emit('error');
74
- // $FlowExpectedError[prop-missing]
75
- emitter.emit('does-not-exist');
76
-
77
- // $FlowExpectedError[prop-missing]
78
- emitter.removeAllListeners('does-not-exist');
79
-
80
- // $FlowExpectedError[prop-missing]
81
- emitter.listenerCount('does-not-exist');
@@ -1,18 +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
- * @oncall react_native
10
- */
11
-
12
- import NativeExceptionsManager from '../../Libraries/Core/NativeExceptionsManager';
13
-
14
- test('NativeExceptionsManager is a mock', () => {
15
- expect(jest.isMockFunction(NativeExceptionsManager.reportException)).toBe(
16
- true,
17
- );
18
- });
@@ -1,267 +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
- NativeMemoryInfo,
14
- NativePerformanceMarkResult,
15
- NativePerformanceMeasureResult,
16
- OpaqueNativeObserverHandle,
17
- PerformanceObserverInit,
18
- RawPerformanceEntry,
19
- RawPerformanceEntryType,
20
- ReactNativeStartupTiming,
21
- } from '../NativePerformance';
22
- import typeof NativePerformance from '../NativePerformance';
23
-
24
- import {RawPerformanceEntryTypeValues} from '../../internals/RawPerformanceEntry';
25
-
26
- type MockObserver = {
27
- handleEntry: (entry: RawPerformanceEntry) => void,
28
- callback: NativeBatchedObserverCallback,
29
- didScheduleFlushBuffer: boolean,
30
- entries: Array<RawPerformanceEntry>,
31
- options: PerformanceObserverInit,
32
- droppedEntriesCount: number,
33
- };
34
-
35
- const eventCounts: Map<string, number> = new Map();
36
- const observers: Set<MockObserver> = new Set();
37
- const marks: Map<string, number> = new Map();
38
- let entries: Array<RawPerformanceEntry> = [];
39
-
40
- function getMockObserver(
41
- opaqueNativeObserverHandle: OpaqueNativeObserverHandle,
42
- ): MockObserver {
43
- return opaqueNativeObserverHandle as $FlowFixMe as MockObserver;
44
- }
45
-
46
- function createMockObserver(callback: NativeBatchedObserverCallback) {
47
- const observer: MockObserver = {
48
- callback,
49
- didScheduleFlushBuffer: false,
50
- entries: [],
51
- options: {},
52
- droppedEntriesCount: 0,
53
- handleEntry: (entry: RawPerformanceEntry) => {
54
- if (
55
- observer.options.type !== entry.entryType &&
56
- !observer.options.entryTypes?.includes(entry.entryType)
57
- ) {
58
- return;
59
- }
60
-
61
- if (
62
- entry.entryType === RawPerformanceEntryTypeValues.EVENT &&
63
- entry.duration < (observer.options?.durationThreshold ?? 0)
64
- ) {
65
- return;
66
- }
67
-
68
- observer.entries.push(entry);
69
-
70
- if (!observer.didScheduleFlushBuffer) {
71
- observer.didScheduleFlushBuffer = true;
72
- // $FlowFixMe[incompatible-call]
73
- global.queueMicrotask(() => {
74
- observer.didScheduleFlushBuffer = false;
75
- // We want to emulate the way it's done in native (i.e. async/batched)
76
- observer.callback();
77
- });
78
- }
79
- },
80
- };
81
-
82
- return observer;
83
- }
84
-
85
- export function reportEntry(entry: RawPerformanceEntry) {
86
- entries.push(entry);
87
-
88
- switch (entry.entryType) {
89
- case RawPerformanceEntryTypeValues.MARK:
90
- marks.set(entry.name, entry.startTime);
91
- break;
92
- case RawPerformanceEntryTypeValues.MEASURE:
93
- break;
94
- case RawPerformanceEntryTypeValues.EVENT:
95
- eventCounts.set(entry.name, (eventCounts.get(entry.name) ?? 0) + 1);
96
- break;
97
- }
98
-
99
- for (const observer of observers) {
100
- observer.handleEntry(entry);
101
- }
102
- }
103
-
104
- let currentTime: number = 12;
105
-
106
- const NativePerformanceMock = {
107
- setCurrentTime: (time: number): void => {
108
- currentTime = time;
109
- },
110
-
111
- now: (): number => currentTime,
112
-
113
- markWithResult: (
114
- name: string,
115
- startTime?: number,
116
- ): NativePerformanceMarkResult => {
117
- const computedStartTime = startTime ?? performance.now();
118
-
119
- marks.set(name, computedStartTime);
120
- reportEntry({
121
- entryType: RawPerformanceEntryTypeValues.MARK,
122
- name,
123
- startTime: computedStartTime,
124
- duration: 0,
125
- });
126
-
127
- return computedStartTime;
128
- },
129
-
130
- measureWithResult: (
131
- name: string,
132
- startTime: number,
133
- endTime: number,
134
- duration?: number,
135
- startMark?: string,
136
- endMark?: string,
137
- ): NativePerformanceMeasureResult => {
138
- const start = startMark != null ? marks.get(startMark) : startTime;
139
- const end = endMark != null ? marks.get(endMark) : endTime;
140
-
141
- if (start === undefined) {
142
- throw new Error('startMark does not exist');
143
- }
144
-
145
- if (end === undefined) {
146
- throw new Error('endMark does not exist');
147
- }
148
-
149
- const computedDuration = duration ?? end - start;
150
- reportEntry({
151
- entryType: RawPerformanceEntryTypeValues.MEASURE,
152
- name,
153
- startTime: start,
154
- duration: computedDuration,
155
- });
156
-
157
- return [start, computedDuration];
158
- },
159
-
160
- getSimpleMemoryInfo: (): NativeMemoryInfo => {
161
- return {};
162
- },
163
-
164
- getReactNativeStartupTiming: (): ReactNativeStartupTiming => {
165
- return {
166
- startTime: 0,
167
- endTime: 0,
168
- executeJavaScriptBundleEntryPointStart: 0,
169
- executeJavaScriptBundleEntryPointEnd: 0,
170
- initializeRuntimeStart: 0,
171
- initializeRuntimeEnd: 0,
172
- };
173
- },
174
-
175
- getEventCounts: (): $ReadOnlyArray<[string, number]> => {
176
- return Array.from(eventCounts.entries());
177
- },
178
-
179
- createObserver: (
180
- callback: NativeBatchedObserverCallback,
181
- ): OpaqueNativeObserverHandle => {
182
- return createMockObserver(callback);
183
- },
184
-
185
- getDroppedEntriesCount: (observer: OpaqueNativeObserverHandle): number => {
186
- return getMockObserver(observer).droppedEntriesCount;
187
- },
188
-
189
- observe: (
190
- observer: OpaqueNativeObserverHandle,
191
- options: PerformanceObserverInit,
192
- ): void => {
193
- const mockObserver = getMockObserver(observer);
194
- mockObserver.options = options;
195
- observers.add(mockObserver);
196
- },
197
-
198
- disconnect: (observer: OpaqueNativeObserverHandle): void => {
199
- const mockObserver = getMockObserver(observer);
200
- observers.delete(mockObserver);
201
- },
202
-
203
- takeRecords: (
204
- observer: OpaqueNativeObserverHandle,
205
- ): $ReadOnlyArray<RawPerformanceEntry> => {
206
- const mockObserver = getMockObserver(observer);
207
- const observerEntries = mockObserver.entries;
208
- mockObserver.entries = [];
209
- return observerEntries.sort((a, b) => a.startTime - b.startTime);
210
- },
211
-
212
- clearMarks: (entryName?: string) => {
213
- if (entryName != null) {
214
- marks.delete(entryName);
215
- } else {
216
- marks.clear();
217
- }
218
-
219
- entries = entries.filter(
220
- entry =>
221
- entry.entryType !== RawPerformanceEntryTypeValues.MARK ||
222
- (entryName != null && entry.name !== entryName),
223
- );
224
- },
225
-
226
- clearMeasures: (entryName?: string) => {
227
- entries = entries.filter(
228
- entry =>
229
- entry.entryType !== RawPerformanceEntryTypeValues.MEASURE ||
230
- (entryName != null && entry.name !== entryName),
231
- );
232
- },
233
-
234
- getEntries: (): $ReadOnlyArray<RawPerformanceEntry> => {
235
- return [...entries].sort((a, b) => a.startTime - b.startTime);
236
- },
237
-
238
- getEntriesByName: (
239
- entryName: string,
240
- entryType?: ?RawPerformanceEntryType,
241
- ): $ReadOnlyArray<RawPerformanceEntry> => {
242
- return NativePerformanceMock.getEntries().filter(
243
- entry =>
244
- (entryType == null || entry.entryType === entryType) &&
245
- entry.name === entryName,
246
- );
247
- },
248
-
249
- getEntriesByType: (
250
- entryType: RawPerformanceEntryType,
251
- ): $ReadOnlyArray<RawPerformanceEntry> => {
252
- return entries.filter(entry => entry.entryType === entryType);
253
- },
254
-
255
- getSupportedPerformanceEntryTypes:
256
- (): $ReadOnlyArray<RawPerformanceEntryType> => {
257
- return [
258
- RawPerformanceEntryTypeValues.MARK,
259
- RawPerformanceEntryTypeValues.MEASURE,
260
- RawPerformanceEntryTypeValues.EVENT,
261
- ];
262
- },
263
- };
264
-
265
- (NativePerformanceMock: NativePerformance);
266
-
267
- export default NativePerformanceMock;