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

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

Closed
adzialocha opened this issue Dec 27, 2014 · 14 comments
Closed

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

adzialocha opened this issue Dec 27, 2014 · 14 comments
Assignees
Milestone

Comments

@adzialocha
Copy link

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: #2309

@sloops77
Copy link

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?

@willyboy
Copy link

Having this issue as well.

@dmishh
Copy link

dmishh commented Feb 4, 2015

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

@darrynten
Copy link

👍 have the same issue

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

@wfsm
Copy link

wfsm commented Feb 11, 2015

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

@adamdbradley adamdbradley self-assigned this Feb 12, 2015
@ZelimDamian
Copy link

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();
    }
  });

@gilles-yvetot
Copy link

same problem here! Any update @adamdbradley ?

@imuhammad
Copy link

+1

my solution was

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

@DavidePastore
Copy link

👍 Same problem for me.

@hasainsab14
Copy link

Hi there,

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

eliabruni added a commit to eliabruni/soyloco-frontend that referenced this issue Apr 11, 2015
Bug +workaround documented here:
ionic-team/ionic-framework#2817
@mhartington mhartington added this to the 1.0.0-rc3 milestone Apr 13, 2015
@adamdbradley adamdbradley modified the milestones: 1.0.0-rc3, 1.0.0-rc4 Apr 13, 2015
@fahimshani
Copy link

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

@CyrilSabbagh
Copy link

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

@jcromp
Copy link

jcromp commented Sep 3, 2015

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

@Heckthor
Copy link

Heckthor commented Aug 19, 2016

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

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests