diff --git a/Hover.podspec b/Hover.podspec index f571a68..570e3e6 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 = '2.0.0' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://github.com/pedrommcarrasco/Hover' spec.authors = { 'Pedro Carrasco' => 'https://twitter.com/pedrommcarrasco' } diff --git a/Hover/Model/HoverConfiguration.swift b/Hover/Model/HoverConfiguration.swift index 21c7975..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 spacing: CGFloat + 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, - spacing: CGFloat = 12.0, + 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.spacing = spacing + self.padding = padding 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 52494b7..8d1b91d 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 } @@ -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.padding) 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.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.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.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.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.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.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.padding.top) } NSLayoutConstraint.activate([stackViewXConstraint, stackViewYConstraint])