Animated Scaling Button in React Native

Saad Khan
Apr 21, 2021

In this post, I will try to describe how can we easily create an animated scaling button in react native. First, let’s see how does the button work in action.

Demo

We can use the Animated.sequence in order to scale up and down sequentially. So onPress button, the code looks like the following –

          onPress={() => {
Animated.sequence([
Animated.timing(selectedAnim, {
toValue: 2,
duration: 300,
useNativeDriver: true,
}),
Animated.timing(selectedAnim, {
toValue: 1,
duration: 300,
useNativeDriver: true,
})
]).start(() => setSelected(prev=>!prev));
}}

Finally, we just need to use this selectedAnim value in our Animated.View.

<Animated.View style={[{transform: [{ scale: selectedAnim }]}]}>

The source code can be found here.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Saad Khan
Saad Khan

Written by Saad Khan

Mobile App Dev (Mainly focused on React Native)

No responses yet

Write a response