Skip to content

Commit

Permalink
Display only warn if measure is called on RN side (software-mansion#2790
Browse files Browse the repository at this point in the history
)

## 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 software-mansion#2779
  • Loading branch information
piaskowyk authored Jan 27, 2022
1 parent b7cc2cf commit 6222491
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/reanimated2/NativeMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ export function measure(
animatedRef: RefObjectFunction<Component>
): 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);
Expand Down

0 comments on commit 6222491

Please sign in to comment.