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

Refer to customBarViewController always gives nil #383

Closed
StackHelp opened this issue Apr 7, 2020 · 22 comments
Closed

Refer to customBarViewController always gives nil #383

StackHelp opened this issue Apr 7, 2020 · 22 comments
Labels

Comments

@StackHelp
Copy link

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
Copy link
Contributor

iDevelopper commented Apr 7, 2020

  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
Copy link
Author

StackHelp commented Apr 7, 2020

@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
Copy link
Contributor

And what about po self.tabBarController.popupBar

@StackHelp
Copy link
Author

@iDevelopper It's nil as well

@iDevelopper
Copy link
Contributor

From which controller?

@StackHelp
Copy link
Author

StackHelp commented Apr 8, 2020

@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
Copy link
Contributor

iDevelopper commented Apr 9, 2020

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
Copy link
Author

StackHelp commented Apr 9, 2020

@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
Copy link
Contributor

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

@StackHelp
Copy link
Author

StackHelp commented Apr 9, 2020

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

@iDevelopper
Copy link
Contributor

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

@iDevelopper
Copy link
Contributor

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

@StackHelp
Copy link
Author

StackHelp commented Apr 9, 2020

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

@iDevelopper
Copy link
Contributor

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
Copy link
Author

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

@iDevelopper
Copy link
Contributor

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
Copy link
Author

StackHelp commented Apr 9, 2020

@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
Copy link
Contributor

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

@StackHelp
Copy link
Author

@iDevelopper ok. Let me try

@StackHelp
Copy link
Author

@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
Copy link
Contributor

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants