Skip to content

Commit cccc232

Browse files
committed
7540 Display maximum one notice at a time
Previously, the PermanentNoticePresenter would display a new notice every time `presentNotice` was called, losing it’s reference to any existing notice, but leaving it in the view hierarchy. This meant that in the In-Person Payments onboarding flow, the “Continue Setup” notice would be displayed once for every failure that was shown, and only the top one removed by `dismiss` when the `.completed` step was reached. This change makes `presentNotice` do nothing if a notice is already presented, so in the In-Person Payments scenario, there will only ever be one presented and dismissed. The PermanentNoticePresenter is not currently used elsewhere.
1 parent f471bbf commit cccc232

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

WooCommerce/Classes/Tools/Notices/PermanentNotice/PermanentNoticePresenter.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ final class PermanentNoticePresenter {
1717
private var hostingController: UIHostingController<PermanentNoticeView>?
1818

1919
/// Presents the given notice into the passed view controller with an animation
20+
/// This will ignore any calls to present if a notice is already displayed
2021
///
2122
func presentNotice(notice: PermanentNotice, from viewController: UIViewController) {
23+
guard hostingController == nil else {
24+
return
25+
}
26+
2227
let permanentNoticeView = PermanentNoticeView(notice: notice)
2328
let newHostingController = ConstraintsUpdatingHostingController(rootView: permanentNoticeView)
2429

@@ -76,12 +81,14 @@ private extension PermanentNoticePresenter {
7681

7782
UIView.animate(withDuration: Animations.appearanceDuration,
7883
delay: 0,
79-
options: .transitionFlipFromLeft, animations: {
84+
options: .transitionFlipFromLeft,
85+
animations: {
8086
hostingController.view.alpha = 0
81-
}) { _ in
82-
hostingController.willMove(toParent: nil)
83-
hostingController.view.removeFromSuperview()
84-
}
87+
}) { [weak self] _ in
88+
hostingController.willMove(toParent: nil)
89+
hostingController.view.removeFromSuperview()
90+
self?.hostingController = nil
91+
}
8592
}
8693
}
8794

0 commit comments

Comments
 (0)