From 0637d61da9e7b6e3f6fc74f357256b9bd0c920ad Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Wed, 27 Jul 2022 16:24:14 +0200 Subject: [PATCH 1/2] Return `NaN` instead of non-deterministic values when measuring flattened view on Android --- .../src/main/java/com/swmansion/reanimated/NodesManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/swmansion/reanimated/NodesManager.java b/android/src/main/java/com/swmansion/reanimated/NodesManager.java index fef8a7bba95..03fcd639353 100644 --- a/android/src/main/java/com/swmansion/reanimated/NodesManager.java +++ b/android/src/main/java/com/swmansion/reanimated/NodesManager.java @@ -1,5 +1,7 @@ package com.swmansion.reanimated; +import static java.lang.Float.NaN; + import android.view.View; import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.GuardedRunnable; @@ -56,7 +58,7 @@ public float[] measure(int viewTag) { view = mUIManager.resolveView(viewTag); } catch (IllegalViewOperationException e) { e.printStackTrace(); - return (new float[] {}); + return (new float[] {NaN, NaN, NaN, NaN, NaN, NaN}); } return NativeMethodsHelper.measure(view); } From 95e81bbd1efd5672548798c7c3e9947972323780 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Wed, 27 Jul 2022 16:38:33 +0200 Subject: [PATCH 2/2] Add `console.warn` --- src/reanimated2/NativeMethods.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/reanimated2/NativeMethods.ts b/src/reanimated2/NativeMethods.ts index 2baf74c7cdd..cbe8b599a18 100644 --- a/src/reanimated2/NativeMethods.ts +++ b/src/reanimated2/NativeMethods.ts @@ -45,6 +45,11 @@ export function measure( if (result.x === -1234567) { throw new Error(`The view with tag ${viewTag} could not be measured`); } + if (isNaN(result.x)) { + console.warn( + 'Trying to measure a component which gets view-flattened on Android. To disable view-flattening, set `collapsable={false}` on this component.' + ); + } return result; }