Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/utils/src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,19 @@ const performanceFallback: CrossPlatformPerformance = {
* Performance wrapper for react native as performance.now() has been found to start off with an unusual offset.
*/
function getReactNativePerformanceWrapper(): CrossPlatformPerformance {
const INITIAL_OFFSET = performance.now();

return {
now(): number {
return performance.now() - INITIAL_OFFSET;
},
timeOrigin: INITIAL_TIME,
};
// Performance only available >= RN 0.63
const { performance } = getGlobalObject<Window>();
if (performance && typeof performance.now === 'function') {
const INITIAL_OFFSET = performance.now();

return {
now(): number {
return performance.now() - INITIAL_OFFSET;
},
timeOrigin: INITIAL_TIME,
};
}
return performanceFallback;
}

export const crossPlatformPerformance: CrossPlatformPerformance = ((): CrossPlatformPerformance => {
Expand Down