Replies: 1 comment 3 replies
-
Issue descriptionWhen you add Because on each layout change you set the And now, why does animation work weird in such a case? Settings Proposed solutionSolution 1 (easiest, not perfect)You should limit onLayout={(e) => {
height.value = Math.round(e.nativeEvent.layout.height);
}} Solution 2 (much better one)You pick an epsilon const EPS = 1
const newHeight = e.nativeEvent.layout.height;
runOnUI(() => {
if (Math.abs(newHeight - height.value) > EPS) {
height.value = newHeight;
}
})(); Example recordings
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, Could someone help me, I want to make an accordion and within each of the options it will contain a ScrollView with several options. I tried to do it with the example in the documentation and it didn't work.
The Documentation, https://docs.swmansion.com/react-native-reanimated/examples/accordion/
Copy this Code and try in https://snack.expo.dev/ to see the error.
import React from 'react';
import { StyleSheet, View, Button, SafeAreaView, ScrollView, Image, Text } from 'react-native';
import Animated, {
useAnimatedStyle,
useDerivedValue,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
function AccordionItem({
isExpanded,
children,
viewKey,
style,
duration = 500,
}) {
const height = useSharedValue(0);
const derivedHeight = useDerivedValue(() =>
withTiming(height.value * Number(isExpanded.value), {
duration,
})
);
const bodyStyle = useAnimatedStyle(() => ({
height: derivedHeight.value,
}));
return (
<Animated.View
key={
accordionItem_${viewKey}
}style={[styles.animatedView, bodyStyle, style]}>
<View
onLayout={(e) => {
height.value = e.nativeEvent.layout.height;
}}
style={styles.wrapper}>
{children}
</Animated.View>
);
}
function Item() {
return (
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
<Text style={{fontSize: 24}}>Prueba
)
}
function Parent({ open }) {
return (
);
}
export default function App() {
const open = useSharedValue(false);
const onPress = () => {
open.value = !open.value;
};
return (
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: 24,
},
buttonContainer: {
flex: 1,
paddingBottom: '1rem',
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
},
content: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
parent: {
width: 200,
},
wrapper: {
width: '100%',
position: 'absolute',
display: 'flex',
alignItems: 'center',
},
animatedView: {
width: '100%',
overflow: 'hidden',
},
});
Beta Was this translation helpful? Give feedback.
All reactions