Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong dimensionsof this.btnsLeftWidth when ComponentDidMount #48

Open
Moskvyak opened this issue Oct 27, 2017 · 3 comments
Open

Wrong dimensionsof this.btnsLeftWidth when ComponentDidMount #48

Moskvyak opened this issue Oct 27, 2017 · 3 comments

Comments

@Moskvyak
Copy link

Moskvyak commented Oct 27, 2017

I noticed that in some cases this function in Swipeout.js:

 _createClass(Swipeout, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0;
            this.btnsRightWidth = this.right ? this.right.offsetWidth : 0;
            document.body.addEventListener('touchstart', this.onCloseSwipe, true);
        }
    },

returns me this.btnsLeftWidth as 0 because this.left.offsetWidth returns 0 even though this.left is defined and it's a proper

It happens when I have fixed dialog and the content of it as
image

As a result this.btnsLeftWidth is 0 and this block (that responsible for swiping)

var limit = value > 0 ? _this.btnsLeftWidth : -_this.btnsRightWidth;
            var contentLeft = _this._getContentEasing(value, limit);
            var transform = 'translate3d(' + contentLeft + 'px, 0px, 0px)'; 

return translate3d(0px,0px,0px) which does not swipe.

Quick fix was to add setTimeout on that function (even with 0 delay it fixes the issue).

_createClass(Swipeout, [
    {
      key: 'componentDidMount',
      value: function componentDidMount() {
        setTimeout(() => {
          this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0
          this.btnsRightWidth = this.right ? this.right.offsetWidth : 0
          document.body.addEventListener('touchstart', this.onCloseSwipe, true)
        }, 0)
      }
    },

Could you please have a look and maybe find something better?

@silentcloud
Copy link
Member

@Moskvyak I will check this later

@shaodahong
Copy link
Member

this.btnsLeftWidth = this.left ? this.left.offsetWidth : 0;
this.btnsRightWidth = this.right ? this.right.offsetWidth : 0;

这样写有时候是拿不到正确的值的

@summer-wu
Copy link

I encountered this bug,too! My solution is to calling method instead of reading variable. Change all this.btnsRightWidth to this.get_btnsRightWidth(),and add the following method

function get_btnsRightWidth(){
        return this.right ? this.right.offsetWidth : 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants