Skip to content

Commit 5195282

Browse files
authored
Cherry-pick #19961 into hotfix 21.5.1 (#19972)
2 parents 0a5a6e9 + 7615115 commit 5195282

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

RELEASE-NOTES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
-----
33
* [*] Fix a layout issue impacting the "No media matching your search" empty state message of the Media Picker screen. [#19820]
44

5+
21.5.1
6+
-----
7+
* [*] [Jetpack-only] Fixed a bug where the Login flow was restarting every time the app enters the foreground. [#19961]
8+
59
21.5
610
-----
711
* [***] [internal] A significant refactor to the app’s architecture was made to allow for the new simplified UI. Regression testing on the app’s main flows is needed. [#19817]

WordPress/Classes/System/WindowManager.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class WindowManager: NSObject {
2121
///
2222
private(set) var isShowingFullscreenSignIn = false
2323

24+
/// The root view controller for the window.
25+
///
26+
var rootViewController: UIViewController? {
27+
return window.rootViewController
28+
}
29+
2430
init(window: UIWindow) {
2531
self.window = window
2632
}

WordPress/Jetpack/Classes/System/JetpackWindowManager.swift

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,41 @@ private extension JetpackWindowManager {
139139
!hasFailedExportAttempts,
140140
let schemeUrl = URL(string: "\(AppScheme.wordpressMigrationV1.rawValue)\(WordPressExportRoute().path.removingPrefix("/"))")
141141
else {
142-
showSignInUI()
142+
performSafeRootNavigation { [weak self] in
143+
self?.showSignInUI()
144+
}
143145
return
144146
}
145147

146148
/// WordPress is a compatible version for migrations, but needs to be loaded to prepare the data
147-
showLoadWordPressUI(schemeUrl: schemeUrl)
149+
performSafeRootNavigation { [weak self] in
150+
self?.showLoadWordPressUI(schemeUrl: schemeUrl)
151+
}
152+
}
153+
154+
/// This method takes care of preventing screens being abruptly replaced.
155+
///
156+
/// Since the import method is called whenever the app is foregrounded, we want to make sure that
157+
/// any root view controller replacements only happen where it is "allowed":
158+
///
159+
/// 1. When there's no root view controller yet, or
160+
/// 2. When the Load WordPress screen is shown.
161+
///
162+
/// Note: We should remove this method when the migration phase is concluded and we no longer need
163+
/// to perfom the migration.
164+
///
165+
/// - Parameter navigationClosure: The closure containing logic that eventually calls the `show` method.
166+
func performSafeRootNavigation(with navigationClosure: @escaping () -> Void) {
167+
switch rootViewController {
168+
case .none:
169+
// we can perform the navigation directly when there's no root view controller yet.
170+
navigationClosure()
171+
case .some(let viewController) where viewController is MigrationLoadWordPressViewController:
172+
// allow the Load WordPress view to be replaced in case the migration process fails.
173+
viewController.dismiss(animated: true, completion: navigationClosure)
174+
default:
175+
// do nothing when another root view controller is already displayed.
176+
break
177+
}
148178
}
149179
}

0 commit comments

Comments
 (0)