Skip to content
Closed
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
32 changes: 32 additions & 0 deletions Sources/UIKit/UITouch/UITouch+ControlEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import UIKit
Copy link
Member

Choose a reason for hiding this comment

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

весь package под макос теперь не соберется

Copy link
Member

@vmzhivetyev vmzhivetyev Nov 18, 2022

Choose a reason for hiding this comment

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

оберните пожалуйста в #if os(iOS)

Copy link
Member

@vmzhivetyev vmzhivetyev Nov 18, 2022

Choose a reason for hiding this comment

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

и переместите пожалуйста в Sources/UIKitExtensions/...

Copy link
Member

Choose a reason for hiding this comment

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

А лучше вообще отдельный package сделать с UIKit (назвать его UIKitExtensions) и оставить чистым SwiftExtensions


extension UITouch {
/// Convert UITouch to UIControl.Event
var toControl: UIControl.Event? {
guard let view = self.view else { return nil }
let isInside = view.bounds.contains(location(in: view))
let wasInside = view.bounds.contains(previousLocation(in: view))
switch phase {
case .began:
guard isInside else { return nil }
return tapCount > 1 ? .touchDownRepeat : .touchDown
case .moved:
if isInside && wasInside {
return .touchDragInside
} else if isInside && !wasInside {
return .touchDragEnter
} else if !isInside && wasInside {
return .touchDragExit
} else if !isInside && !wasInside {
return .touchDragOutside
}
return nil
case .ended:
return isInside ? .touchUpInside : .touchUpOutside
case .cancelled:
return .touchCancel
default:
return nil
}
}
}