From 79196874156378646344d64a5785fdb7984d7aed Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 12:01:20 +0200 Subject: [PATCH 1/7] Fix HitTest when tapping visible DimView --- Hover/UI/HoverView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hover/UI/HoverView.swift b/Hover/UI/HoverView.swift index 52494b7..1b29aaf 100644 --- a/Hover/UI/HoverView.swift +++ b/Hover/UI/HoverView.swift @@ -134,7 +134,7 @@ public extension HoverView { let hitView = super.hitTest(point, with: event) if hitView == self { onTouchInDim() - return nil + if state == .none { return nil } } return hitView } From 1bc80b69749afaa972cd4df006d7e495ff499064 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 12:02:44 +0200 Subject: [PATCH 2/7] Bump podspec version --- Hover.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hover.podspec b/Hover.podspec index f571a68..05c0b83 100644 --- a/Hover.podspec +++ b/Hover.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'Hover' - spec.version = '1.5.0' + spec.version = '1.5.1' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://github.com/pedrommcarrasco/Hover' spec.authors = { 'Pedro Carrasco' => 'https://twitter.com/pedrommcarrasco' } From 11cee98f8f942e8a172f779f9cc47bf756f1a3d2 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 12:47:28 +0200 Subject: [PATCH 3/7] First proposal to allow custom --- Example/Example/ViewController.swift | 4 +++- Hover/Model/HoverConfiguration.swift | 6 +++--- Hover/Model/HoverPosition.swift | 18 +++++++++--------- Hover/UI/HoverView.swift | 26 +++++++++++++++++--------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 60540e4..cbc3028 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -6,7 +6,9 @@ import os class ViewController: UIViewController { @IBOutlet weak var webview: WKWebView! - private let hoverView = HoverView(with: HoverConfiguration(image: .add, color: .gradient(top: .pink, bottom: .darkPink)), + private let hoverView = HoverView(with: HoverConfiguration(image: .add, + color: .gradient(top: .pink, bottom: .darkPink), + insets: .init(top: 12, left: 12, bottom: 40, right: 12)), items: [HoverItem(title: "Drop it Anywhere", image: .anywhere) { os_log("Tapped 'Drop it anywhere'") }, HoverItem(title: "Gesture Driven", image: .gesture) { os_log("Tapped 'Gesture driven'") }, HoverItem(title: "Give it a Star", image: .star) { os_log("Tapped 'Give it a star'") }]) diff --git a/Hover/Model/HoverConfiguration.swift b/Hover/Model/HoverConfiguration.swift index 21c7975..374850b 100644 --- a/Hover/Model/HoverConfiguration.swift +++ b/Hover/Model/HoverConfiguration.swift @@ -29,7 +29,7 @@ public struct HoverConfiguration { /// Dictates the size of the image shown in any button (imageSize = size * imageSizeRatio) public var imageSizeRatio: CGFloat /// Spacing between the floating button to the edges - public var spacing: CGFloat + public var insets: UIEdgeInsets /// Font used in items' labels public var font: UIFont? /// Color of the overlay @@ -53,7 +53,7 @@ public struct HoverConfiguration { color: HoverColor = .color(.blue), size: CGFloat = 60.0, imageSizeRatio: CGFloat = 0.4, - spacing: CGFloat = 12.0, + insets: UIEdgeInsets = .init(top: 12, left: 12, bottom: 12, right: 12), font: UIFont? = nil, dimColor: UIColor = UIColor.black.withAlphaComponent(0.75), initialPosition: HoverPosition = .bottomRight, @@ -64,7 +64,7 @@ public struct HoverConfiguration { self.imageExpandAnimation = imageExpandAnimation self.size = size self.imageSizeRatio = imageSizeRatio - self.spacing = spacing + self.insets = insets self.font = font self.dimColor = dimColor self.initialPosition = initialPosition diff --git a/Hover/Model/HoverPosition.swift b/Hover/Model/HoverPosition.swift index fc9e586..7aaf1fa 100644 --- a/Hover/Model/HoverPosition.swift +++ b/Hover/Model/HoverPosition.swift @@ -41,28 +41,28 @@ extension HoverPosition { // MARK: - Configuration extension HoverPosition { - func configurePosition(of guide: UILayoutGuide, inside view: UIView, with spacing: CGFloat) { + func configurePosition(of guide: UILayoutGuide, inside view: UIView, with insets: UIEdgeInsets) { let positionConstraints: [NSLayoutConstraint] switch self { case .topLeft: positionConstraints = [ - guide.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: spacing), - guide.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: spacing) + guide.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: insets.top), + guide.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: insets.left) ] case .topRight: positionConstraints = [ - guide.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: spacing), - guide.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -spacing) + guide.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: insets.top), + guide.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -insets.right) ] case .bottomLeft: positionConstraints = [ - guide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -spacing), - guide.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: spacing) + guide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -insets.bottom), + guide.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: insets.left) ] case .bottomRight: positionConstraints = [ - guide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -spacing), - guide.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -spacing) + guide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -insets.bottom), + guide.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -insets.right) ] } NSLayoutConstraint.activate(positionConstraints) diff --git a/Hover/UI/HoverView.swift b/Hover/UI/HoverView.swift index 1b29aaf..5a93a90 100644 --- a/Hover/UI/HoverView.swift +++ b/Hover/UI/HoverView.swift @@ -156,7 +156,7 @@ private extension HoverView { func defineConstraints() { anchors.forEach { - $0.position.configurePosition(of: $0.guide, inside: self, with: self.configuration.spacing) + $0.position.configurePosition(of: $0.guide, inside: self, with: self.configuration.insets) NSLayoutConstraint.activate( [ $0.guide.widthAnchor.constraint(equalToConstant: self.configuration.size), @@ -309,20 +309,28 @@ private extension HoverView { switch anchor.position { case .topLeft: itemsStackView.add(arrangedViews: itemViews.reversed(), hidden: true) - stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, constant: self.configuration.itemConfiguration.margin) - stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, constant: self.configuration.spacing) + stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, + constant: self.configuration.itemConfiguration.margin) + stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, + constant: self.configuration.insets.bottom) case .topRight: itemsStackView.add(arrangedViews: itemViews.reversed(), hidden: true) - stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, constant: -self.configuration.itemConfiguration.margin) - stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, constant: self.configuration.spacing) + stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, + constant: -self.configuration.itemConfiguration.margin) + stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, + constant: self.configuration.insets.bottom) case .bottomLeft: itemsStackView.add(arrangedViews: itemViews, hidden: true) - stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, constant: self.configuration.itemConfiguration.margin) - stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, constant: -self.configuration.spacing) + stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, + constant: self.configuration.itemConfiguration.margin) + stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, + constant: -self.configuration.insets.top) case .bottomRight: itemsStackView.add(arrangedViews: itemViews, hidden: true) - stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, constant: -self.configuration.itemConfiguration.margin) - stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, constant: -self.configuration.spacing) + stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, + constant: -self.configuration.itemConfiguration.margin) + stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, + constant: -self.configuration.insets.top) } NSLayoutConstraint.activate([stackViewXConstraint, stackViewYConstraint]) From 3a82741c0b815d3359325b8321347b7e66815ae5 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 12:48:44 +0200 Subject: [PATCH 4/7] First proposal to enable custom padding --- Example/Example/ViewController.swift | 2 +- Hover/Model/HoverConfiguration.swift | 6 +++--- Hover/UI/HoverView.swift | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index cbc3028..e86d81d 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -8,7 +8,7 @@ class ViewController: UIViewController { @IBOutlet weak var webview: WKWebView! private let hoverView = HoverView(with: HoverConfiguration(image: .add, color: .gradient(top: .pink, bottom: .darkPink), - insets: .init(top: 12, left: 12, bottom: 40, right: 12)), + padding: .init(top: 12, left: 12, bottom: 40, right: 12)), items: [HoverItem(title: "Drop it Anywhere", image: .anywhere) { os_log("Tapped 'Drop it anywhere'") }, HoverItem(title: "Gesture Driven", image: .gesture) { os_log("Tapped 'Gesture driven'") }, HoverItem(title: "Give it a Star", image: .star) { os_log("Tapped 'Give it a star'") }]) diff --git a/Hover/Model/HoverConfiguration.swift b/Hover/Model/HoverConfiguration.swift index 374850b..6479423 100644 --- a/Hover/Model/HoverConfiguration.swift +++ b/Hover/Model/HoverConfiguration.swift @@ -29,7 +29,7 @@ public struct HoverConfiguration { /// Dictates the size of the image shown in any button (imageSize = size * imageSizeRatio) public var imageSizeRatio: CGFloat /// Spacing between the floating button to the edges - public var insets: UIEdgeInsets + public var padding: UIEdgeInsets /// Font used in items' labels public var font: UIFont? /// Color of the overlay @@ -53,7 +53,7 @@ public struct HoverConfiguration { color: HoverColor = .color(.blue), size: CGFloat = 60.0, imageSizeRatio: CGFloat = 0.4, - insets: UIEdgeInsets = .init(top: 12, left: 12, bottom: 12, right: 12), + padding: UIEdgeInsets = .init(top: 12, left: 12, bottom: 12, right: 12), font: UIFont? = nil, dimColor: UIColor = UIColor.black.withAlphaComponent(0.75), initialPosition: HoverPosition = .bottomRight, @@ -64,7 +64,7 @@ public struct HoverConfiguration { self.imageExpandAnimation = imageExpandAnimation self.size = size self.imageSizeRatio = imageSizeRatio - self.insets = insets + self.padding = padding self.font = font self.dimColor = dimColor self.initialPosition = initialPosition diff --git a/Hover/UI/HoverView.swift b/Hover/UI/HoverView.swift index 5a93a90..8d1b91d 100644 --- a/Hover/UI/HoverView.swift +++ b/Hover/UI/HoverView.swift @@ -156,7 +156,7 @@ private extension HoverView { func defineConstraints() { anchors.forEach { - $0.position.configurePosition(of: $0.guide, inside: self, with: self.configuration.insets) + $0.position.configurePosition(of: $0.guide, inside: self, with: self.configuration.padding) NSLayoutConstraint.activate( [ $0.guide.widthAnchor.constraint(equalToConstant: self.configuration.size), @@ -312,25 +312,25 @@ private extension HoverView { stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, constant: self.configuration.itemConfiguration.margin) stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, - constant: self.configuration.insets.bottom) + constant: self.configuration.padding.bottom) case .topRight: itemsStackView.add(arrangedViews: itemViews.reversed(), hidden: true) stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, constant: -self.configuration.itemConfiguration.margin) stackViewYConstraint = itemsStackView.topAnchor.constraint(equalTo: currentAnchor.guide.bottomAnchor, - constant: self.configuration.insets.bottom) + constant: self.configuration.padding.bottom) case .bottomLeft: itemsStackView.add(arrangedViews: itemViews, hidden: true) stackViewXConstraint = itemsStackView.leadingAnchor.constraint(equalTo: anchor.guide.leadingAnchor, constant: self.configuration.itemConfiguration.margin) stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, - constant: -self.configuration.insets.top) + constant: -self.configuration.padding.top) case .bottomRight: itemsStackView.add(arrangedViews: itemViews, hidden: true) stackViewXConstraint = itemsStackView.trailingAnchor.constraint(equalTo: anchor.guide.trailingAnchor, constant: -self.configuration.itemConfiguration.margin) stackViewYConstraint = itemsStackView.bottomAnchor.constraint(equalTo: currentAnchor.guide.topAnchor, - constant: -self.configuration.insets.top) + constant: -self.configuration.padding.top) } NSLayoutConstraint.activate([stackViewXConstraint, stackViewYConstraint]) From a2736b8deba50c0cc1cff92ccd674bd93bbafc54 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 13:03:31 +0200 Subject: [PATCH 5/7] Revert original example code --- Example/Example/ViewController.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index e86d81d..60540e4 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -6,9 +6,7 @@ import os class ViewController: UIViewController { @IBOutlet weak var webview: WKWebView! - private let hoverView = HoverView(with: HoverConfiguration(image: .add, - color: .gradient(top: .pink, bottom: .darkPink), - padding: .init(top: 12, left: 12, bottom: 40, right: 12)), + private let hoverView = HoverView(with: HoverConfiguration(image: .add, color: .gradient(top: .pink, bottom: .darkPink)), items: [HoverItem(title: "Drop it Anywhere", image: .anywhere) { os_log("Tapped 'Drop it anywhere'") }, HoverItem(title: "Gesture Driven", image: .gesture) { os_log("Tapped 'Gesture driven'") }, HoverItem(title: "Give it a Star", image: .star) { os_log("Tapped 'Give it a star'") }]) From c1f96d244ab078bafcf94e27e439344c34293f4a Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 13:04:25 +0200 Subject: [PATCH 6/7] Bump version: 1.6.0 --- Hover.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hover.podspec b/Hover.podspec index 05c0b83..f79a862 100644 --- a/Hover.podspec +++ b/Hover.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'Hover' - spec.version = '1.5.1' + spec.version = '1.6.0' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://github.com/pedrommcarrasco/Hover' spec.authors = { 'Pedro Carrasco' => 'https://twitter.com/pedrommcarrasco' } From 68ff344bd2630b952c18867d2d027c93ad612f40 Mon Sep 17 00:00:00 2001 From: Bruno Guidolim Date: Thu, 12 Aug 2021 13:20:48 +0200 Subject: [PATCH 7/7] Bump version: 2.0.0 --- Hover.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Hover.podspec b/Hover.podspec index f79a862..570e3e6 100644 --- a/Hover.podspec +++ b/Hover.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'Hover' - spec.version = '1.6.0' + spec.version = '2.0.0' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://github.com/pedrommcarrasco/Hover' spec.authors = { 'Pedro Carrasco' => 'https://twitter.com/pedrommcarrasco' }