From 580e8ec1cd18ab94d5986278f0336d14c957b9df Mon Sep 17 00:00:00 2001 From: koppt Date: Sun, 11 Nov 2018 20:20:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(Drawer):=20=E4=BF=AE=E5=A4=8D=20onClose=20?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=A7=A6=E5=8F=91=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#167)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/drawer/index.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/components/drawer/index.js b/src/components/drawer/index.js index 76352a374..d9a675b05 100644 --- a/src/components/drawer/index.js +++ b/src/components/drawer/index.js @@ -9,10 +9,17 @@ import AtComponent from '../../common/component' import './index.scss' export default class AtDrawer extends AtComponent { - constructor () { + constructor (props) { super(...arguments) - this.state = { animShow: false } - if (this.props.show) this.animShow() + this.state = { + animShow: false, + _show: props.show + } + } + + componentDidMount () { + const { _show } = this.state + if (_show) this.animShow() } onItemClick (index, e) { @@ -21,8 +28,9 @@ export default class AtDrawer extends AtComponent { } onHide () { - this.setState({ show: false }) - this.props.onClose && this.props.onClose() + this.setState({ _show: false }, () => { + this.props.onClose && this.props.onClose() + }) } animHide () { @@ -35,7 +43,7 @@ export default class AtDrawer extends AtComponent { } animShow () { - this.setState({ show: true }) + this.setState({ _show: true }) setTimeout(() => { this.setState({ animShow: true, @@ -47,11 +55,10 @@ export default class AtDrawer extends AtComponent { this.animHide(...arguments) } - componentWillReceiveProps (props) { - const { show } = props - if (show !== this.props.show) { - if (show) this.animShow() - else this.animHide(...arguments) + componentWillReceiveProps (nextProps) { + const { show } = nextProps + if (show !== this.props._show) { + show ? this.animShow() : this.animHide(...arguments) } } @@ -64,7 +71,7 @@ export default class AtDrawer extends AtComponent { } = this.props const { animShow, - show, + _show, } = this.state const rootClassName = ['at-drawer'] @@ -84,7 +91,7 @@ export default class AtDrawer extends AtComponent { } return ( - show &&