I have a button component and I change its backgroundColor to a different colour while it is pressed but the change happens instantly and I was wondering if its possible to add some fade in animation that would make the colour change smoother.
The colour change happens here:
{ ...(variant === 'tertiary' && isPressed ? { backgroundColor: colors.primary50 } : {}) },
The button component:
const PrimaryButton: FunctionComponent<Props> = ({ title, variant = 'primary', wide = false, style, ...rest }) => {
const width = wide ? '100%' : undefined;
const textColor = variant === 'primary' ? colors.white : colors.primary600;
return (
<Pressable
style={({ pressed: isPressed }) => [
styles.button,
styles[variant],
{
width,
elevation: isPressed ? 5 : 0,
},
style,
{ ...(variant === 'tertiary' && isPressed ? { backgroundColor: colors.primary50 } : {}) },
]}
{...rest}
>
<HeaderText variant="h4" style={[styles.text, { color: textColor }]}>
{title}
</HeaderText>
</Pressable>
);
};
const styles = StyleSheet.create({
button: {
paddingVertical: 12,
paddingHorizontal: 24,
borderRadius: 100,
borderWidth: 1.5,
justifyContent: 'center',
alignItems: 'center',
alignSelf: 'center',
},
primary: {
backgroundColor: colors.primary600,
borderColor: colors.primary600,
},
secondary: {
backgroundColor: colors.white,
borderColor: colors.primary600,
},
tertiary: {
backgroundColor: 'transparent',
borderColor: 'transparent',
},
text: {
textAlign: 'center',
},
});
export default PrimaryButton;