fastred / SloppySwiper

UINavigationController delegate that allows swipe back gesture to be started from anywhere on the screen (not just from the edge).
MIT License
806 stars 107 forks source link

Old navigationItem remains when leftBarButtonItem is set without title and sloppy-swiper cancelled #22

Open inamiy opened 7 years ago

inamiy commented 7 years ago

Hi!

This could be an UIKit bug (that is hard to fix), but I noticed an awkward navigationItem behavior as I wrote reproducing code below:

[Example] Reproduce navigationItem bug when leftBarButtonItem is set without title and sloppy-swiper cancelled

Step to reproduce

  1. Set left & right barButtonItems WITHOUT title.
  2. Push a new ViewController.
  3. Sloppy-swipe-back, but cancel it (don't pop).
  4. Sloppy-swipe-back to pop.
  5. RootViewController's navigationItem remains on navigationBar.

NOTE

Bug won't reproduce if...

  1. leftBarButtonItem is not set, or
  2. title is set

Is there any workaround or fixes for this problem? (One idea might be to add a dummy transparent text 😵) Thanks!

inamiy commented 7 years ago

OK, I just solved it by adding empty titleView as follows:

if (self.navigationItem.title == nil && self.navigationItem.titleView == nil) {
    self.navigationItem.titleView = [[UIView alloc] init];
}
fastred commented 7 years ago

Thanks for posting a workaround and a sample code! I think this may be a bug in SloppySwiper. I haven't used it with a custom leftBarButtonItem.

I'd investigate the logic in https://github.com/fastred/SloppySwiper/blob/master/Classes/SloppySwiper.m#L82-L107. There's also this separate issue (when not using SloppySwiper) that may be somehow related: http://holko.pl/ios/2014/04/06/interactive-pop-gesture/