AnimatedでModalの
Animationを変えてみた
2019/01/17
自己紹介
 大津 穂高
 OPEN8 Inc.
 テクノロジー開発本部 コンテンツ部
@14__oz
ルトロン
モーダルとAnimated
 ModalのanimatedTypeの「slide」「fade」を
組み合わせたような出現方法を実現
モーダルとAnimated
?
Modalの完成
Fade
Slide
モーダルのコード
<Modal
transparent
visible={this.props.isVisible}
animationType={'none'}
onRequestClose={this.closeModal}
>
<View
style={[s.background]}
>
<View style={[s.modalContainer]}>
{/*Modalの中身*/}
</View>
</View>
</Modal>
モーダルのコード
<Modal
transparent
visible={this.props.isVisible}
animationType={'none'}
onRequestClose={this.closeModal}
>
<Animated.View
style={[s.background, { opacity: this.modalAnimation }]}
>
<Animated.View style={[s.modalContainer, { top: contentTop }]}>
{/*Modalの中身*/}
</Animated.View>
</Animated.View>
</Modal>
Animated.timing
componentWillReceiveProps(nextProps) {
if (nextProps.isVisible) {
Animated.timing(this.modalAnimation, {
toValue: 1,
duration: 300
}).start();
}
}
const contentTop = this.modalAnimation.interpolate({
inputRange: [0, 1],
outputRange: [DeviceHeight, 0]
});
interpolate
プログレスバー
プログレスバーのコード
<View>
<Animated.View
style={[
{ flex: percent },
s.progressBar
]}
/>
</View>
Animated.Valueをグローバルで持つ
import {Animated} from 'react-native';
const percent = new Animated.Value(0);
export default percent;
Animation面白いよ!!

AnimatedでmodalのAnimationを変えてみた