Presentr icon indicating copy to clipboard operation
Presentr copied to clipboard

Present a VC inside the presenter VC weird behaviour

Open chlebta opened this issue 8 years ago • 11 comments

My custom presenter is presenting another ViewController and when dismissing this second VC I got wired behaviour check ( the custom VC go to top of view )out the image.

img_0383 img_0382 img_0381

chlebta avatar Feb 13 '17 16:02 chlebta

Hi! Sorry for the late response, have been really busy with work, but I'm taking this whole week to look over all the issues and PR's. Thanks for your patience!

So you are using Presentr to present the first view controller, which works correctly because it shows your controller in the bottom as you want to.

Afterwards, you are presenting the second controller, then after dismissing that second controller, the first controller goes "full screen", copying the second controllers presentation.

  • How are you presenting the second controller? Using presentr or using a normal presentation?
  • In what VC are you holding on to the Presentr object?

Any sample code would be greatly appreciated!

:)

danlozano avatar Mar 20 '17 18:03 danlozano

@danlozano Yes I'm using presentr two present the first VC (the small one in bottom of screen) then when user click on first textfield here I present the second VC.

  • How are you presenting the second controller? Using presentr or using a normal presentation => Normal self.prensent()

  • In what VC are you holding on to the Presentr object? => In the Main VC that presenting the presentr

Snippet :

Main VC

    let presenter: Presentr = {
        let bounds = UIScreen.main.bounds
        let center = ModalCenterPosition.customOrigin(origin: CGPoint(x: 0, y: bounds.height - 210))
        let width = ModalSize.full
        let height = ModalSize.custom(size: 210)

        
        let presenter = Presentr(presentationType: .custom(width: width , height: height, center: center))
        presenter.transitionType = .coverVerticalWithSpring
        presenter.roundCorners = false
        return presenter
    }()

    //function to open the presentr (first VC)
    fileprivate func addTrip() {
        let addTripVC = UIStoryboard(name: "Passport", bundle: nil).instantiateViewController(withIdentifier: "addTripViewController") as! AddTripViewController
        addTripVC.delegate = self
        customPresentViewController(presenter, viewController: addTripVC, animated: true, completion: nil)
    }

Presentr VC

// How i'm calling the second VC inside the presentr VC 
self.present(searchVC, animated: true, completion: nil)

chlebta avatar Mar 23 '17 08:03 chlebta

OK!

So doing some research this seems to be a bug with Apple's SDK's.

I managed to recreate the bug, I think. I presented the small modal on the bottom using you Presentr. Then I presented another controller, using the normal built-in way, then dismissed that modal.

AND I did get the bug, but just for a second. The first small modal appears full-screen for a second, and then after that it resizes to it's original small size and position.

Is that what happens to you or does yours persist in that full screen size and position?

Anyways, I think the bugs are related if not the same. There is probably a fix by Apple or something we can do internally in Presentr to prevent this, BUT for now I figured out two ways that fixed it, at least in my case. Let me know if it works for you.

  • The first thing I tried is doing the second presentation with Presentr. I created a regular Presentr imitating the built in default presentation.
let presenter: Presentr = {
        let presenter = Presentr(presentationType: .fullScreen)
        presenter.transitionType = .coverVertical
        return presenter
    }()

Afterwards, when I dismissed that second VC, the first VC was in it's correct size and position, no bug! This is a cool solution because this way you can modify the second presentation even further using Presentr.

  • Another solution I came upon, if you want to use the apple built in present method. Just set this property on the second view controller your presenting.
let secondVC = storyboard!.instantiateViewController(withIdentifier: "SecondViewController")
secondVC.modalPresentationStyle = .overFullScreen
present(secondVC, animated: true, completion: nil)

The .overFullScreen modal presentation style is what you use when you don't want apple to remove the underlying views when making a presentation, in case you want to have a translucent background. But for some reason that fixes the bug as well!

Go ahead and try both "solutions" let me know if they worked for you.

danlozano avatar Mar 23 '17 15:03 danlozano

  • Another solution I found. If set animated = false on the second VC dismissal, it also works properly.

I would recommend any of the other two solutions, but it did seem interesting that this fixed the issue as well.

danlozano avatar Mar 23 '17 17:03 danlozano

I'll leave this issue opened for two reasons.

  1. If someone else runs into this, I want the fixes to be available to them here.
  2. To keep this open in case in the future this gets fixed by Apple or we find another way to fix/prevent this.

danlozano avatar Mar 23 '17 17:03 danlozano

Exactly the same issue I am facing with topHalf Presentr as reported in #102 .

annjawn avatar Jul 31 '17 02:07 annjawn

@annjawn Yeah, it seems like it's the same issue.

That's why I left this issue opened.

You should try any of the solutions in my previous 3 comments up here ^^^ .

danlozano avatar Jul 31 '17 02:07 danlozano

@danlozano Unfortunately, my second VC is too elaborate for me to be able to move it completely to Presentr, but it's a great idea so i will try it sometime in the future. That being said, I just tried setting the .modalPresentationStyle = .overFullScreen on my second VC and that seem to have solved the issue. 👍🏼

UPDATE: Although setting the modalPresentationStyle for the second VC to overFullScreen has solved the size issue, it now seems that once the Second VC is dismissed the background for the Presentr is messed up and becomes dark(er) almost black(ish), this is especially when using blur background i.e. .blurBackground = true and .blurStyle = .dark. However, it works ok with just a background color .backgroundColor = .darkGray and .backgroundOpacity = 0.8. It must also be noted that's it's inconsistent and may not be easily re-created in simulator but can be re-produced in a physical device.

annjawn avatar Jul 31 '17 03:07 annjawn

@annjawn hmm will look into the second issue you mentioned.

But, why can't you use Presentr to present the second view controller? Are you already using the custom view controller presentation API's to present it?

Even if the second vc is internally very elaborate, just doing a presentation with Presentr shouldn't change anything. 🤔

danlozano avatar Aug 02 '17 14:08 danlozano

@danlozano I guess now that I am thinking of it, you're right, I can present my second VC using Presentr. I am using just the base SDK present method right now. I'll give it a try. thanks.

annjawn avatar Aug 02 '17 17:08 annjawn

I felt this was apple sdk bug. Interestingly the solution does work. So thanks.

freesuraj avatar Dec 03 '17 22:12 freesuraj