Skip to content

Commit

Permalink
Rename NoticeArtifact to NoticePresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
shiki committed Mar 18, 2019
1 parent 262a9f8 commit 64d0031
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions WordPress/Classes/ViewRelated/System/Notices/NoticePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import WordPressFlux
/// - SeeAlso: `NoticeAction`
class NoticePresenter: NSObject {
/// Used for tracking the currently displayed Notice and its corresponding view.
private struct NoticeArtifact {
private struct NoticePresentation {
let notice: Notice
let containerView: NoticeContainerView?
}
Expand All @@ -50,7 +50,7 @@ class NoticePresenter: NSObject {
private let generator = UINotificationFeedbackGenerator()
private var storeReceipt: Receipt?

private var currentNoticeArtifact: NoticeArtifact?
private var currentNoticePresentation: NoticePresentation?

private init(store: NoticeStore) {
self.store = store
Expand Down Expand Up @@ -85,7 +85,7 @@ class NoticePresenter: NSObject {
private func listenToKeyboardEvents() {
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: nil) { [weak self] (notification) in
guard let self = self,
let currentContainer = self.currentNoticeArtifact?.containerView,
let currentContainer = self.currentNoticePresentation?.containerView,
let userInfo = notification.userInfo,
let keyboardFrameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue,
let durationValue = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else {
Expand All @@ -101,7 +101,7 @@ class NoticePresenter: NSObject {
}
NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: nil) { [weak self] (notification) in
guard let self = self,
let currentContainer = self.currentNoticeArtifact?.containerView,
let currentContainer = self.currentNoticePresentation?.containerView,
let userInfo = notification.userInfo,
let durationValue = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else {
return
Expand All @@ -119,20 +119,20 @@ class NoticePresenter: NSObject {
/// In here, we determine whether to show a Notice or dismiss the currently shown Notice based
/// on the value of `NoticeStore.currentNotice`.
private func onStoreChange() {
guard currentNoticeArtifact?.notice != store.currentNotice else {
guard currentNoticePresentation?.notice != store.currentNotice else {
return
}

dismissForegroundNotice()

currentNoticeArtifact = nil
currentNoticePresentation = nil

guard let notice = store.currentNotice else {
return
}

if let artifact = present(notice) {
currentNoticeArtifact = artifact
currentNoticePresentation = artifact
} else {
// We were not able to show the `notice` so we will dispatch a .clear action. This
// should prevent us from getting in a stuck state where `NoticeStore` thinks its
Expand All @@ -145,16 +145,16 @@ class NoticePresenter: NSObject {

/// Present the `notice` in the UI (foreground) or as a push notification (background).
///
/// - Returns: A `NoticeArtifact` if the `notice` was presented, otherwise `nil`.
private func present(_ notice: Notice) -> NoticeArtifact? {
/// - Returns: A `NoticePresentation` if the `notice` was presented, otherwise `nil`.
private func present(_ notice: Notice) -> NoticePresentation? {
if UIApplication.shared.applicationState == .background {
return presentNoticeInBackground(notice)
} else {
return presentNoticeInForeground(notice)
}
}

private func presentNoticeInBackground(_ notice: Notice) -> NoticeArtifact? {
private func presentNoticeInBackground(_ notice: Notice) -> NoticePresentation? {
guard let notificationInfo = notice.notificationInfo else {
return nil
}
Expand All @@ -170,10 +170,10 @@ class NoticePresenter: NSObject {
}
})

return NoticeArtifact(notice: notice, containerView: nil)
return NoticePresentation(notice: notice, containerView: nil)
}

private func presentNoticeInForeground(_ notice: Notice) -> NoticeArtifact? {
private func presentNoticeInForeground(_ notice: Notice) -> NoticePresentation? {
generator.prepare()

let noticeView = NoticeView(notice: notice)
Expand Down Expand Up @@ -210,7 +210,7 @@ class NoticePresenter: NSObject {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Animations.dismissDelay, execute: dismiss)
})

return NoticeArtifact(notice: notice, containerView: noticeContainerView)
return NoticePresentation(notice: notice, containerView: noticeContainerView)
}

private func addNoticeContainerToPresentingViewController(_ noticeContainer: UIView) {
Expand All @@ -226,7 +226,7 @@ class NoticePresenter: NSObject {
// MARK: - Dismissal

private func dismissForegroundNotice() {
guard let container = currentNoticeArtifact?.containerView,
guard let container = currentNoticePresentation?.containerView,
container.superview != nil else {
return
}
Expand All @@ -236,7 +236,7 @@ class NoticePresenter: NSObject {

// It is possible that when the dismiss animation finished, another Notice was already
// being shown. Hiding the window would cause that new Notice to be invisible.
if self?.currentNoticeArtifact == nil {
if self?.currentNoticePresentation == nil {
self?.window.isHidden = true
}
})
Expand Down

0 comments on commit 64d0031

Please sign in to comment.