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

Update event options to match new version of Swiper #14865

Closed

Conversation

adamlacombe
Copy link
Contributor

@adamlacombe adamlacombe commented Jul 25, 2018

Short description of what this resolves:

Some of the Swiper options have been re-named/re-structured: http://idangero.us/swiper/api/#events

When navigating away from a page that contained <ion-slides scrollbar={false}> you'd receive an error:

Uncaught TypeError: Cannot read property 'removeEventListener' of undefined
at Swiper.disableDraggable (ion-anchor.md.js:8691)
at Swiper.destroy (ion-anchor.md.js:8770)
at Swiper.destroy (ion-anchor.md.js:8837)
at ion-anchor.md.js:3370
at Array.forEach ()
at ion-anchor.md.js:3369
at Array.forEach ()
at Swiper.emit (ion-anchor.md.js:3363)
at Swiper.destroy (ion-anchor.md.js:6827)
at Slides.componentDidUnload (ion-anchor.md.js:11703)

It looks like Swiper expects the scrollbar div to be in the dom.

Changes proposed in this pull request:

Add events:

  • ionSlidesDidLoad
  • ionSlideTap
  • ionSlideDoubleTap

Fix:

  • The structure and names in eventOptions.
  • Keep swiper-scrollbar in dom and instead add a hidden attribute

Ionic Version: 4.0.0-beta.0

Fixes: #14859, #14822

@manucorporat manucorporat requested a review from mhartington July 29, 2018 13:26
@@ -379,7 +403,7 @@ export class Slides {
<slot></slot>
</div>
{ this.pager ? <div class="swiper-pagination"></div> : null }
{ this.scrollbar ? <div class="swiper-scrollbar"></div> : null }
<div class="swiper-scrollbar" hidden={!this.scrollbar}/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed? If the scrollbars are not needed, we should not render them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Swiper expects the scrollbar div to exist in the dom even if it isn't being displayed. When navigating away from a page that has the scrollbar prop set to false you'll receive this error:

Uncaught TypeError: Cannot read property 'removeEventListener' of undefined
at Swiper.disableDraggable (ion-anchor.md.js:8691)
at Swiper.destroy (ion-anchor.md.js:8770)
at Swiper.destroy (ion-anchor.md.js:8837)
at ion-anchor.md.js:3370
at Array.forEach ()
at ion-anchor.md.js:3369
at Array.forEach ()
at Swiper.emit (ion-anchor.md.js:3363)
at Swiper.destroy (ion-anchor.md.js:6827)
at Slides.componentDidUnload (ion-anchor.md.js:11703)

I didn't dig too far into it, there could be a better solution.

Keeping the scrollbar in the dom does seem to silent the Cannot read property 'removeEventListener' of undefined errors though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to modify the scrollbar options in the default settings

      scrollbar: {
        el: this.scrollbar ? '.swiper-scrollbar' : null,
        hide: true,
      },

Then you could go back to conditionally rendering the scrollbar.

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

Successfully merging this pull request may close these issues.

2 participants