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

Extend or override backdropview #614

Open
DigitalVanilla opened this issue Nov 21, 2023 · 5 comments
Open

Extend or override backdropview #614

DigitalVanilla opened this issue Nov 21, 2023 · 5 comments

Comments

@DigitalVanilla
Copy link

Hello,

I needed for a project to subclass the background view, or make my own uiview class,
for set it as transparent backdropview (I did set it as .clear color with alpha 1.0) and when selected,
not only have a dismissal of the modal, but to propagate the tap event in the parent view controller,
so if the user tap a "close" button behind the modal, that button was trig as well.
For now I had to go into the pod files and modify by hand, but I wonder if you could add this possibility
in a new version of the library.

Thanks

@scenee
Copy link
Owner

scenee commented Dec 1, 2023

Thanks for your request. I'm considering enabling to assign an instance of a custom BackdropView.

[Added]

I've created iss-614 branch to enable to use a custom backdrop view. I also added a custom backrdop view with blur in the Samples example. Just check it.

@DigitalVanilla
Copy link
Author

Thanks 🙏🏻
In this way some more custom behaviour can be added like I did mention in my first post.
In fact I had to override the pod class for the background view to add some code to send the gesture to the parent view controller.

@DigitalVanilla
Copy link
Author

DigitalVanilla commented Dec 11, 2023

I had, for now, import brutally the pod into the project and updated the backdropview as the follow, maybe you can have some better ideas how to propagate the gesture in the presenting viewcontroller

  
  public var dismissalTapGestureRecognizer: UITapGestureRecognizer!
  
  public var notification: Notification.Name?
  public var presentingViewcontroller: UIViewController?
  
  override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    // little hack to fire back to the floatingpanel controller an extra action, like dismiss the floating panel
    // and at the same time let the event be trig in the presented viewcontroller
    if let pvc = presentingViewcontroller {
      if let n = notification {
        NotificationCenter.default.post(name: n, object: nil)
      }
      
      return pvc.view.hitTest(point, with: event)
    }

    // 1
    if !self.isUserInteractionEnabled || self.isHidden || self.alpha == 0 {
      return nil
    }
    //2
    var hitView: UIView? = self
    if !self.point(inside: point, with: event) {
      if self.clipsToBounds {
        return nil
      } else {
        hitView = nil
      }
    }
    //3
    for subview in self.subviews.reversed() {
      let insideSubview = self.convert(point, to: subview)
      if let sview = subview.hitTest(insideSubview, with: event) {
        return sview
      }
    }
    
    return hitView
  }
}

@DigitalVanilla
Copy link
Author

Thanks for your request. I'm considering enabling to assign an instance of a custom BackdropView.

[Added]

I've created iss-614 branch to enable to use a custom backdrop view. I also added a custom backrdop view with blur in the Samples example. Just check it.

Nice, when will you merge into master ?

@scenee
Copy link
Owner

scenee commented Feb 16, 2024

I will release the BackdropView update in v2.8.2. Thanks.

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

No branches or pull requests

2 participants