FIX: Smoother animation

This commit is contained in:
Marcos Rodriguez Velez 2024-06-12 12:54:44 -04:00
parent 32099e2bff
commit 89742af8b2
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7

View File

@ -1,5 +1,5 @@
import React, { useRef, useEffect } from 'react'; import React, { useRef, useEffect } from 'react';
import { StyleSheet, Text, View, Pressable, LayoutAnimation, Platform, UIManager, ViewStyle, TextStyle, Animated } from 'react-native'; import { StyleSheet, Text, View, Pressable, Platform, UIManager, ViewStyle, TextStyle, Animated } from 'react-native';
import { useTheme } from './themes'; import { useTheme } from './themes';
if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) { if (Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental) {
@ -43,8 +43,13 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({ values, selectedInd
}); });
const handleTabPress = (index: number) => { const handleTabPress = (index: number) => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); Animated.timing(animatedValue, {
onChange(index); toValue: index,
duration: 300,
useNativeDriver: false,
}).start(() => {
onChange(index);
});
}; };
const tabWidth = animatedValue.interpolate({ const tabWidth = animatedValue.interpolate({