Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change window access modifier to open #46

Merged
merged 7 commits into from
Jan 29, 2024
Merged
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
42 changes: 20 additions & 22 deletions Sources/Fingertips/FingerTipWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ class FingerTipView: UIImageView {
}

@objc (MBXFingerTipOverlayWindow)
class FingerTipOverlayWindow: UIWindow {
override var rootViewController: UIViewController? {
set {
super.rootViewController = newValue
}

get {
return FingerTipWindow.fingerTipWindow?.rootViewController ?? super.rootViewController
}
}
}
Comment on lines -14 to -24
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was causing a warning in logs; the getter also looks suspicious - sharing a view controller between UIWindows sounds dangerous. I don't see any issue with removing this code.

class FingerTipOverlayWindow: UIWindow {}

@objc (MBXFingerTipWindow)
public class FingerTipWindow: UIWindow {
open class FingerTipWindow: UIWindow {

public static var fingerTipWindow: FingerTipWindow? {
return UIApplication.shared.windows.compactMap({ $0 as? FingerTipWindow }).first
Expand Down Expand Up @@ -97,7 +87,11 @@ public class FingerTipWindow: UIWindow {
var action: Bool?
var fingerTipRemovalScheduled: Bool = false

required init?(coder aDecoder: NSCoder) {
deinit {
NotificationCenter.default.removeObserver(self)
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

commonInit()
Expand Down Expand Up @@ -200,13 +194,6 @@ public class FingerTipWindow: UIWindow {
perform(#selector(removeInactiveFingerTips), with: nil, afterDelay: 0.1)
}

func cancelScheduledFingerTipRemoval() {
fingerTipRemovalScheduled = true
NSObject.cancelPreviousPerformRequests(withTarget: self,
selector: #selector(removeInactiveFingerTips),
object: nil)
}

Comment on lines -203 to -209
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not used; I imagine that it was once used in conjunction with the perform(#selector(removeInactiveFingerTips), with: nil, afterDelay: 0.1). I do not see a need for it, but perhaps I'm not seeing the full picture.

@objc func removeInactiveFingerTips() {
fingerTipRemovalScheduled = false

Expand All @@ -233,16 +220,27 @@ public class FingerTipWindow: UIWindow {
return
}

UIView.animate(withDuration: fadeDuration) {
let animation = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The animated parameter wasn't being observed. As it is it seems that animated is always true, so we could simplify and rename to removeFingerTipAnimated(with:).

touchView.alpha = 0
touchView.frame = CGRect(x: touchView.center.x - touchView.frame.size.width / 1.5,
y: touchView.center.y - touchView.frame.size.height / 1.5,
width: touchView.frame.size.width * 1.5,
height: touchView.frame.size.height * 1.5)
}

let completion: (Bool) -> () = { _ in
touchView.fadingOut = false
touchView.removeFromSuperview()
}

touchView.fadingOut = true
touchView.perform(#selector(removeFromSuperview), with: nil, afterDelay: fadeDuration)

if animated {
UIView.animate(withDuration: fadeDuration, animations: animation, completion: completion)
} else {
animation()
completion(true)
}
}

func shouldAutomaticallyRemoveFingerTip(for touch: UITouch) -> Bool {
Expand Down