Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when measuring flattened view on Android #3414

Merged
merged 2 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/reanimated2/NativeMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down