Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

add hit test to capture touch and send to subviews on notification cell #2705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Classes/Notifications/NotificationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ final class NotificationCell: SelectableCell, CAAnimationDelegate {
override var canBecomeFirstResponder: Bool {
return true
}

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
for view in subviews {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be more functional?

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    let view = subviews.map { view -> UIView? in
        let newPoint = view.convert(point, from: self)
        return view.hitTest(newPoint, with: event)
     }
     .compactMap { $0 }
     .first

   return view ?? super.hitTest(point, with: event)
}

What do you think?

let newPoint = view.convert(point, from: self)
let view = view.hitTest(newPoint, with: event)
if view != nil {
return view
}
}
return super.hitTest(point, with: event)
}

public func configure(with model: NotificationViewModel, delegate: NotificationCellDelegate?) {
textView.configure(with: model.title, width: contentView.bounds.width)
Expand Down