Skip to content

Commit

Permalink
Merge pull request #366 from kvyatkovskys/feature/pointer_interaction
Browse files Browse the repository at this point in the history
removed the common `UIView` extension to handle `pointer interaction`
  • Loading branch information
kvyatkovskys authored Aug 2, 2024
2 parents 010b5f2 + 2558797 commit f555bbd
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 26 deletions.
18 changes: 18 additions & 0 deletions Sources/KVKCalendar/AllDayEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,22 @@ final class AllDayEventView: UIView {
}
}

@available(iOS 13.4, *)
extension AllDayEventView: UIPointerInteractionDelegate {
func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

#endif
20 changes: 0 additions & 20 deletions Sources/KVKCalendar/Calendar+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,24 +389,4 @@ public extension KVKDequeueProxyProtocol where Self: UICollectionView {
extension UITableView: KVKDequeueProxyProtocol {}
extension UICollectionView: KVKDequeueProxyProtocol {}

@available(iOS 13.4, *)
extension UIView: UIPointerInteractionDelegate {

func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}

}

#endif
18 changes: 18 additions & 0 deletions Sources/KVKCalendar/DayCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,22 @@ class DayCell: UICollectionViewCell {
}
}

@available(iOS 13.4, *)
extension DayCell: UIPointerInteractionDelegate {
func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

#endif
18 changes: 18 additions & 0 deletions Sources/KVKCalendar/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,22 @@ final class EventView: EventViewGeneral {

}

@available(iOS 13.4, *)
extension EventView: UIPointerInteractionDelegate {
func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

#endif
18 changes: 18 additions & 0 deletions Sources/KVKCalendar/ListViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,22 @@ final class ListViewCell: KVKTableViewCell {

}

@available(iOS 13.4, *)
extension ListViewCell: UIPointerInteractionDelegate {
func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

#endif
4 changes: 0 additions & 4 deletions Sources/KVKCalendar/MonthCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ final class MonthCell: KVKCollectionViewCell {
dateLabel.frame = dateFrame
dateLabel.tag = defaultTagView
contentView.addSubview(dateLabel)

if #available(iOS 13.4, *) {
contentView.addPointInteraction()
}
}

required init?(coder aDecoder: NSCoder) {
Expand Down
16 changes: 15 additions & 1 deletion Sources/KVKCalendar/ResizeEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ final class ResizeEventView: UIView {
}

@available(iOS 13.4, *)
extension ResizeEventView {
extension ResizeEventView: UIPointerInteractionDelegate {

func pointerInteraction(_ interaction: UIPointerInteraction, regionFor request: UIPointerRegionRequest, defaultRegion: UIPointerRegion) -> UIPointerRegion? {
if topView.frame.contains(request.location) {
Expand All @@ -156,6 +156,20 @@ extension ResizeEventView {
}
}

func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

protocol ResizeEventViewDelegate: AnyObject {
Expand Down
1 change: 0 additions & 1 deletion Sources/KVKCalendar/ScrollableWeekView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ extension ScrollableWeekView: CalendarSettingProtocol {

if #available(iOS 14.0, *) {
cornerBtn.showsMenuAsPrimaryAction = true
cornerBtn.addPointInteraction()
cornerBtn.menu = createTimeZonesMenu()

if style.selectedTimeZones.count > 1 {
Expand Down
18 changes: 18 additions & 0 deletions Sources/KVKCalendar/YearCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,22 @@ final class YearCell: UICollectionViewCell {
}
}

@available(iOS 13.4, *)
extension YearCell: UIPointerInteractionDelegate {
func addPointInteraction() {
let interaction = UIPointerInteraction(delegate: self)
addInteraction(interaction)
}

public func pointerInteraction(_ interaction: UIPointerInteraction, styleFor region: UIPointerRegion) -> UIPointerStyle? {
var pointerStyle: UIPointerStyle?

if let interactionView = interaction.view {
let targetedPreview = UITargetedPreview(view: interactionView)
pointerStyle = UIPointerStyle(effect: .highlight(targetedPreview))
}
return pointerStyle
}
}

#endif

0 comments on commit f555bbd

Please sign in to comment.