1

I need to make an animation, which will make image smaller, then will make image a little bit bigger and then back to normal, this animation should repeat every time, when user is pressing on the button.

Here is what I already have, currently it makes image just smaller. How to make it bigger after that and then to normal size again?

class ReflectionScreen extends React.Component {

    constructor(props) {
        super(props)
        this.animatedValue = new Animated.Value(0)
    }

  handleAnimation = () => {
        Animated.timing(this.animatedValue, {
            toValue: 1,
            duration: 1000,
            easing: Easing.ease
        }).start()
    }

render() {
  <TouchableOpacity style={styles.handContainer} onPress={this.goIncrement}>
                        <Animated.Image
                            source={require('../images/tapHand.png')}
                            style={
                                [styles.imageHand, 
                                    {transform: [
                                    {
                                        translateX: this.animatedValue.interpolate({
                                            inputRange: [0, 1],
                                            outputRange: [0, 0.7]
                                        })
                                    },
                                    {
                                        translateY: this.animatedValue.interpolate({
                                            inputRange: [0, 1],
                                            outputRange: [0, 0.7]
                                        })
                                    },
                                    {
                                        scaleX: this.animatedValue.interpolate({
                                            inputRange: [0, 1],
                                            outputRange: [1, 0.7]
                                        })
                                    },
                                    {
                                        scaleY: this.animatedValue.interpolate({
                                            inputRange: [0, 1],
                                            outputRange: [1, 0.7]
                                        })
                                    },
                                    {perspective: 1000}
                            ]
                            } 
                         ]}
                        />
</TouchableOpacity>
}

)} 
}

Here how it should look like:
enter image description here

Lucky_girl
  • 4,543
  • 6
  • 42
  • 82

1 Answers1

0
expand = () => {
    Animated.timing(this.animatedValue, {
        toValue: 1,
        duration: 1000,
        easing: Easing.ease
    }).start(this.shrink)
}
shrink = () => {
    Animated.timing(this.animatedValue, {
        toValue: 1,
        duration: 1000,
        easing: Easing.ease
    }).start(this.expand)
}

call callback function inside start, then reverse the transform

this.animatedValue.interpolate({
    inputRange: [0, 1],
    outputRange: [0.7, 1.3]
})
...
Medet Tleukabiluly
  • 11,662
  • 3
  • 34
  • 69