Skip to content

Commit e8b152c

Browse files
salimbraksamokagio
authored andcommitted
Jetpack Content Migration: Refactor "Open WordPress" screen to appear only when the app launches (#19961)
1 parent 0a5a6e9 commit e8b152c

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [*] [internal] Editor: Only register core blocks when `onlyCoreBlocks` capability is enabled [https://github.com/wordpress-mobile/gutenberg-mobile/pull/5293]
1010
* [**] [internal] Disable StockPhoto and Tenor media sources when Jetpack features are removed [#19826]
1111
* [*] [Jetpack-only] Fixed a bug where analytics calls weren't synced to the user account. [#19926]
12+
* [*] [Jetpack-only] Fixed a bug where the Login flow was restarting every time the app enters the foreground. [#19961]
1213

1314
21.4
1415
-----

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)