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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pan bool #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions SwiftMessages/Presenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Presenter: NSObject {
UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: focus)
}

func hide(animated: Bool, completion: @escaping AnimationCompletion) {
func hide(animated: Bool, isPanGest: Bool, completion: @escaping AnimationCompletion) {
isHiding = true
self.config.eventListeners.forEach { $0(.willHide(self.view)) }
let context = animationContext()
Expand All @@ -189,7 +189,7 @@ class Presenter: NSObject {
}
self.maskingView.removeFromSuperview()
completion(true)
self.config.eventListeners.forEach { $0(.didHide(self.view)) }
self.config.eventListeners.forEach { $0(.didHide(self.view, isIneractiveGesture: isPanGest)) }
}
guard animated else {
action()
Expand Down
30 changes: 15 additions & 15 deletions SwiftMessages/SwiftMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ open class SwiftMessages {
case willShow(UIView)
case didShow(UIView)
case willHide(UIView)
case didHide(UIView)
case didHide(UIView, isIneractiveGesture: Bool)

public var view: UIView {
switch self {
case .willShow(let view): return view
case .didShow(let view): return view
case .willHide(let view): return view
case .didHide(let view): return view
case .didHide(let view, _): return view
}
}

Expand Down Expand Up @@ -452,7 +452,7 @@ open class SwiftMessages {
*/
open func hide(animated: Bool = true) {
messageQueue.sync {
hideCurrent(animated: animated)
hideCurrent(animated: animated, isPanGest: false)
}
}

Expand All @@ -465,7 +465,7 @@ open class SwiftMessages {
queue.removeAll()
delays.removeAll()
counts.removeAll()
hideCurrent()
hideCurrent(isPanGest: false)
}
}

Expand All @@ -478,7 +478,7 @@ open class SwiftMessages {
open func hide(id: String) {
messageQueue.sync {
if id == _current?.id {
hideCurrent()
hideCurrent(isPanGest: false)
}
queue = queue.filter { $0.id != id }
delays.remove(id: id)
Expand All @@ -502,7 +502,7 @@ open class SwiftMessages {
}
}
if id == _current?.id {
hideCurrent()
hideCurrent(isPanGest: false)
}
queue = queue.filter { $0.id != id }
delays.remove(id: id)
Expand Down Expand Up @@ -621,7 +621,7 @@ open class SwiftMessages {
guard let strongSelf = self else { return }
guard completed else {
strongSelf.messageQueue.sync {
strongSelf.internalHide(presenter: current)
strongSelf.internalHide(presenter: current, isPanGest: false)
}
return
}
Expand All @@ -637,19 +637,19 @@ open class SwiftMessages {
}
}

fileprivate func internalHide(presenter: Presenter) {
fileprivate func internalHide(presenter: Presenter, isPanGest: Bool) {
if presenter == _current {
hideCurrent()
hideCurrent(isPanGest: isPanGest)
} else {
queue = queue.filter { $0 != presenter }
delays.remove(presenter: presenter)
}
}

fileprivate func hideCurrent(animated: Bool = true) {
fileprivate func hideCurrent(animated: Bool = true, isPanGest: Bool) {
guard let current = _current, !current.isHiding else { return }
let action = { [weak self] in
current.hide(animated: animated) { (completed) in
current.hide(animated: animated, isPanGest: isPanGest) { (completed) in
guard completed, let strongSelf = self else { return }
strongSelf.messageQueue.sync {
guard strongSelf._current === current else { return }
Expand All @@ -674,14 +674,14 @@ open class SwiftMessages {
messageQueue.asyncAfter(deadline: delayTime, execute: {
// Make sure we've still got a green light to auto-hide.
if self.autohideToken !== current { return }
self.internalHide(presenter: current)
self.internalHide(presenter: current, isPanGest: false)
})
}
}

deinit {
// Prevent orphaned messages
hideCurrent()
hideCurrent(isPanGest: false)
}
}

Expand Down Expand Up @@ -756,14 +756,14 @@ extension SwiftMessages: PresenterDelegate {

func hide(presenter: Presenter) {
messageQueue.sync {
self.internalHide(presenter: presenter)
self.internalHide(presenter: presenter, isPanGest: false)
}
}

public func hide(animator: Animator) {
messageQueue.sync {
guard let presenter = self.presenter(forAnimator: animator) else { return }
self.internalHide(presenter: presenter)
self.internalHide(presenter: presenter, isPanGest: true)
}
}

Expand Down