From dfbfc05eaae9bea46a8b0bf205582263ad0455b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AA=97=E4=BD=A0=E6=98=AF=E5=B0=8F=E7=8C=AB=E5=92=AA?= Date: Wed, 7 Aug 2019 20:25:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20this.btnsLeftWidth?= =?UTF-8?q?=20=E5=92=8C=20this.btnsRightWidth=20=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 this.btnsLeftWidth 和 this.btnsRightWidth 在未渲染完成的情况下拿到错误的 offsetWidth 值 --- src/Swipeout.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Swipeout.tsx b/src/Swipeout.tsx index 88c6e00..b126a9e 100644 --- a/src/Swipeout.tsx +++ b/src/Swipeout.tsx @@ -52,8 +52,10 @@ export default class Swipeout extends React.Component { } componentDidMount() { - this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0; - this.btnsRightWidth = this.right ? this.right.offsetWidth : 0; + setTimeout(() => { + this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0; + this.btnsRightWidth = this.right ? this.right.offsetWidth : 0; + }, 300); document.body.addEventListener('touchstart', this.onCloseSwipe, true); }