react-native-animatable icon indicating copy to clipboard operation
react-native-animatable copied to clipboard

Animatable TouchableOpacity, ToucableHighlight disappear after press

Open quangtruong16994 opened this issue 7 years ago • 11 comments

Example:

import { Text, View, TouchableOpacity, FlatList, InteractionManager, Image } from "react-native";
import * as Animatable from "react-native-animatable";

const AnimatableTouchableOpacity = Animatable.createAnimatableComponent(TouchableOpacity);

export default class Demo extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: "#9C27B0", justifyContent: "center", alignItems: "center" }}>
        <AnimatableTouchableOpacity onPress={() => { }} animation="bounceIn" style={{ borderColor: "#ddd", borderRadius: 3, borderWidth: 1, paddingHorizontal: 15, paddingVertical: 5 }}>
          <Text style={{ fontSize: 18, color: "#ddd", textAlign: "center" }}> Hit me!!! </Text>
        </AnimatableTouchableOpacity>
      </View>
    );
  }
}

After press AnimatableTouchableOpacity, it's gone. Something wrong? Or did I do something wrong?

I'm using: react-native: 0.46.4 react-native-animatable: 1.2.3 Genymotion: Android 6.0

quangtruong16994 avatar Aug 04 '17 06:08 quangtruong16994

Yeah.I am also facing the same issue!

harryharanr avatar Apr 08 '18 21:04 harryharanr

Yeah, same issue for me, but without using animatable. It seems to be linked with react-native Animated.

kornfleks avatar Apr 24 '18 10:04 kornfleks

Has anyone found a fix for this, it's really frustrating. I'm using: react-native: 0.54.2 react-native-animatable: 1.2.4

oneuptim avatar May 25 '18 02:05 oneuptim

Had the same issue, solved it by moving the Animatable component down to be a child of the <TouchableOpacity> instead, which was an image for me.

This somewhat makes sense because I'm sure the intention is not to animate the clickable boundaries of your touchable. So in your case I would suspect it makes sense to move your styles to an <Animatable.View> which is a child of your <TouchableOpacity>

nkov avatar Aug 25 '18 17:08 nkov

Thank you @nkov this solved the issue for me!

oneuptim avatar Sep 25 '18 03:09 oneuptim

Does anyone fix this? solution of @nkov doesn't fix my issue (wrap component is temporary solution)

nighttiger1990 avatar Nov 12 '18 04:11 nighttiger1990

I have tested and using <AnimatableView> also works when wrapping the <TouchableOpacity> as seen below. <TouchableOpacity> is a child of <AnimatableView>. Thank you for this workaround!

import * as Animatable from 'react-native-animatable';

AnimatableView = Animatable.createAnimatableComponent(View);
<AnimatableView
            animation="bounceInLeft"
            delay={90}
            duration={1500}>
            <TouchableOpacity
              style={styles.mapButton}
              onPress={() => this.props.navigation.push("Map")}>
              <Text style={styles.mapButtonText}>Map 🗺</Text>
            </TouchableOpacity>
          </AnimatableView>

konjoinfinity avatar May 15 '19 20:05 konjoinfinity

This still happens.

Edit: the @konjoinfinity code disables the onPress trigger.

mayconmesquita avatar Sep 12 '19 17:09 mayconmesquita

I have a workaround that is working here:

Using onPressIn and disable animation, as follows:

const AnimatedTouchableOpacity = createAnimatableComponent(TouchableOpacity);

<AnimatedTouchableOpacity
   animation={this.state.disableAnimation ? null : "bounceIn"}
   delay={100} 
   useNativeDriver={true}
   onPressIn={()=>{ this.setState({ disableAnimation: true }) }}
   onPress={this.openImageDialog}
   activeOpacity={.6}
>
   <Icon name='camera2' color='#fff' size={22} />
</AnimatedTouchableOpacity>

mayconmesquita avatar Sep 12 '19 17:09 mayconmesquita

It works when you put an extra view inside the hierarchy, like this:

<Animated.View style={style}> <View> <TouchableOpacity> {code} </TouchableOpacity> <View> </Animated.View>

robertsmit avatar Jan 30 '20 10:01 robertsmit

How about try using <Animatable.Text>

import { Text, View, TouchableOpacity, FlatList, InteractionManager, Image } from "react-native";
import * as Animatable from "react-native-animatable";

const AnimatableTouchableOpacity = Animatable.createAnimatableComponent(TouchableOpacity);

export default class Demo extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: "#9C27B0", justifyContent: "center", alignItems: "center" }}>
        <AnimatableTouchableOpacity onPress={() => { }} animation="bounceIn" style={{ borderColor: "#ddd", borderRadius: 3, borderWidth: 1, paddingHorizontal: 15, paddingVertical: 5 }}>
          <Animatable.Text style={{ fontSize: 18, color: "#ddd", textAlign: "center" }}> Hit me!!! </Animatable.Text>
        </AnimatableTouchableOpacity>
      </View>
    );
  }
}

tuoying96 avatar Mar 09 '21 19:03 tuoying96