Created
September 25, 2018 03:00
-
-
Save isacjunior/73ab9e43f321b5dce1b876052e79a8db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { PureComponent } from 'react' | |
import { Animated } from 'react-native' | |
class SlideLeft extends PureComponent { | |
state = { | |
left: new Animated.Value(300), | |
// Precisamos mapear o valor a ser manipulado, no meu caso, coloquei no estado, tendo o valor inicial como 300. | |
} | |
componentDidMount() { | |
const { left } = this.state | |
// Apos montar o componente, executo o efeito de transição, passando o valor e as configurações necessárias. | |
Animated.spring(left, { | |
toValue: 0, // Aqui menciono o valor final no fim da animação. | |
speed: 2, // Velocidade da animação. | |
bounciness: 6, // Valor para o efeito de elástico. | |
}).start() | |
} | |
render() { | |
const { left } = this.state | |
const { children } = this.props | |
// Todo componente que terá animação precisa vir do Animated, neste caso o View. | |
// Passo o valor left que irá alterar nosso estilo. | |
return ( | |
<Animated.View style={{ left }}> | |
{children} | |
</Animated.View> | |
) | |
} | |
} | |
export default SlideLeft |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment