Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
p-x9 committed Apr 13, 2023
1 parent 89f199e commit 5943c29
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions Sources/TouchTracker/Extension/UIWindow+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,19 @@ extension UIWindow {
return true
}
.forEach { view in
let touches = event.allTouches
touches?.forEach { touch in
switch touch.phase {
case .began:
view.touchesBegan(Set([touch]), with: event)
case .moved:
view.touchesMoved(Set([touch]), with: event)
case .ended:
view.touchesEnded(Set([touch]), with: event)
case .cancelled:
view.touchesCancelled(Set([touch]), with: event)
default:
break
}
guard let touches = event.allTouches else { return }
let began = touches.filter { $0.phase == .began }
let moved = touches.filter { $0.phase == .moved }
let ended = touches.filter { $0.phase == .cancelled || $0.phase == .ended }

if !began.isEmpty {
view.touchesBegan(began, with: event)
}
if !moved.isEmpty {
view.touchesMoved(moved, with: event)
}
if !ended.isEmpty {
view.touchesEnded(ended, with: event)
}
}
}
Expand Down

0 comments on commit 5943c29

Please sign in to comment.