UIDrawer icon indicating copy to clipboard operation
UIDrawer copied to clipboard

[Question] DrawerPresentationControllerDelegate not working, applied to a UIViewController received as argument in a Pod class

Open pckz opened this issue 2 years ago • 0 comments

My I have to make a Pod who show a modal with custom height from bottomBar compatible with iOS12.

I trying to use a library called UIDrawer to show the bottomBar

I have a Pod that is initialized as following:

Example init ViewController:

let myPod = myPodController(controller: self, randomStr: "someRandomString")
myPod.run()

and myPodController has the following structure class

public class myPodController: UIViewController {
    let mainController: UIViewController // <- is the init ViewController passed as argument who will execute the .present() function later
    var bottomController: UINavigationController
    var someCustomController: SomeCustomControllerWithLogic

    public init(controller: UIViewController, randomStr: String) {
    
        self.mainController = controller
        self.randomStr = randomStr
        self.bottomController = UINavigationController(rootViewController: someCustomController)
    }
    
    public func run() {
        DispatchQueue.main.async {
             self.bottomController.modalPresentationStyle = .custom
             self.bottomController.transitioningDelegate = self
             self.mainController.present(self.bottomController, animated: true) // <-- here has to present, and transitionDelegate not work with the extension declared
        }
    }
}
extension myPodController: DrawerPresentationControllerDelegate {
    public func drawerMovedTo(position: DraweSnapPoint) {

    }
}
extension myPodController: UIViewControllerTransitioningDelegate {
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        return DrawerPresentationController(presentedViewController: presented, presenting: presenting, blurEffectStyle: .dark)
    }
}

using UIDrawer files who make the render, theres no way that the delegate of extension UIViewControllerTransitioningDelegate works

In the original example of UIDrawer works, I think because they declare the extension for the class who has can render the modal directly with:

self.present(viewController, animated: true) In my case, I have to present with self.mainController:

self.mainController.present(viewController, animated: true) and I think that's why the extension of DrawerPresentationControllerDelegate not work with the custom lib UIDrawer

So, my question is: How can extends the DrawerPresentationControllerDelegate for a custom controller that is located as variable into a class, in this case, how to make the self.mainController accepts the delegate of DrawerPresentationControllerDelegate?

pckz avatar Aug 16 '22 23:08 pckz