Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native: LayoutAnimation

Tags:

react-native

I am using react-native's LayoutAnimation to implement a custom switch component.

enter image description here

I am animating the movement of the circle using LayoutAnimation like so:

componentWillUpdate() {
  let switchAnimation = {
    duration: 250,
     update: {
       type: LayoutAnimation.Types.linear,
       property: LayoutAnimation.Properties.opacity,
     },
  };
  LayoutAnimation.configureNext(switchAnimation);
}

The switch is its own component. It recieves props to set the circle to be on the left or right using css (justifyContent flex-start or flex-end)

Problem is in my view when the switch changes value other components change as well: Namely when the switch is hit:

1) Switch changes

2) An icon changes

3) Some text changes

All of the above animate. I want to reduce the animation to affect the switch only

UPDATE: I have tried using the Animated API but it doesnt seem to support animating flex properties. Is there really no one out there that uses The Animated API extensively?

like image 893
Gilbert Nwaiwu Avatar asked Mar 22 '17 12:03

Gilbert Nwaiwu


People also ask

How do I make Layout animations work in Android react native?

How do I make Layout animations work in Android react native? import { LayoutAnimation, Platform, UIManager} from “react-native”; Step 2: Initialize this in the constructor. Step 3: Call when the UI Layout changes.

How do you transition in react native?

The transition animation is one of the easiest ways to easily animate a React Native application. It provides a way to create a seamless change between various states in your application. In this tutorial, we will be exploring the Transition API and a use-case where the transition animation can be employed; Dark mode.

What is Layout animation?

Layout builds the first 3D representation of that storyboard, in a full cinematic form, by using the characters, sets and props created by the Modeling department. Layout Artists animate the characters roughly at this stage of production, working efficiently through numerous iterations.


1 Answers

LayoutAnimation does a lot under the hood. Unless you are willing to go through the source you can set and vary a margin value in order to move the circle in the container. You can make all the calculations within the component and expose some styles as props.

like image 74
Ayodeji Agboola Avatar answered Oct 10 '22 13:10

Ayodeji Agboola