LeoNatan / LNPopupController

A framework for presenting view controllers as popups of other view controllers, much like the Apple Music and Podcasts apps.
MIT License
3.04k stars 342 forks source link

Refer to customBarViewController always gives `nil` #383

Closed StackHelp closed 4 years ago

StackHelp commented 4 years ago

I am trying to use the custom controller as a popupBar and for that, I set up code like

    let customPlayerBar = PlayerPopUpBarVC.instantiate()
    self.tabBarController?.popupBar.customBarViewController = customPlayerBar
    self.tabBarController?.presentPopupBar(withContentViewController: vc, openPopup: true, animated: true, completion: nil)

Now, the problem is when I'm trying to refer customBarViewController, it gives me nil

    if let customItem = self.tabBarController?.popupBar.customBarViewController as? PlayerPopUpBarVC { } // I got nil here 

So, What's the correct way to refer customBarViewController that we can change/ update elements that are part of it.

Device, OS and Xcode Versions

Simulator: iPhone 11, XCode Version 11.2.1, iOS 13 Device: iPhone 7, XCode Version 11.2.1, iOS 13

iDevelopper commented 4 years ago
  1. Is customPlayerBar inherit from LNPopupCustomBarViewController?

  2. To update popupItem from the popupContentViewController: popupItem is accessible from your vc (the popupContentViewController): self.popupItem

  3. To update popupItem from the container VC: containerVC.popupBar.popupItem

StackHelp commented 4 years ago

@iDevelopper

  1. Yes class PlayerPopUpBarVC: LNPopupCustomBarViewController

       class PlayerPopUpBarVC: LNPopupCustomBarViewController {
             @IBOutlet weak var songImageView: UIImageView!
             @IBOutlet weak var songTitleLabel: UILabel!
       }
  2. I don't understand this. In #354 , Leo Suggests this before closing an issue. Custom bars do not have images, progress bars or any other of the standard views. It's up to you to implement them..

So, as I want custom things and custom layouts, I made a custom bar but it's not accessible than it's of no use.

These are some logs I got

(lldb) po self.popupBar
<LNPopupBar: 0x7ffa7afa11d0; frame = (0 896; 414 0); clipsToBounds = YES; hidden = YES; gestureRecognizers = <NSArray: 0x60000330aa30>; layer = <CALayer: 0x600003d2df00>>

(lldb) po self.popupBar.customBarViewController
nil

(lldb) po self.popupBar.popupItem
nil
iDevelopper commented 4 years ago

And what about po self.tabBarController.popupBar

StackHelp commented 4 years ago

@iDevelopper It's nil as well

iDevelopper commented 4 years ago

From which controller?

StackHelp commented 4 years ago

@iDevelopper

    let vc = PlayerViewController.instantiate()

    let customPlayerBar = PlayerPopUpBarVC.instantiate()
    self.tabBarController?.popupBar.customBarViewController = customPlayerBar
    self.tabBarController?.presentPopupBar(withContentViewController: vc, openPopup: true, animated: true, completion: nil)

I am calling if let customItem = self.tabBarController?.popupBar.customBarViewController as? PlayerPopUpBarVC { } in PlayerViewController which is contentViewController

iDevelopper commented 4 years ago

In your playerViewController, which is the contentViewController, you simply access the popuItem like this:

self.popupItem

The popupBar is: self.popupPresentationContainer?.popupBar (you do not have a tabBarController here, this is the popupPresentationContainer's property) The custom bar controller is self.popupPresentationContainer?.popupBar.customBarViewController

StackHelp commented 4 years ago

@iDevelopper Here is the log for popupPresentationContainer in playerViewController

(lldb) po self.popupPresentationContainer?.popupBar.customBarViewController
nil

(lldb) po self.popupPresentationContainer?.popupBar
nil

(lldb) po self.popupPresentationContainer
nil
iDevelopper commented 4 years ago

I think you are in the viewDidLoad function, try in viewWillAppear.

StackHelp commented 4 years ago

@iDevelopper But why? If it's there in popupPresentationContainer, then whenever we call we should have get it.

iDevelopper commented 4 years ago

popupPresentationContainer is set during the popup bar presentation. You probably load your playerViewController before the presentation...

iDevelopper commented 4 years ago

Do you need to access to popupPresentationContainer in viewDidLoad? Why?

StackHelp commented 4 years ago

I am loading it as it described in readme self.tabBarController?.presentPopupBar(withContentViewController: vc, openPopup: true, animated: true, completion: nil)

iDevelopper commented 4 years ago

Yes, this is how you present the popup bar. But your vc (the player view controller) is already allocated and his view loaded. Then in viewDidLoad you can't have access to popupPresentationContainer. Search why his view is already loaded. Look at your instantiate() function... And put a breakpoint in viewDidLoad() function, you will see that the view is loaded before the popup bar presentation.

StackHelp commented 4 years ago

@iDevelopper I don't understand this scenario. can you help me If I am sharing my screen?

iDevelopper commented 4 years ago

You can share your screen but your code is welcome to understand. I ask the question again:

Do you need to access to popupPresentationContainer in viewDidLoad?

StackHelp commented 4 years ago

@iDevelopper I want it on runtimes, like when song loads or song change

var currentMedia: Media = Media() {
    didSet {
        if isViewLoaded {
            playMediaScenario() // In this function I want to refer customBarViewController
        }
    }
}

I have checked you have a git repo for Swift version as well but I don't think it supports custom controller yet.

iDevelopper commented 4 years ago

Can you present the popup bar and set currentMedia in the completion block? A least for the first song...

StackHelp commented 4 years ago

@iDevelopper ok. Let me try

StackHelp commented 4 years ago

@iDevelopper Yes SIr, It worked. Now I understood that the thing is PlayerView Loads even before completing presentation of popupBar and that's why it's not even in hierarchy of controllers and that's why it produces nil. Thanks a lot for your help and giving this issue too much time.

iDevelopper commented 4 years ago

@StackHelp , glad to hear it works!

I have checked you have a git repo for Swift version as well but I don't think it supports custom controller yet.

This framework support custom bars. But a little outdated, I will update with a new version soon. If you want to test?... The main difference with LN is that this framework uses fewer private APIs and animates views (such as image or controls), as the Apple Music application does.

StackHelp commented 4 years ago

@iDevelopper Yes, I will surely test it once you updated it. I like to do that.