cubiq/SwipeView

Orientationchange event is flaky

Opened this issue · 2 comments

The behaviour of orientationchange event isn't consistent; specifically, on many Android devices this event fires before orientation is actually updated, resulting in the wrong (opposite) size being detected. On some Android devices, it apparently doesn't fire at all.

Workaround I am using is to unregister SwipeView from listening to orientationchange, and manually call __resize on window resize. My recommendation would be to remove orientationchange detection from SwipeView completely, and just rely on window resize, which seems to give more reliable results.

I'd hook resize only on android, or maybe call __resize inside a timeout. I'll check this, thanks for the report

By popular demand, here is a sketch of the code for my workaround (forgive any syntax errors, I did a cross-compile from coffeescript in my head):

var carousel = new SwipeView($('#carousel').get(0));
// prevent swipeview from resizing itself on orientation change, instead use `resize` event
window.removeEventListener('orientationchange', carousel, false);
window.addEventListener('resize', function(e) {
  carousel.__resize();
});

Alternatively, just patch line 38 in your copy of swipeview.js:
https://github.com/cubiq/SwipeView/blob/master/src/swipeview.js#L38