@react-native-oh/react-native-harmony 0.72.10
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/Libraries/Alert/Alert.harmony.js +71 -0
- package/Libraries/Alert/AlertManager.ts +35 -0
- package/Libraries/Animated/NativeAnimatedHelper.harmony.js +601 -0
- package/Libraries/Components/Button/Button.harmony.js +451 -0
- package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +208 -0
- package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +75 -0
- package/Libraries/Components/ScrollView/ScrollView.harmony.js +1940 -0
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +24 -0
- package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +68 -0
- package/Libraries/Components/StatusBar/StatusBar.harmony.js +447 -0
- package/Libraries/Components/TextInput/TextInput.harmony.js +1697 -0
- package/Libraries/Components/TextInput/TextInputState.harmony.js +220 -0
- package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +396 -0
- package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +364 -0
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +227 -0
- package/Libraries/Components/View/View.harmony.js +149 -0
- package/Libraries/Core/setUpErrorHandling.harmony.js +35 -0
- package/Libraries/Image/AssetSourceResolver.harmony.ts +32 -0
- package/Libraries/NativeComponent/BaseViewConfig.harmony.js +325 -0
- package/Libraries/NativeModules/specs/NativeDevSettings.harmony.js +10 -0
- package/Libraries/Network/XMLHttpRequest.harmony.js +677 -0
- package/Libraries/Settings/Settings.harmony.js +15 -0
- package/Libraries/Utilities/BackHandler.harmony.js +109 -0
- package/Libraries/Utilities/NativePlatformConstantsHarmony.ts +8 -0
- package/Libraries/Utilities/Platform.d.ts +117 -0
- package/Libraries/Utilities/Platform.harmony.ts +33 -0
- package/Libraries/Utilities/createPerformanceLogger.harmony.js +328 -0
- package/index.js +178 -0
- package/metro.config.js +190 -0
- package/package.json +45 -0
- package/react-native.config.js +10 -0
- package/rnoh-4.0.0.200.har +0 -0
- package/tsconfig.json +13 -0
- package/types/index.d.ts +101 -0
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
// RNOH: This is a copy of the original Android file
|
|
12
|
+
|
|
13
|
+
import NativeDeviceEventManager from 'react-native/Libraries/NativeModules/specs/NativeDeviceEventManager';
|
|
14
|
+
import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';
|
|
15
|
+
|
|
16
|
+
const DEVICE_BACK_EVENT = 'hardwareBackPress';
|
|
17
|
+
|
|
18
|
+
type BackPressEventName = 'backPress' | 'hardwareBackPress';
|
|
19
|
+
|
|
20
|
+
const _backPressSubscriptions = [];
|
|
21
|
+
|
|
22
|
+
RCTDeviceEventEmitter.addListener(DEVICE_BACK_EVENT, function () {
|
|
23
|
+
for (let i = _backPressSubscriptions.length - 1; i >= 0; i--) {
|
|
24
|
+
if (_backPressSubscriptions[i]()) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
BackHandler.exitApp();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Detect hardware button presses for back navigation.
|
|
34
|
+
*
|
|
35
|
+
* Android: Detect hardware back button presses, and programmatically invoke the default back button
|
|
36
|
+
* functionality to exit the app if there are no listeners or if none of the listeners return true.
|
|
37
|
+
*
|
|
38
|
+
* iOS: Not applicable.
|
|
39
|
+
*
|
|
40
|
+
* The event subscriptions are called in reverse order (i.e. last registered subscription first),
|
|
41
|
+
* and if one subscription returns true then subscriptions registered earlier will not be called.
|
|
42
|
+
*
|
|
43
|
+
* Example:
|
|
44
|
+
*
|
|
45
|
+
* ```javascript
|
|
46
|
+
* BackHandler.addEventListener('hardwareBackPress', function() {
|
|
47
|
+
* // this.onMainScreen and this.goBack are just examples, you need to use your own implementation here
|
|
48
|
+
* // Typically you would use the navigator here to go to the last state.
|
|
49
|
+
*
|
|
50
|
+
* if (!this.onMainScreen()) {
|
|
51
|
+
* this.goBack();
|
|
52
|
+
* return true;
|
|
53
|
+
* }
|
|
54
|
+
* return false;
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
type TBackHandler = {|
|
|
59
|
+
+exitApp: () => void,
|
|
60
|
+
+addEventListener: (
|
|
61
|
+
eventName: BackPressEventName,
|
|
62
|
+
handler: () => ?boolean,
|
|
63
|
+
) => {remove: () => void, ...},
|
|
64
|
+
+removeEventListener: (
|
|
65
|
+
eventName: BackPressEventName,
|
|
66
|
+
handler: () => ?boolean,
|
|
67
|
+
) => void,
|
|
68
|
+
|};
|
|
69
|
+
const BackHandler: TBackHandler = {
|
|
70
|
+
exitApp: function (): void {
|
|
71
|
+
if (!NativeDeviceEventManager) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
NativeDeviceEventManager.invokeDefaultBackPressHandler();
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Adds an event handler. Supported events:
|
|
80
|
+
*
|
|
81
|
+
* - `hardwareBackPress`: Fires when the Android hardware back button is pressed.
|
|
82
|
+
*/
|
|
83
|
+
addEventListener: function (
|
|
84
|
+
eventName: BackPressEventName,
|
|
85
|
+
handler: () => ?boolean,
|
|
86
|
+
): {remove: () => void, ...} {
|
|
87
|
+
if (_backPressSubscriptions.indexOf(handler) === -1) {
|
|
88
|
+
_backPressSubscriptions.push(handler);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
remove: (): void => BackHandler.removeEventListener(eventName, handler),
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Removes the event handler.
|
|
97
|
+
*/
|
|
98
|
+
removeEventListener: function (
|
|
99
|
+
eventName: BackPressEventName,
|
|
100
|
+
handler: () => ?boolean,
|
|
101
|
+
): void {
|
|
102
|
+
const index = _backPressSubscriptions.indexOf(handler);
|
|
103
|
+
if (index !== -1) {
|
|
104
|
+
_backPressSubscriptions.splice(index, 1);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
module.exports = BackHandler;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TurboModule, TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import { PlatformHarmonyConstants } from "./Platform";
|
|
3
|
+
|
|
4
|
+
interface Spec extends TurboModule {
|
|
5
|
+
getConstants: () => PlatformHarmonyConstants;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const NativePlatformConstantsHarmony = TurboModuleRegistry.getEnforcing<Spec>('PlatformConstants');
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* @see https://reactnative.dev/docs/platform-specific-code#content
|
|
12
|
+
*/
|
|
13
|
+
export type PlatformOSType =
|
|
14
|
+
| 'ios'
|
|
15
|
+
| 'android'
|
|
16
|
+
| 'macos'
|
|
17
|
+
| 'windows'
|
|
18
|
+
| 'web'
|
|
19
|
+
| "harmony" // RNOH: patch
|
|
20
|
+
| 'native';
|
|
21
|
+
type PlatformConstants = {
|
|
22
|
+
isTesting: boolean;
|
|
23
|
+
reactNativeVersion: {
|
|
24
|
+
major: number;
|
|
25
|
+
minor: number;
|
|
26
|
+
patch: number;
|
|
27
|
+
prerelease?: number | null | undefined;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
interface PlatformStatic {
|
|
31
|
+
isTV: boolean;
|
|
32
|
+
isTesting: boolean;
|
|
33
|
+
Version: number | string;
|
|
34
|
+
constants: PlatformConstants;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @see https://reactnative.dev/docs/platform-specific-code#content
|
|
38
|
+
*/
|
|
39
|
+
select<T>(
|
|
40
|
+
specifics:
|
|
41
|
+
| ({ [platform in PlatformOSType]?: T } & { default: T; })
|
|
42
|
+
| { [platform in PlatformOSType]: T },
|
|
43
|
+
): T;
|
|
44
|
+
select<T>(specifics: { [platform in PlatformOSType]?: T }): T | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface PlatformIOSStatic extends PlatformStatic {
|
|
48
|
+
constants: PlatformConstants & {
|
|
49
|
+
forceTouchAvailable: boolean;
|
|
50
|
+
interfaceIdiom: string;
|
|
51
|
+
osVersion: string;
|
|
52
|
+
systemName: string;
|
|
53
|
+
};
|
|
54
|
+
OS: 'ios';
|
|
55
|
+
isPad: boolean;
|
|
56
|
+
isTV: boolean;
|
|
57
|
+
Version: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
interface PlatformAndroidStatic extends PlatformStatic {
|
|
61
|
+
constants: PlatformConstants & {
|
|
62
|
+
Version: number;
|
|
63
|
+
Release: string;
|
|
64
|
+
Serial: string;
|
|
65
|
+
Fingerprint: string;
|
|
66
|
+
Model: string;
|
|
67
|
+
Brand: string;
|
|
68
|
+
Manufacturer: string;
|
|
69
|
+
ServerHost?: string | undefined;
|
|
70
|
+
uiMode: 'car' | 'desk' | 'normal' | 'tv' | 'watch' | 'unknown';
|
|
71
|
+
};
|
|
72
|
+
OS: 'android';
|
|
73
|
+
Version: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface PlatformMacOSStatic extends PlatformStatic {
|
|
77
|
+
OS: 'macos';
|
|
78
|
+
Version: string;
|
|
79
|
+
constants: PlatformConstants & {
|
|
80
|
+
osVersion: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
interface PlatformWindowsOSStatic extends PlatformStatic {
|
|
85
|
+
OS: 'windows';
|
|
86
|
+
Version: number;
|
|
87
|
+
constants: PlatformConstants & {
|
|
88
|
+
osVersion: number;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface PlatformWebStatic extends PlatformStatic {
|
|
93
|
+
OS: 'web';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// begin RNOH: patch
|
|
97
|
+
export type PlatformHarmonyConstants = PlatformConstants & {
|
|
98
|
+
deviceType: "default" | "phone" | "wearable" | "liteWearable" | "tablet" | "tv" | "car" | "smartVision";
|
|
99
|
+
osFullName: string;
|
|
100
|
+
Model: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export interface PlatformHarmonyStatic extends PlatformStatic {
|
|
104
|
+
OS: 'harmony';
|
|
105
|
+
constants: PlatformHarmonyConstants;
|
|
106
|
+
}
|
|
107
|
+
// end RNOH: patch
|
|
108
|
+
|
|
109
|
+
export type Platform =
|
|
110
|
+
| PlatformIOSStatic
|
|
111
|
+
| PlatformAndroidStatic
|
|
112
|
+
| PlatformWindowsOSStatic
|
|
113
|
+
| PlatformMacOSStatic
|
|
114
|
+
| PlatformWebStatic
|
|
115
|
+
| PlatformHarmonyStatic; // RNOH: patch
|
|
116
|
+
|
|
117
|
+
export const Platform: Platform;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { NativePlatformConstantsHarmony } from "./NativePlatformConstantsHarmony";
|
|
2
|
+
import type { PlatformHarmonyStatic, PlatformHarmonyConstants, PlatformOSType } from "./Platform";
|
|
3
|
+
|
|
4
|
+
const Platform = {
|
|
5
|
+
__constants: undefined as undefined | PlatformHarmonyConstants,
|
|
6
|
+
OS: 'harmony' as const,
|
|
7
|
+
get constants() {
|
|
8
|
+
if (this.__constants == null) {
|
|
9
|
+
this.__constants = NativePlatformConstantsHarmony.getConstants();
|
|
10
|
+
}
|
|
11
|
+
return this.__constants;
|
|
12
|
+
},
|
|
13
|
+
get Version() {
|
|
14
|
+
return this.constants.osFullName;
|
|
15
|
+
},
|
|
16
|
+
get isPad() {
|
|
17
|
+
return this.constants.deviceType === 'tablet';
|
|
18
|
+
},
|
|
19
|
+
get isTV() {
|
|
20
|
+
return this.constants.deviceType === 'tv';
|
|
21
|
+
},
|
|
22
|
+
get isTesting() {
|
|
23
|
+
if (__DEV__) {
|
|
24
|
+
return this.constants.isTesting;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
select<T>(spec: ({ [platform in PlatformOSType]?: T } & { default: T; }) | { [platform in PlatformOSType]: T }) {
|
|
29
|
+
return 'harmony' in spec ? spec.harmony : 'native' in spec ? spec.native : spec.default;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = Platform as PlatformHarmonyStatic;
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const Systrace = require('react-native/Libraries/Performance/Systrace'); // RNOH: patch
|
|
12
|
+
const infoLog = require('react-native/Libraries/Utilities/infoLog'); // RNOH: patch
|
|
13
|
+
|
|
14
|
+
export type Timespan = {
|
|
15
|
+
startTime: number,
|
|
16
|
+
endTime?: number,
|
|
17
|
+
totalTime?: number,
|
|
18
|
+
startExtras?: Extras,
|
|
19
|
+
endExtras?: Extras,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Extra values should be serializable primitives
|
|
23
|
+
export type ExtraValue = number | string | boolean;
|
|
24
|
+
|
|
25
|
+
export type Extras = {[key: string]: ExtraValue};
|
|
26
|
+
|
|
27
|
+
export interface IPerformanceLogger {
|
|
28
|
+
addTimespan(
|
|
29
|
+
key: string,
|
|
30
|
+
startTime: number,
|
|
31
|
+
endTime: number,
|
|
32
|
+
startExtras?: Extras,
|
|
33
|
+
endExtras?: Extras,
|
|
34
|
+
): void;
|
|
35
|
+
append(logger: IPerformanceLogger): void;
|
|
36
|
+
clear(): void;
|
|
37
|
+
clearCompleted(): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
currentTimestamp(): number;
|
|
40
|
+
getExtras(): $ReadOnly<{[key: string]: ?ExtraValue, ...}>;
|
|
41
|
+
getPoints(): $ReadOnly<{[key: string]: ?number, ...}>;
|
|
42
|
+
getPointExtras(): $ReadOnly<{[key: string]: ?Extras, ...}>;
|
|
43
|
+
getTimespans(): $ReadOnly<{[key: string]: ?Timespan, ...}>;
|
|
44
|
+
hasTimespan(key: string): boolean;
|
|
45
|
+
isClosed(): boolean;
|
|
46
|
+
logEverything(): void;
|
|
47
|
+
markPoint(key: string, timestamp?: number, extras?: Extras): void;
|
|
48
|
+
removeExtra(key: string): ?ExtraValue;
|
|
49
|
+
setExtra(key: string, value: ExtraValue): void;
|
|
50
|
+
startTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
51
|
+
stopTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const _cookies: {[key: string]: number, ...} = {};
|
|
55
|
+
|
|
56
|
+
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
|
|
57
|
+
|
|
58
|
+
export const getCurrentTimestamp: () => number =
|
|
59
|
+
global.nativeQPLTimestamp ?? global.performance ? global.performance.now.bind(global.performance) : Date.now; // RNOH: patch
|
|
60
|
+
|
|
61
|
+
class PerformanceLogger implements IPerformanceLogger {
|
|
62
|
+
_timespans: {[key: string]: ?Timespan} = {};
|
|
63
|
+
_extras: {[key: string]: ?ExtraValue} = {};
|
|
64
|
+
_points: {[key: string]: ?number} = {};
|
|
65
|
+
_pointExtras: {[key: string]: ?Extras, ...} = {};
|
|
66
|
+
_closed: boolean = false;
|
|
67
|
+
|
|
68
|
+
addTimespan(
|
|
69
|
+
key: string,
|
|
70
|
+
startTime: number,
|
|
71
|
+
endTime: number,
|
|
72
|
+
startExtras?: Extras,
|
|
73
|
+
endExtras?: Extras,
|
|
74
|
+
) {
|
|
75
|
+
if (this._closed) {
|
|
76
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
77
|
+
infoLog('PerformanceLogger: addTimespan - has closed ignoring: ', key);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this._timespans[key]) {
|
|
82
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
83
|
+
infoLog(
|
|
84
|
+
'PerformanceLogger: Attempting to add a timespan that already exists ',
|
|
85
|
+
key,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this._timespans[key] = {
|
|
92
|
+
startTime,
|
|
93
|
+
endTime,
|
|
94
|
+
totalTime: endTime - (startTime || 0),
|
|
95
|
+
startExtras,
|
|
96
|
+
endExtras,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
append(performanceLogger: IPerformanceLogger) {
|
|
101
|
+
this._timespans = {
|
|
102
|
+
...performanceLogger.getTimespans(),
|
|
103
|
+
...this._timespans,
|
|
104
|
+
};
|
|
105
|
+
this._extras = {...performanceLogger.getExtras(), ...this._extras};
|
|
106
|
+
this._points = {...performanceLogger.getPoints(), ...this._points};
|
|
107
|
+
this._pointExtras = {
|
|
108
|
+
...performanceLogger.getPointExtras(),
|
|
109
|
+
...this._pointExtras,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
clear() {
|
|
114
|
+
this._timespans = {};
|
|
115
|
+
this._extras = {};
|
|
116
|
+
this._points = {};
|
|
117
|
+
if (PRINT_TO_CONSOLE) {
|
|
118
|
+
infoLog('PerformanceLogger.js', 'clear');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
clearCompleted() {
|
|
123
|
+
for (const key in this._timespans) {
|
|
124
|
+
if (this._timespans[key]?.totalTime != null) {
|
|
125
|
+
delete this._timespans[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this._extras = {};
|
|
129
|
+
this._points = {};
|
|
130
|
+
if (PRINT_TO_CONSOLE) {
|
|
131
|
+
infoLog('PerformanceLogger.js', 'clearCompleted');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
close() {
|
|
136
|
+
this._closed = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
currentTimestamp(): number {
|
|
140
|
+
return getCurrentTimestamp();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getExtras(): {[key: string]: ?ExtraValue} {
|
|
144
|
+
return this._extras;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getPoints(): {[key: string]: ?number} {
|
|
148
|
+
return this._points;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getPointExtras(): {[key: string]: ?Extras} {
|
|
152
|
+
return this._pointExtras;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getTimespans(): {[key: string]: ?Timespan} {
|
|
156
|
+
return this._timespans;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
hasTimespan(key: string): boolean {
|
|
160
|
+
return !!this._timespans[key];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isClosed(): boolean {
|
|
164
|
+
return this._closed;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
logEverything() {
|
|
168
|
+
if (PRINT_TO_CONSOLE) {
|
|
169
|
+
// log timespans
|
|
170
|
+
for (const key in this._timespans) {
|
|
171
|
+
if (this._timespans[key]?.totalTime != null) {
|
|
172
|
+
infoLog(key + ': ' + this._timespans[key].totalTime + 'ms');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// log extras
|
|
177
|
+
infoLog(this._extras);
|
|
178
|
+
|
|
179
|
+
// log points
|
|
180
|
+
for (const key in this._points) {
|
|
181
|
+
if (this._points[key] != null) {
|
|
182
|
+
infoLog(key + ': ' + this._points[key] + 'ms');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
markPoint(
|
|
189
|
+
key: string,
|
|
190
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
191
|
+
extras?: Extras,
|
|
192
|
+
) {
|
|
193
|
+
if (this._closed) {
|
|
194
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
195
|
+
infoLog('PerformanceLogger: markPoint - has closed ignoring: ', key);
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this._points[key] != null) {
|
|
200
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
201
|
+
infoLog(
|
|
202
|
+
'PerformanceLogger: Attempting to mark a point that has been already logged ',
|
|
203
|
+
key,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this._points[key] = timestamp;
|
|
209
|
+
if (extras) {
|
|
210
|
+
this._pointExtras[key] = extras;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
removeExtra(key: string): ?ExtraValue {
|
|
215
|
+
const value = this._extras[key];
|
|
216
|
+
delete this._extras[key];
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
setExtra(key: string, value: ExtraValue) {
|
|
221
|
+
if (this._closed) {
|
|
222
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
223
|
+
infoLog('PerformanceLogger: setExtra - has closed ignoring: ', key);
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (this._extras.hasOwnProperty(key)) {
|
|
229
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
230
|
+
infoLog(
|
|
231
|
+
'PerformanceLogger: Attempting to set an extra that already exists ',
|
|
232
|
+
{key, currentValue: this._extras[key], attemptedValue: value},
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this._extras[key] = value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
startTimespan(
|
|
241
|
+
key: string,
|
|
242
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
243
|
+
extras?: Extras,
|
|
244
|
+
) {
|
|
245
|
+
if (this._closed) {
|
|
246
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
247
|
+
infoLog(
|
|
248
|
+
'PerformanceLogger: startTimespan - has closed ignoring: ',
|
|
249
|
+
key,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (this._timespans[key]) {
|
|
256
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
257
|
+
infoLog(
|
|
258
|
+
'PerformanceLogger: Attempting to start a timespan that already exists ',
|
|
259
|
+
key,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this._timespans[key] = {
|
|
266
|
+
startTime: timestamp,
|
|
267
|
+
startExtras: extras,
|
|
268
|
+
};
|
|
269
|
+
_cookies[key] = Systrace.beginAsyncEvent(key);
|
|
270
|
+
if (PRINT_TO_CONSOLE) {
|
|
271
|
+
infoLog('PerformanceLogger.js', 'start: ' + key);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
stopTimespan(
|
|
276
|
+
key: string,
|
|
277
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
278
|
+
extras?: Extras,
|
|
279
|
+
) {
|
|
280
|
+
if (this._closed) {
|
|
281
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
282
|
+
infoLog('PerformanceLogger: stopTimespan - has closed ignoring: ', key);
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const timespan = this._timespans[key];
|
|
288
|
+
if (!timespan || timespan.startTime == null) {
|
|
289
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
290
|
+
infoLog(
|
|
291
|
+
'PerformanceLogger: Attempting to end a timespan that has not started ',
|
|
292
|
+
key,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (timespan.endTime != null) {
|
|
298
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
299
|
+
infoLog(
|
|
300
|
+
'PerformanceLogger: Attempting to end a timespan that has already ended ',
|
|
301
|
+
key,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
timespan.endExtras = extras;
|
|
308
|
+
timespan.endTime = timestamp;
|
|
309
|
+
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
|
|
310
|
+
if (PRINT_TO_CONSOLE) {
|
|
311
|
+
infoLog('PerformanceLogger.js', 'end: ' + key);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (_cookies[key] != null) {
|
|
315
|
+
Systrace.endAsyncEvent(key, _cookies[key]);
|
|
316
|
+
delete _cookies[key];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* This function creates performance loggers that can be used to collect and log
|
|
323
|
+
* various performance data such as timespans, points and extras.
|
|
324
|
+
* The loggers need to have minimal overhead since they're used in production.
|
|
325
|
+
*/
|
|
326
|
+
export default function createPerformanceLogger(): IPerformanceLogger {
|
|
327
|
+
return new PerformanceLogger();
|
|
328
|
+
}
|