My code looks something like this currently:
<View>
<TextInput placeholder='PlaceholderText'>
</TextInput>
</View>
I want to make a TextInput
component that has an opacity animation on click (exactly like TouchableOpacity
changes opacity on click).
I tried wrapping the TextInput
inside TouchableOpacity
, but it doesn’t work since the touchable component surrounds text input. Is there a standard React Native or StyleSheet way of doing this or would I have to manually create an animation to mimic that effect?
2
Answers
If you just want to set opacity, make your styles change using the
onPressIn
andonPressOut
props:If you need the changes to animate, you can do that with the built-in RN Animated component or react-native-reanimated, using the same props to trigger the animations.
Simply wrap your
TextInput
in aView
element and animate the View’s opacity color from the onFocs event of the TextInput. TextInput doesn’t have the opacity attribute, therefore the additional view is required for your goal.Following code may give you an idea how to solve it. Have to admit, that I haven’t tested the code, it may contain some error, so use it carefully.