Issue
The new Pressable
component is great; I like being able to access new events but, how do you add the opacity feedback the TouchableOpacity
component has?
Solution
Given the answer of @Adams:
Here is the code, which worked for me. You can customize it.
import React from "react";
import { Pressable, Animated } from "react-native";
const animated = new Animated.Value(1);
const PressableOpacity = ({ children, ...props }) => {
const fadeIn = () => {
Animated.timing(animated, {
toValue: 0.1,
duration: 100,
useNativeDriver: true,
}).start();
};
const fadeOut = () => {
Animated.timing(animated, {
toValue: 1,
duration: 200,
useNativeDriver: true,
}).start();
};
return (
<Pressable onPressIn={fadeIn} onPressOut={fadeOut} {...props}>
<Animated.View style={{ opacity: animated }}>{children}</Animated.View>
</Pressable>
);
};
export default PressableOpacity;
Answered By - André
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.