From a52e20887bc7ddd7e5119b6953462cfdd63acbf1 Mon Sep 17 00:00:00 2001 From: Zach Nolan Date: Thu, 1 Mar 2018 16:09:57 -0800 Subject: [PATCH] fix disableOnBackPress --- index.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 872f405..6cbd740 100644 --- a/index.js +++ b/index.js @@ -13,13 +13,13 @@ import { class Modal extends Component { constructor() { super(); - + this.state = { opacity: new Animated.Value(0), scale: new Animated.Value(0.8), offset: new Animated.Value(0) }; - + this.hardwareBackPress = this.hardwareBackPress.bind(this); } componentWillMount() { @@ -46,21 +46,19 @@ class Modal extends Component { this.close(); } } - + if (props.offset !== this.props.offset) { this.animateOffset(props.offset); } } hardwareBackPress() { - if (this.props.disableOnBackPress) { - return true; - } - if (this.state.open) { - this.close(); + if (!this.props.disableOnBackPress) { + this.close(); + } return true; } - + return false; } componentDidMount() { @@ -86,7 +84,7 @@ class Modal extends Component { duration: animationDuration } ).start(); - + Animated.spring( this.state.scale, { @@ -95,7 +93,7 @@ class Modal extends Component { } ).start(); } - + setTimeout(() => { if (toValue) { this.props.modalDidOpen(); @@ -109,11 +107,11 @@ class Modal extends Component { render() { const {opacity, open, scale, offset, children} = this.state; let containerStyles = [styles.absolute, styles.container, this.props.containerStyle]; - + if (!this.state.open) { containerStyles.push(styles.hidden); } - + return (