scenee / FloatingPanel

A clean and easy-to-use floating panel UI component for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Extend or override backdropview

DigitalVanilla opened this issue · comments

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

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.

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.

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
  }
}

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 ?

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