Skip to content

Commit

Permalink
Merge branch 'fix/surfaceview-hittest'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdgroot committed Nov 22, 2022
2 parents 0581325 + 0fd5c8e commit 55fe2b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ extension UIView {
}
return ret
}

var isHittable: Bool {
return !isHidden && alpha >= 0.01 && isUserInteractionEnabled
}
}

extension UIView {
Expand Down
17 changes: 17 additions & 0 deletions Sources/SurfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,24 @@ public class SurfaceView: UIView {

shadowLayers = appearance.shadows.map { _ in CALayer() }
}

public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
if isHittable && super.backgroundColor != .clear && super.point(inside: point, with: event) {
return true
}

for subview in subviews {
if subview.isHittable {
let converted = convert(point, to: subview)
if subview.point(inside: converted, with: event) {
return true
}
}
}

return false
}

public override func updateConstraints() {
switch position {
case .top:
Expand Down

0 comments on commit 55fe2b0

Please sign in to comment.