Write a react native component with pressable that is just like touchableopacity. It…
- User
Write a react native component with pressable that is just like touchableopacity. It should have the opacity animated
- Assistant
Sure, here is an example of a React Native component using Pressable to create similar behavior to TouchableOpacity:
import React, { useState } from 'react'; import { Animated, Pressable, Text, View } from 'react-native'; const MyPressableComponent = () => { const [opacity, setOpacity] = useState(new Animated.Value(1)); const startOpacityAnimation = () => { Animated.timing(opacity, { toValue: 0.5, duration: 250, useNativeDriver: true, }).start(); }; const endOpacityAnimation = () => { Animated.timing(opacity, { toValue: 1, duration: 250, useNativeDriver: true, }).start(); }; return ( <Pressable onPressIn={startOpacityAnimation} onPressOut={endOpacityAnimation} > <Animated.View style={{ opacity }}> <Text>Press Me</Text> </Animated.View> </Pressable> ); }; export default MyPressableComponent;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.