mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
b89358263a
Summary: ## Changelog: [Internal] - Now that Performance API implementation is getting close to the final stage, it should be safe to replace the `global.performance` instance with the corresponding new implementation. This is done *only* if the actual native implementation is present, however (otherwise the behaviour will be exactly the same as before). Currently this is the case for all VR apps, Catalyst and very soon will be the case for fb4a/ios. Reviewed By: cipolleschi Differential Revision: D44057951 fbshipit-source-id: 7ccff4a4930175def69ef4d8a44335fbbd4a5df4
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict
|
|
* @format
|
|
*/
|
|
|
|
import NativePerformance from '../WebPerformance/NativePerformance';
|
|
import Performance from '../WebPerformance/Performance';
|
|
|
|
// In case if the native implementation of the Performance API is available, use it,
|
|
// otherwise fall back to the legacy/default one, which only defines 'Performance.now()'
|
|
if (NativePerformance) {
|
|
// $FlowExpectedError[cannot-write]
|
|
global.performance = new Performance();
|
|
} else {
|
|
if (!global.performance) {
|
|
// $FlowExpectedError[cannot-write]
|
|
global.performance = ({}: {now?: () => number});
|
|
}
|
|
|
|
/**
|
|
* Returns a double, measured in milliseconds.
|
|
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
|
|
*/
|
|
if (typeof global.performance.now !== 'function') {
|
|
// $FlowExpectedError[cannot-write]
|
|
global.performance.now = function () {
|
|
const performanceNow = global.nativePerformanceNow || Date.now;
|
|
return performanceNow();
|
|
};
|
|
}
|
|
}
|