ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

v1.0.0-beta.14: wrong ion-slide-box width after opening modal

Open adzialocha opened this issue 11 years ago • 14 comments

Code-Pen

http://codepen.io/anon/pen/ZYpRzw

The first view contains a slider-box inside a cached view, this slider breaks after opening a modal. This bug occurs only in cached views (since beta 14 release).

Steps to reproduce:

  • go to second view
  • open modal
  • close modal
  • go back to first view

Description

Opening a modal triggers an window.resize Event. https://github.com/driftyco/ionic/blob/master/js/angular/service/modal.js#L163

Slider-directives are listening to these resize events although theyre not visible and in cached mode. Theire event handlers are not being unregistered when put in view-cache. https://github.com/driftyco/ionic/blob/master/release/js/ionic.js#L7314 (is killmethod ever called? cant find the handler).

The triggered resize event calls the setup() function of the Slider, calculating the width of the slider container. Since this element is not visible at this point the width will be set to zero. https://github.com/driftyco/ionic/blob/master/release/js/ionic.js#L7109

There might propably be more bugs of this kind with other elements listening to a resize event although theire not shown.

Related issue: https://github.com/driftyco/ionic/issues/2309

adzialocha avatar Dec 27 '14 18:12 adzialocha

I'm also having this one. Currently I've hacked a work around into the view's controller:

  $scope.$on '$ionicView.beforeEnter', ->
    ionic.trigger('resize', {target: window})

PS. I would be happy to do the PR if i could get some direction: should it the event listeners be detached and then reattached like scope? Or should the call to setup() be suppressed if the view is detached?

sloops77 avatar Dec 29 '14 17:12 sloops77

Having this issue as well.

willyboy avatar Jan 21 '15 18:01 willyboy

I have the same issue. @sloops77 thanks for the workaround!

dmishh avatar Feb 04 '15 17:02 dmishh

:+1: have the same issue

http://codepen.io/anon/pen/dPJGKY

darrynten avatar Feb 10 '15 10:02 darrynten

I have the same issue too. @sloops77 I used your solution, but the slides doubled after manually resize, I use ng-repeat to show the slides

wfsm avatar Feb 11 '15 01:02 wfsm

I have the same problem. Show slidebox -> show modal -> back to slidebox , but its not visible.

My initial workaround (somewhat nasty):


  // assuming the slides are static cache this to save DOM lookups
  //var firstSlide = $('.container .slide').first();
  $scope.$watch(function() {
    // this is the nasty bit (visibility polling)
    var visible = $('.container .slide').first().is(":visible");
    return visible;
  }, function(visible) {
    // only need to do this when visible
    if(visible) {
      var width = $('.container .slide').first().width();
      // only update when the width is wrong
      if(width === 0) {
        $ionicSlideBoxDelegate.update();
      }  
    }
  });

I tried @sloops77 's solution, which seems to work nicely. Except that that I call not the resize trigger, but the slideBoxDelegate update directly. I think this will save some extra work, because resize may trigger all kinds of other updates. Here is how I do it:

  // assuming the slides are static cache this to save DOM lookups
  // var firstSlide = $('.container .slide').first();
  $scope.$on('$ionicView.beforeEnter', function() {
    // this is not polling anymore
    var width = $('.container .slide').first().width();
    // only update when the width is wrong
    if(width === 0) {
      $ionicSlideBoxDelegate.update();
    }
  });

ZelimDamian avatar Mar 01 '15 00:03 ZelimDamian

same problem here! Any update @adamdbradley ?

gilles-yvetot avatar Mar 30 '15 15:03 gilles-yvetot

+1

my solution was

$scope.$on('$ionicView.beforeEnter', function() { $ionicSlideBoxDelegate.update(); });

imuhammad avatar Apr 07 '15 08:04 imuhammad

:+1: Same problem for me.

DavidePastore avatar Apr 07 '15 10:04 DavidePastore

Hi there,

The workaround is not working for me. could some one give codepen sample plz?

hasainsab14 avatar Apr 10 '15 10:04 hasainsab14

making cache-view="false" in template file or cache: false in state worked for me.

fahimshani avatar Apr 30 '15 14:04 fahimshani

I don't know why this issue is closed but i'm still having this problem. all libs are up to date

CyrilSabbagh avatar Jun 13 '15 11:06 CyrilSabbagh

I had this issue today as well, @imuhammad This fixed it, thanks!

jcromp avatar Sep 03 '15 07:09 jcromp

Is there an actual fix for this instead of just workarounds? I still have this issue...

mikeCm14 avatar Aug 19 '16 05:08 mikeCm14