rn: wait for animation before hiding SlidingView

This commit is contained in:
Saúl Ibarra Corretgé 2019-04-24 13:14:20 +02:00 committed by Zoltan Bettenbuk
parent 70dc22c107
commit 34dcbd991e
1 changed files with 37 additions and 31 deletions

View File

@ -110,7 +110,7 @@ export default class SlidingView extends PureComponent<Props, State> {
};
// Bind event handlers so they are only bound once per instance.
this._onHideMenu = this._onHideMenu.bind(this);
this._onHide = this._onHide.bind(this);
}
/**
@ -158,7 +158,7 @@ export default class SlidingView extends PureComponent<Props, State> {
pointerEvents = 'box-none'
style = { styles.sliderViewContainer } >
<TouchableWithoutFeedback
onPress = { this._onHideMenu } >
onPress = { this._onHide } >
<View style = { styles.sliderViewShadow } />
</TouchableWithoutFeedback>
<Animated.View
@ -211,7 +211,7 @@ export default class SlidingView extends PureComponent<Props, State> {
return style;
}
_onHideMenu: () => void;
_onHide: () => void;
/**
* Hides the slider.
@ -219,15 +219,16 @@ export default class SlidingView extends PureComponent<Props, State> {
* @private
* @returns {void}
*/
_onHideMenu() {
this._setShow(false);
_onHide() {
this._setShow(false)
.then(() => {
const { onHide } = this.props;
onHide && onHide();
});
}
_setShow: (boolean) => void;
_setShow: (boolean) => Promise<*>;
/**
* Shows/hides the slider menu.
@ -235,10 +236,13 @@ export default class SlidingView extends PureComponent<Props, State> {
* @param {boolean} show - If the slider view is to be made visible,
* {@code true}; otherwise, {@code false}.
* @private
* @returns {void}
* @returns {Promise}
*/
_setShow(show) {
return new Promise(resolve => {
if (!this._mounted) {
resolve();
return;
}
@ -261,6 +265,8 @@ export default class SlidingView extends PureComponent<Props, State> {
.start(({ finished }) => {
finished && this._mounted && !show
&& this.setState({ showOverlay: false });
resolve();
});
});
}
}