From 6222491cbf4488d29235e222fd10602127b3a248 Mon Sep 17 00:00:00 2001 From: Krzysztof Piaskowy Date: Thu, 27 Jan 2022 11:48:50 +0100 Subject: [PATCH] Display only warn if measure is called on RN side (#2790) ## Description I replaced the exception with a warning message in the `measure` function because if someone uses `measure` inside `useDerivedValue` the initial call is called on react native side. Fixes #2779 --- src/reanimated2/NativeMethods.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/reanimated2/NativeMethods.ts b/src/reanimated2/NativeMethods.ts index 0629e5b683d..8477c8600b8 100644 --- a/src/reanimated2/NativeMethods.ts +++ b/src/reanimated2/NativeMethods.ts @@ -25,8 +25,16 @@ export function measure( animatedRef: RefObjectFunction ): MeasuredDimensions { 'worklet'; - if (!_WORKLET && !isChromeDebugger()) { - throw new Error('(measure) method cannot be used on RN side!'); + if (!_WORKLET || isChromeDebugger()) { + console.warn('[reanimated.measure] method cannot be used on RN side!'); + return { + x: NaN, + y: NaN, + width: NaN, + height: NaN, + pageX: NaN, + pageY: NaN, + }; } const viewTag = animatedRef(); const result = _measure(viewTag);