Calling measure on the element which is off the screen causing crash on Android
See original GitHub issueDescription
If the element is off the screen (user can’t see it) on iOS we can get its measurements, on Android it causing the app to crash.
Screenshots
Steps To Reproduce
- Run provided example
- Wait 1 second. It will try to measure the element which is off the screen
Expected behavior
Should work just like on iOS – should return values off the screen
Actual behavior
Crashes
Snack or minimal code example
import React from 'react';
import { useEffect } from 'react';
import {
FlatList,
TapGestureHandler,
} from 'react-native-gesture-handler';
import Animated, {
useAnimatedRef,
useAnimatedGestureHandler,
measure,
runOnUI,
} from 'react-native-reanimated';
function Block({ index }) {
const ref = useAnimatedRef();
const handler = useAnimatedGestureHandler({
onFinish: () => {
console.log(measure(ref));
},
});
useEffect(() => {
if (index === 9) {
setTimeout(
() =>
runOnUI(() => {
'worklet';
console.log(measure(ref));
})(),
1000,
);
}
}, []);
return (
<TapGestureHandler onGestureEvent={handler}>
<Animated.View
ref={ref}
style={{
height: 200,
marginBottom: 16,
backgroundColor: 'red',
}}
/>
</TapGestureHandler>
);
}
function Navigation() {
return (
<FlatList
data={Array.from({ length: 10 }).map((item, index) => index)}
renderItem={({ index }) => <Block index={index} />}
/>
);
}
Package versions
- React: 16.13.1
- React Native: 0.63.2
- React Native Reanimated: 2.0.0-alpha.7
- NodeJS: 12.16.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Crashes - Android Developers
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >RecyclerView: Inconsistency detected. Invalid item position
Scroll recycler view. So I assume this crash happens when you remove items from the list and scroll without calling notify methods.
Read more >My App Crashed, Now What? - RayWenderlich.com
You'll find a project called CrashGallery. Crash Gallery main screen. The project shows some common scenarios that cause your app to crash.
Read more >How to Diagnose App Issues Using Crash Logs - Papertrail
With our device connected via USB before the crash, Android Studio's Logcat feature will display information about our app and the crash. To...
Read more >How to fix Premiere Pro crash issues - Adobe Support
Check if any instance of the app is running in the background. If so, force quit it using Activity Monitor (macOS) or Task...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, forgive me for the english of the google translator.
It seems to me that this is a rendering problem on android, the measure tries to get the measurements before the view is even rendered on the screen, I got a good result with the code below.
Even with this result, my team and I chose not to use measure less on android until we have a definitive correction, because this palliative solution that is found below may not work in 100% of cases.
Hi there, thanks for your reply, it seems like I had some caching issues on Android because now try-catch actually catches the error just like it’s on iOS.
I will let you know if I find any other issues regarding that.