Skip to content

Instantly share code, notes, and snippets.

@HerbertLim
Last active June 30, 2018 07:22
Show Gist options
  • Save HerbertLim/f6b26d5235418d37883b1d97a86350e8 to your computer and use it in GitHub Desktop.
Save HerbertLim/f6b26d5235418d37883b1d97a86350e8 to your computer and use it in GitHub Desktop.
Slide in and out animation at React Native
/*
* Not so good way to slide in, show for 4 seconds, and then hide window
*/
Animated.parallel([ // 윈도우를 슬라이드인, 페이드인 한다.
Animated.timing(
this.state.fadeAnim,
{
toValue: 1,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.in(),
useNativeDriver,
}
),
Animated.timing(
this.state.transY,
{
toValue: shouldFix ? 0 : -visibleWindowHeight,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.elastic(),
useNativeDriver,
}
)
]).start( () => { // 윈도우를 보여주는 애니메이션이 완료되었으면 윈도우를 사라지는 애니메이션을 한다
this.closeTimer = setTimeout( () => { // 윈도우를 4초 동안 보여주기 위해 setTimeout() 을 활용
// 슬라이드 다운, 페이드 아웃 애니메이션을 실행한다
Animated.parallel([
Animated.timing(
this.state.fadeAnim,
{
toValue: 0.01,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.back(),
useNativeDriver,
}
),
Animated.timing(
this.state.transY,
{
toValue: 0,
duration: isAndroid ? androidDuration : iosDuration,
easing: Easing.back(),
useNativeDriver,
}
)
]).start()
}, 4000)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment