Skip to content

Commit d1a7cf1

Browse files
hendesiFelix Desiderato
andauthored
Experiment/tap location (#6)
* Reactivate dismissal logic * Add option to dismiss all tooltips * Fix typo * Rename function Co-authored-by: Felix Desiderato <felix.desiderato@tum.de>
1 parent d93bbdd commit d1a7cf1

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

Sources/SwiftTooltipKit/Extensions.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ internal extension UIApplication {
2828
static func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
2929
if let nav = base as? UINavigationController {
3030
return getTopViewController(base: nav.visibleViewController)
31-
31+
3232
} else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
3333
return getTopViewController(base: selected)
34-
34+
3535
} else if let presented = base?.presentedViewController {
3636
return getTopViewController(base: presented)
3737
}
@@ -61,7 +61,7 @@ extension UIView {
6161
/// True if there is currently a tooltip presented that has the calling view as `presentingView`.
6262
public var hasActiveTooltip: Bool {
6363
guard let activeTooltips = UIApplication.shared.keyWindow?.subviews.filter({ $0 is Tooltip }),
64-
!activeTooltips.isEmpty else { return false }
64+
!activeTooltips.isEmpty else { return false }
6565

6666
return activeTooltips.compactMap { $0 as? Tooltip }.contains(where: { $0.presentingView == self })
6767
}
@@ -93,7 +93,7 @@ extension UIView {
9393
label.numberOfLines = 0
9494
label.text = text
9595
label.preferredMaxLayoutWidth = configuration.labelConfiguration.preferredMaxLayoutWidth
96-
96+
9797
let toolTip = Tooltip(view: label, presentingView: self, orientation: orientation, configuration: configuration)
9898

9999
UIApplication.shared.keyWindow?.addSubview(toolTip)
@@ -171,4 +171,14 @@ extension UIBarItem {
171171
}
172172
}
173173

174+
extension Tooltip {
175+
/// Dismisses all tooltips that are currently shown on any sub view in the `keyWindow`.
176+
public static func dismissAll() {
177+
guard let activeTooltips = UIApplication.shared.keyWindow?.subviews.filter({ $0 is Tooltip }),
178+
!activeTooltips.isEmpty else { return }
179+
180+
activeTooltips.compactMap { $0 as? Tooltip }.forEach { $0.dismiss() }
181+
}
182+
}
183+
174184
#endif

Sources/SwiftTooltipKit/Tooltip.swift

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,11 @@ open class Tooltip: UIView {
434434
}
435435

436436
public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
437-
dismiss()
438-
return false
439-
440-
// TODO: Maybe enable later
441-
// if !self.bounds.contains(point) {
442-
// dismiss()
443-
// return false
444-
// }
445-
// return true
437+
if !self.bounds.contains(point) {
438+
dismiss()
439+
return false
440+
}
441+
return true
446442
}
447443
}
448444

0 commit comments

Comments
 (0)