From cc09544bdc1cc5d34c66c2e7d646133a88838d91 Mon Sep 17 00:00:00 2001 From: Anton Medoks Date: Mon, 21 Nov 2022 13:34:29 +0300 Subject: [PATCH 1/3] Added UITouch extension for ControlEvent --- .../{UIColor.swift => UIColor+.swift} | 0 .../Extensions/UITouch+.swift | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+) rename Sources/DSUIKitExtensions/Extensions/{UIColor.swift => UIColor+.swift} (100%) create mode 100644 Sources/DSUIKitExtensions/Extensions/UITouch+.swift diff --git a/Sources/DSUIKitExtensions/Extensions/UIColor.swift b/Sources/DSUIKitExtensions/Extensions/UIColor+.swift similarity index 100% rename from Sources/DSUIKitExtensions/Extensions/UIColor.swift rename to Sources/DSUIKitExtensions/Extensions/UIColor+.swift diff --git a/Sources/DSUIKitExtensions/Extensions/UITouch+.swift b/Sources/DSUIKitExtensions/Extensions/UITouch+.swift new file mode 100644 index 0000000..12fa11e --- /dev/null +++ b/Sources/DSUIKitExtensions/Extensions/UITouch+.swift @@ -0,0 +1,39 @@ +// Created for in 2022 +// +// Copyright (c) https://github.com/DuckingSwift + +import UIKit + +// MARK: - ControlEvent + +public 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 + } + } + } From c5edfb474c92f081512644c2406d609f4e3981e1 Mon Sep 17 00:00:00 2001 From: Anton Medoks Date: Mon, 21 Nov 2022 13:38:49 +0300 Subject: [PATCH 2/3] Fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a2eea9..4381bb1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# DSUIKitExtensions +# UIKitExtensions A description of this package. From 65f94f59e9421655ae23df91498160c45b653382 Mon Sep 17 00:00:00 2001 From: Anton Medoks Date: Fri, 2 Dec 2022 18:44:16 +0300 Subject: [PATCH 3/3] Format code --- .../Extensions/UITouch+.swift | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/Sources/DSUIKitExtensions/Extensions/UITouch+.swift b/Sources/DSUIKitExtensions/Extensions/UITouch+.swift index 12fa11e..7ee2c47 100644 --- a/Sources/DSUIKitExtensions/Extensions/UITouch+.swift +++ b/Sources/DSUIKitExtensions/Extensions/UITouch+.swift @@ -7,33 +7,32 @@ import UIKit // MARK: - ControlEvent public 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 - } - } - } + /// 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 + } + } +}