Skip to content

Commit

Permalink
Allow specifying multiple interactive frames, not just one
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk committed Aug 14, 2022
1 parent 928a745 commit 1c10182
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Sources/TGCardViewController/cards/TGCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import UIKit

public protocol TGInteractiveCardTitle: UIView {

/// This method returns a frame that covers the interactive area of a card title in a
/// This method returns frames that cover the interactive areas of a card title in a
/// `TGCardView`. If the card title does not contain interactive components, this
/// method should return `nil`.
/// method should return an empty array.
///
/// - Parameter cardView: The parent view that contains the card title. This
/// is typically a subclass of `TGCardView`
func interactiveFrame(relativeTo cardView: TGCardView) -> CGRect?
func interactiveFrames(relativeTo cardView: TGCardView) -> [CGRect]

}

Expand Down Expand Up @@ -159,10 +160,11 @@ public class TGCardView: TGCornerView, TGPreferrableView {
func interactiveTitleContains(_ point: CGPoint) -> Bool {
guard
let titlePlaceholder = titleViewPlaceholder,
let interactiveTitle = titlePlaceholder.subviews.first as? TGInteractiveCardTitle,
let interactiveFrame = interactiveTitle.interactiveFrame(relativeTo: self)
let interactiveTitle = titlePlaceholder.subviews.first as? TGInteractiveCardTitle
else { return false }
return interactiveFrame.contains(point)

let frames = interactiveTitle.interactiveFrames(relativeTo: self)
return frames.contains { $0.contains(point) }
}

func headerHeight(for position: TGCardPosition) -> CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class TGCardDefaultTitleView: UIView, TGPreferrableView {

extension TGCardDefaultTitleView: TGInteractiveCardTitle {

func interactiveFrame(relativeTo cardView: TGCardView) -> CGRect? {
guard let accessory = accessoryViewContainer.subviews.first else { return nil }
return accessoryViewContainer.convert(accessory.frame, to: cardView)
func interactiveFrames(relativeTo cardView: TGCardView) -> [CGRect] {
guard let accessory = accessoryViewContainer.subviews.first else { return [] }
return [accessoryViewContainer.convert(accessory.frame, to: cardView)]
}

}

0 comments on commit 1c10182

Please sign in to comment.