Skip to content

Commit

Permalink
#324: make previous window key again after dismissal (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
huri000 committed Dec 28, 2020
1 parent cafba39 commit 2bff39f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions Source/Infra/EKContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import QuickLayout
protocol EntryContentViewDelegate: class {
func changeToActive(withAttributes attributes: EKAttributes)
func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool)
func didFinishDisplaying(entry: EKEntryView, keepWindowActive: Bool)
func didFinishDisplaying(entry: EKEntryView, keepWindowActive: Bool, dismissCompletionHandler: SwiftEntryKit.DismissCompletionHandler?)
}

class EKContentView: UIView {
Expand Down Expand Up @@ -473,16 +473,16 @@ class EKContentView: UIView {
}

// Execute didDisappear action if needed
contentView.content.attributes.lifecycleEvents.didDisappear?()

// Execute dismiss handler if needed
dismissHandler?()

let didDisappear = contentView.content.attributes.lifecycleEvents.didDisappear

// Remove the view from its superview and in a case of a view controller, from its parent controller.
super.removeFromSuperview()
contentView.content.viewController?.removeFromParent()

entryDelegate.didFinishDisplaying(entry: contentView, keepWindowActive: keepWindow)
entryDelegate.didFinishDisplaying(entry: contentView, keepWindowActive: keepWindow, dismissCompletionHandler: dismissHandler)

// Lastly, perform the Dismiss Completion Handler as the entry is no longer displayed
didDisappear?()
}

deinit {
Expand Down
6 changes: 3 additions & 3 deletions Source/Infra/EKRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

protocol EntryPresenterDelegate: class {
var isResponsiveToTouches: Bool { set get }
func displayPendingEntryIfNeeded()
func displayPendingEntryOrRollbackWindow(dismissCompletionHandler: SwiftEntryKit.DismissCompletionHandler?)
}

class EKRootViewController: UIViewController {
Expand Down Expand Up @@ -214,7 +214,7 @@ extension EKRootViewController {

extension EKRootViewController: EntryContentViewDelegate {

func didFinishDisplaying(entry: EKEntryView, keepWindowActive: Bool) {
func didFinishDisplaying(entry: EKEntryView, keepWindowActive: Bool, dismissCompletionHandler: SwiftEntryKit.DismissCompletionHandler?) {
guard !isDisplaying else {
return
}
Expand All @@ -223,7 +223,7 @@ extension EKRootViewController: EntryContentViewDelegate {
return
}

delegate.displayPendingEntryIfNeeded()
delegate.displayPendingEntryOrRollbackWindow(dismissCompletionHandler: dismissCompletionHandler)
}

func changeToInactive(withAttributes attributes: EKAttributes, pushOut: Bool) {
Expand Down
12 changes: 11 additions & 1 deletion Source/Infra/EKWindowProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,21 @@ final class EKWindowProvider: EntryPresenterDelegate {
}

/** Display a pending entry if there is any inside the queue */
func displayPendingEntryIfNeeded() {
func displayPendingEntryOrRollbackWindow(dismissCompletionHandler: SwiftEntryKit.DismissCompletionHandler?) {
if let next = entryQueue.dequeue() {

// Execute dismiss handler if needed before dequeuing (potentially) another entry
dismissCompletionHandler?()

// Show the next entry in queue
show(entryView: next.view, presentInsideKeyWindow: next.presentInsideKeyWindow, rollbackWindow: next.rollbackWindow)
} else {

// Display the rollback window
displayRollbackWindow()

// As a last step, invoke the dismissal method
dismissCompletionHandler?()
}
}

Expand Down

0 comments on commit 2bff39f

Please sign in to comment.