iDevelopper / PBPopupController

A framework for presenting bars and view controllers as popup, much like the look and feel of Apple Music App.
MIT License
62 stars 15 forks source link

PBPopupPresentationController in the open state has a black rounding #23

Closed balabon7 closed 1 year ago

balabon7 commented 1 year ago

Hello Patrick.

When PBPopupPresentationController in the open state (status == .open ) has a defaultCornerRadius = 55.0

IMG_8146

If I start opening the Control Center in iOS (with a drag gesture from top to bottom), I will see these black corners in blur

IMG_8147

As far as I understand, rounding is configured in extension PBPopupPresentationController (PBPopupController library)

internal func setupCornerRadiusForPopupContentViewAnimated(_ animated: Bool, open: Bool)
{  ...  case .fullScreen:
cornerRadius = open ? defaultCornerRadius : 0.0 ...

Could you please help me to make this behavior:

When status == .open then cornerRadius = 0.0, but as soon as the user starts the "swipe-to-dismiss" gesture then cornerRadius = 55.0

(and then work with rounding will be implemented as it is now)

It seems to me that we can set up this in this place:

public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?
{
    self.popupPresentationController?.isPresenting = false
    self.popupPresentationController?.popupController = self
    self.popupPresentationController?.popupPresentationStyle = self.containerViewController.popupContentView.popupPresentationStyle

    return self.popupPresentationController
}

What do you think how best to do it?

iDevelopper commented 1 year ago

Hello,

It's a detail and you have the eye!

If we want to change this behavior, we need to make the following changes in PBPopupPopupPresentationController.swift (commented // Issue #23 in code below):

Can you test? And if it's okay I'll update the framework.

    override func presentationTransitionDidEnd(_ completed: Bool)
    {
        // Issue #23
        if self.popupPresentationStyle == .fullScreen {
            self.setupCornerRadiusForPopupContentViewAnimated(false, open: false)
        }
        //
        self.popupBarForPresentation?.removeFromSuperview()
        self.popupBarForPresentation = nil
        self.imageViewForPresentation?.removeFromSuperview()
        self.imageViewForPresentation = nil
        if !completed {
            self.cleanup()
        }
        else {
            self.blackView?.alpha = 1.0
            NotificationCenter.default.addObserver(self, selector: #selector(didEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil)
        }
    }
    override func dismissalTransitionWillBegin()
    {
        guard let coordinator = self.presentedViewController.transitionCoordinator,
              let containerView = self.containerView
        else {
            return
        }

        self.popupBarForPresentation = self.setupPopupBarForPresentation()
        if let popupBarForPresentation = self.popupBarForPresentation {
            self.popupContentView.contentView.addSubview(popupBarForPresentation)
            popupBarForPresentation.alpha = 0.0
        }

        self.imageViewForPresentation = self.setupImageViewForPresentation()
        if let imageViewForPresentation = self.imageViewForPresentation {
            self.popupContentView.contentView.addSubview(imageViewForPresentation)
            self.configureImageViewInStartPosition()
        }

        if let backingView = self.backingView {
            backingView.removeFromSuperview()
        }
        self.backingView = nil
        self.setupBackingView()
        self.animateBackingViewToDeck(true, animated: false)

        self.popupContentView.popupCloseButton?.setButtonStateTransitioning()

        // Issue #23
        self.setupCornerRadiusForPopupContentViewAnimated(false, open: true)
        //

        self.popupController.popupStatusBarStyle = self.popupController.containerPreferredStatusBarStyle

        coordinator.animate { context in
            self.animateBackingViewToDeck(false, animated: true)
            if !context.isInteractive {
                self.animateImageViewInFinalPosition()
                self.popupBarForPresentation?.alpha = 1.0
                self.popupContentView.popupCloseButton?.alpha = 0.0
            }

            self.setupCornerRadiusForPopupContentViewAnimated(true, open: false)

            self.presentingVC.setNeedsStatusBarAppearanceUpdate()

            containerView.layoutIfNeeded()
        } completion: { _ in
            self.popupContentView.popupImageView?.isHidden = false
            self.popupContentView.popupImageModule?.isHidden = false
        }
    }
    override func dismissalTransitionDidEnd(_ completed: Bool)
    {
        self.popupBarForPresentation?.removeFromSuperview()
        self.popupBarForPresentation = nil
        self.imageViewForPresentation?.removeFromSuperview()
        self.imageViewForPresentation = nil

        // Issue #23
        if self.popupPresentationStyle == .fullScreen {
            self.setupCornerRadiusForPopupContentViewAnimated(false, open: false)
        }
        //

        if completed {
            self.cleanup()
        }
        else {
            self.blackView?.alpha = 1.0
        }
    }
balabon7 commented 1 year ago

Now everything works perfectly☺️ No more dark corners. I checked, please update this framework.

iDevelopper commented 1 year ago

Completed in https://github.com/iDevelopper/PBPopupController/commit/b0d7bcc46e523158eeaf6af889fff7cdc7139065