File tree Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Expand file tree Collapse file tree 1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -271,14 +271,19 @@ const performanceFallback: CrossPlatformPerformance = {
271
271
* Performance wrapper for react native as performance.now() has been found to start off with an unusual offset.
272
272
*/
273
273
function getReactNativePerformanceWrapper ( ) : CrossPlatformPerformance {
274
- const INITIAL_OFFSET = performance . now ( ) ;
275
-
276
- return {
277
- now ( ) : number {
278
- return performance . now ( ) - INITIAL_OFFSET ;
279
- } ,
280
- timeOrigin : INITIAL_TIME ,
281
- } ;
274
+ // Performance only available >= RN 0.63
275
+ const { performance } = getGlobalObject < Window > ( ) ;
276
+ if ( performance && typeof performance . now === 'function' ) {
277
+ const INITIAL_OFFSET = performance . now ( ) ;
278
+
279
+ return {
280
+ now ( ) : number {
281
+ return performance . now ( ) - INITIAL_OFFSET ;
282
+ } ,
283
+ timeOrigin : INITIAL_TIME ,
284
+ } ;
285
+ }
286
+ return performanceFallback ;
282
287
}
283
288
284
289
export const crossPlatformPerformance : CrossPlatformPerformance = ( ( ) : CrossPlatformPerformance => {
You can’t perform that action at this time.
0 commit comments