const ExpandableView = ({ expanded = false, children }) => { const [height] =…
- User
const ExpandableView = ({ expanded = false, children }) => { const [height] = useState(new Animated.Value(0)); useEffect(() => { Animated.timing(height, { toValue: expanded ? 100 : 0, duration: 700, easing: Easing.out(Easing.exp), useNativeDriver: false }).start(); }, [expanded, height]); // Interpolate the height value to convert it into a percentage string const interpolatedHeight = height.interpolate({ inputRange: [0, 100], outputRange: ['0%', '100%'], }); return ( <Animated.View style={{ maxHeight: interpolatedHeight, opacity: 1 }}> {/* {interpolatedHeight} */} {children} </Animated.View> ); };
I just want the expandable item to go to max height it needs, but when I put max-height to 100% it seems to want the max height of the entire window, i just want it to fill 100% of the height space it needs. Is there a different property I should use (react native)
const ExpandableView = ({ expanded = false, children }) => { const [height] = useState(new Animated.Value(0)); useEffect(() => { Animated.timing(height, { toValue: expanded ? 100 : 0, duration: 700, easing: Easing.out(Easing.exp), useNativeDriver: false }).start(); }, [expanded, height]); // Interpolate the height value to convert it into a percentage string const interpolatedHeight = height.interpolate({ inputRange: [0, 100], outputRange: ['0%', '100%'], }); return ( <Animated.View style={{ maxHeight: interpolatedHeight, opacity: 1 }}> {/* {interpolatedHeight} */} {children} </Animated.View> ); };
- Assistant