Skip to content

Commit 5d8c5ba

Browse files
authored
Merge pull request #8263 from woocommerce/issue/8224-order-completed-toast-goes-up
Fix Notice View when navigating to a view without tab bar
2 parents e4fae92 + 58da1fd commit 5d8c5ba

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class DefaultNoticePresenter: NoticePresenter {
2020
///
2121
private var noticeOnScreen: Notice?
2222

23+
var kvoToken: NSKeyValueObservation?
24+
2325
/// UIViewController to be used as Notice(s) Presenter
2426
///
2527
weak var presentingViewController: UIViewController?
@@ -191,6 +193,7 @@ private extension DefaultNoticePresenter {
191193
func dismiss() {
192194
noticeOnScreen = nil
193195
keyboardFrameObserver = nil
196+
kvoToken = nil
194197
presentNextNoticeIfPossible()
195198
}
196199

@@ -207,7 +210,20 @@ private extension DefaultNoticePresenter {
207210
fatalError("NoticePresenter requires a presentingViewController!")
208211
}
209212

210-
if let tabBarController = presentingViewController as? UITabBarController {
213+
if let tabBarController = presentingViewController as? UITabBarController,
214+
!tabBarController.tabBar.isHidden {
215+
if kvoToken == nil {
216+
kvoToken = tabBarController.tabBar.observe(\.isHidden, options: .new) { tabBar, _ in
217+
guard tabBar.isHidden else {
218+
return
219+
}
220+
221+
// If the tab bar hides we also hide the notice, as trying to rearrange the notice accordingly might bring unexpected results
222+
// due to the internal logic of UITabBarController e.g they remove/recreate the tab bar when navigation happens
223+
container.isHidden = true
224+
}
225+
}
226+
211227
return container.bottomAnchor.constraint(equalTo: tabBarController.tabBar.topAnchor)
212228
}
213229

0 commit comments

Comments
 (0)