ivanvorobei / SPStorkController

Now playing controller from Apple Music, Mail & Podcasts Apple's apps.
https://opensource.ivanvorobei.io
MIT License
2.74k stars 204 forks source link

Trouble with updatePresentingController #98

Closed cedixon closed 5 years ago

cedixon commented 5 years ago

I'm trying to update UILabel on presenting ViewController when the user taps a button in a modally presented VC. Here's the code I'm using to present the modal:

modalShopView = ModalShopViewController()
modalShopView.delegate = self
let transitionDelegate = SPStorkTransitioningDelegate()
transitionDelegate.customHeight = 450
modalShopView.transitioningDelegate = transitionDelegate
modalShopView.modalPresentationStyle = .custom
self.present(modalShopView, animated: true, completion: nil)

I'm assuming that I need to call SPStorkController.updatePresentingController(modal:) or SPStorkController.updatePresentingController(parent:), but where should this be run from?

In the modal VC, I've tried:

delegate?.didBuyItem()
SPStorkController.updatePresentingController(parent: self.presentingViewController!)

and in the presenting VC delegate method I've tried:

extension CityViewController: ShopViewDelegate {
    func didBuyItem() {
        label.text = newText
        SPStorkController.updatePresentingController(modal: modalShopView)
    }
}

But neither result in the presenting VC's snapshot being updated. I'm thinking I must be calling updatePresentingController incorrectly? Where should I call it from?

ivanvorobei commented 5 years ago

Hi!

For modal - pass modal controller, which presenting as SPStork. For parent - pass parent controller, on which controller present pass.

If you try update in SPStork controller, I think you need call

SPStorkController.updatePresentingController(modal: self)

Pass self because self is modal controller.