Skip to content

Commit 0e7705c

Browse files
Merge pull request #19817 from wordpress-mobile/task/19812-handle-simplified-ui
Jetpack Focus: Fix UI issues by removing the `WPTabBarController` dependency
2 parents 7b7fcb6 + 1775563 commit 0e7705c

File tree

59 files changed

+515
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+515
-366
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
21.5
22
-----
3+
* [***] [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]
34

45

56
21.4

WordPress/Classes/System/3DTouch/WP3DTouchShortcutHandler.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@ open class WP3DTouchShortcutHandler: NSObject {
2525
@objc static let applicationShortcutUserInfoIconKey = "applicationShortcutUserInfoIconKey"
2626

2727
@objc open func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
28-
let tabBarController: WPTabBarController = WPTabBarController.sharedInstance()
28+
let rootViewPresenter = RootViewCoordinator.sharedPresenter
2929

3030
switch shortcutItem.type {
3131
case ShortcutIdentifier.LogIn.type:
3232
WPAnalytics.track(.shortcutLogIn)
3333
return true
3434
case ShortcutIdentifier.NewPost.type:
3535
WPAnalytics.track(.shortcutNewPost)
36-
tabBarController.showPostTab(animated: false, toMedia: false)
36+
rootViewPresenter.showPostTab(animated: false, toMedia: false)
3737
return true
3838
case ShortcutIdentifier.NewPhotoPost.type:
3939
WPAnalytics.track(.shortcutNewPhotoPost)
40-
tabBarController.showPostTab(animated: false, toMedia: true)
40+
rootViewPresenter.showPostTab(animated: false, toMedia: true)
4141
return true
4242
case ShortcutIdentifier.Stats.type:
4343
WPAnalytics.track(.shortcutStats)
4444
clearCurrentViewController()
4545
if let mainBlog = Blog.lastUsedOrFirst(in: ContextManager.sharedInstance().mainContext) {
46-
tabBarController.mySitesCoordinator.showStats(for: mainBlog)
46+
rootViewPresenter.mySitesCoordinator.showStats(for: mainBlog)
4747
}
4848
return true
4949
case ShortcutIdentifier.Notifications.type:
5050
WPAnalytics.track(.shortcutNotifications)
5151
clearCurrentViewController()
52-
tabBarController.showNotificationsTab()
52+
rootViewPresenter.showNotificationsTab()
5353
return true
5454
default:
5555
return false

WordPress/Classes/System/MySitesCoordinator+RootViewPresenter.swift

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,132 @@ import Foundation
44
/// and the app's UI is simplified.
55
extension MySitesCoordinator: RootViewPresenter {
66

7+
// MARK: General
8+
9+
var currentViewController: UIViewController? {
10+
return rootViewController
11+
}
12+
13+
func getMeScenePresenter() -> ScenePresenter {
14+
meScenePresenter
15+
}
16+
17+
func currentlySelectedScreen() -> String {
18+
return "Blog List"
19+
}
20+
21+
func currentlyVisibleBlog() -> Blog? {
22+
currentBlog
23+
}
24+
25+
// MARK: Reader
26+
27+
var readerTabViewController: ReaderTabViewController? {
28+
fallbackBehavior()
29+
return nil
30+
}
31+
32+
var readerCoordinator: ReaderCoordinator? {
33+
fallbackBehavior()
34+
return nil
35+
}
36+
37+
var readerNavigationController: UINavigationController? {
38+
fallbackBehavior()
39+
return nil
40+
}
41+
42+
func showReaderTab() {
43+
fallbackBehavior()
44+
}
45+
46+
func switchToDiscover() {
47+
fallbackBehavior()
48+
}
49+
50+
func switchToSavedPosts() {
51+
fallbackBehavior()
52+
}
53+
54+
func resetReaderDiscoverNudgeFlow() {
55+
fallbackBehavior()
56+
}
57+
58+
func resetReaderTab() {
59+
fallbackBehavior()
60+
}
61+
62+
func navigateToReaderSearch() {
63+
fallbackBehavior()
64+
}
65+
66+
func switchToTopic(where predicate: (ReaderAbstractTopic) -> Bool) {
67+
fallbackBehavior()
68+
}
69+
70+
func switchToMyLikes() {
71+
fallbackBehavior()
72+
}
73+
74+
func switchToFollowedSites() {
75+
fallbackBehavior()
76+
}
77+
78+
func navigateToReaderSite(_ topic: ReaderSiteTopic) {
79+
fallbackBehavior()
80+
}
81+
82+
func navigateToReaderTag(_ topic: ReaderTagTopic) {
83+
fallbackBehavior()
84+
}
85+
86+
func navigateToReader(_ pushControlller: UIViewController?) {
87+
fallbackBehavior()
88+
}
89+
90+
func showReaderTab(forPost: NSNumber, onBlog: NSNumber) {
91+
fallbackBehavior()
92+
}
93+
94+
// MARK: My Site
95+
96+
var mySitesCoordinator: MySitesCoordinator {
97+
return self
98+
}
99+
100+
func showMySitesTab() {
101+
// Do nothing
102+
// Landing here means we're trying to show the My Sites, but it's already showing.
103+
}
104+
105+
// MARK: Notifications
106+
107+
var notificationsViewController: NotificationsViewController? {
108+
fallbackBehavior()
109+
return nil
110+
}
111+
112+
func showNotificationsTab() {
113+
fallbackBehavior()
114+
}
115+
116+
func switchNotificationsTabToNotificationSettings() {
117+
fallbackBehavior()
118+
}
119+
120+
func showNotificationsTabForNote(withID notificationID: String) {
121+
fallbackBehavior()
122+
}
123+
124+
func popNotificationsTabToRoot() {
125+
fallbackBehavior()
126+
}
127+
128+
// MARK: Helpers
129+
130+
/// Default implementation for functions that are not supported by the simplified UI.
131+
private func fallbackBehavior(callingFunction: String = #function) {
132+
let properties = ["calling_function": callingFunction]
133+
WPAnalytics.track(.jetpackFeatureIncorrectlyAccessed, properties: properties)
134+
}
7135
}

WordPress/Classes/System/RootViewControllerCoordinator.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Foundation
2+
3+
class RootViewCoordinator {
4+
5+
// MARK: Static shared variables
6+
7+
static let shared = RootViewCoordinator()
8+
static var sharedPresenter: RootViewPresenter {
9+
shared.rootViewPresenter
10+
}
11+
12+
// MARK: Public Variables
13+
14+
lazy var whatIsNewScenePresenter: ScenePresenter = {
15+
return makeWhatIsNewPresenter()
16+
}()
17+
18+
lazy var bloggingPromptCoordinator: BloggingPromptCoordinator = {
19+
return makeBloggingPromptCoordinator()
20+
}()
21+
22+
// MARK: Private instance variables
23+
24+
private(set) var rootViewPresenter: RootViewPresenter
25+
26+
// MARK: Initializer
27+
28+
init() {
29+
if JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled() {
30+
self.rootViewPresenter = WPTabBarController()
31+
}
32+
else {
33+
let meScenePresenter = MeScenePresenter()
34+
self.rootViewPresenter = MySitesCoordinator(meScenePresenter: meScenePresenter, onBecomeActiveTab: {})
35+
}
36+
updatePromptsIfNeeded()
37+
}
38+
}

WordPress/Classes/ViewRelated/System/WPTabBarController+ShowTab.swift renamed to WordPress/Classes/System/RootViewPresenter+EditorNavigation.swift

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
1-
extension WPTabBarController {
1+
import Foundation
22

3-
func showBlogDetails(for blog: Blog) {
4-
mySitesCoordinator.showBlogDetails(for: blog)
3+
extension RootViewPresenter {
4+
func currentOrLastBlog() -> Blog? {
5+
if let blog = currentlyVisibleBlog() {
6+
return blog
7+
}
8+
let context = ContextManager.shared.mainContext
9+
return Blog.lastUsedOrFirst(in: context)
10+
}
11+
12+
func showPostTab() {
13+
showPostTab(completion: nil)
14+
}
15+
16+
func showPostTab(completion afterDismiss: (() -> Void)?) {
17+
let context = ContextManager.shared.mainContext
18+
// Ignore taps on the post tab and instead show the modal.
19+
if Blog.count(in: context) == 0 {
20+
mySitesCoordinator.showAddNewSite()
21+
} else {
22+
showPostTab(animated: true, toMedia: false, completion: afterDismiss)
23+
}
24+
}
25+
26+
func showPostTab(for blog: Blog) {
27+
let context = ContextManager.shared.mainContext
28+
if Blog.count(in: context) == 0 {
29+
mySitesCoordinator.showAddNewSite()
30+
} else {
31+
showPostTab(animated: true, toMedia: false, blog: blog)
32+
}
33+
}
34+
35+
func showPostTab(animated: Bool,
36+
toMedia openToMedia: Bool,
37+
blog: Blog? = nil,
38+
completion afterDismiss: (() -> Void)? = nil) {
39+
if rootViewController.presentedViewController != nil {
40+
rootViewController.dismiss(animated: false)
41+
}
42+
43+
guard let blog = blog ?? currentOrLastBlog() else {
44+
return
45+
}
46+
47+
let editor = EditPostViewController(blog: blog)
48+
editor.modalPresentationStyle = .fullScreen
49+
editor.showImmediately = !animated
50+
editor.openWithMediaPicker = openToMedia
51+
editor.afterDismiss = afterDismiss
52+
53+
let properties = [WPAppAnalyticsKeyTapSource: "create_button", WPAppAnalyticsKeyPostType: "post"]
54+
WPAppAnalytics.track(.editorCreatedPost, withProperties: properties, with: blog)
55+
rootViewController.present(editor, animated: false)
556
}
657

7-
@objc func showPageEditor(forBlog: Blog? = nil) {
58+
func showPageEditor(forBlog: Blog? = nil) {
859
showPageEditor(blog: forBlog)
960
}
1061

11-
@objc func showStoryEditor(forBlog: Blog? = nil) {
62+
func showStoryEditor(forBlog: Blog? = nil) {
1263
showStoryEditor(blog: forBlog)
1364
}
1465

@@ -17,8 +68,8 @@ extension WPTabBarController {
1768
func showPageEditor(blog inBlog: Blog? = nil, title: String? = nil, content: String? = nil, source: String = "create_button") {
1869

1970
// If we are already showing a view controller, dismiss and show the editor afterward
20-
guard presentedViewController == nil else {
21-
dismiss(animated: true) { [weak self] in
71+
guard rootViewController.presentedViewController == nil else {
72+
rootViewController.dismiss(animated: true) { [weak self] in
2273
self?.showPageEditor(blog: inBlog, title: title, content: content, source: source)
2374
}
2475
return
@@ -32,22 +83,22 @@ extension WPTabBarController {
3283
let blogID = blog.dotComID?.intValue ?? 0 as Any
3384
WPAnalytics.track(WPAnalyticsEvent.editorCreatedPage, properties: [WPAppAnalyticsKeyTapSource: source, WPAppAnalyticsKeyBlogID: blogID, WPAppAnalyticsKeyPostType: "page"])
3485

35-
PageCoordinator.showLayoutPickerIfNeeded(from: self, forBlog: blog) { [weak self] (selectedLayout) in
86+
PageCoordinator.showLayoutPickerIfNeeded(from: rootViewController, forBlog: blog) { [weak self] (selectedLayout) in
3687
self?.showEditor(blog: blog, title: selectedLayout?.title, content: selectedLayout?.content, templateKey: selectedLayout?.slug)
3788
}
3889
}
3990

4091
private func showEditor(blog: Blog, title: String?, content: String?, templateKey: String?) {
4192
let editorViewController = EditPageViewController(blog: blog, postTitle: title, content: content, appliedTemplate: templateKey)
42-
present(editorViewController, animated: false)
93+
rootViewController.present(editorViewController, animated: false)
4394
}
4495

4596
/// Show the story editor
4697
/// - Parameter blog: Blog to a add a story to. Uses the current or last blog if not provided
4798
func showStoryEditor(blog inBlog: Blog? = nil, title: String? = nil, content: String? = nil, source: String = "create_button") {
4899
// If we are already showing a view controller, dismiss and show the editor afterward
49-
guard presentedViewController == nil else {
50-
dismiss(animated: true) { [weak self] in
100+
guard rootViewController.presentedViewController == nil else {
101+
rootViewController.dismiss(animated: true) { [weak self] in
51102
self?.showStoryEditor(blog: inBlog, title: title, content: content, source: source)
52103
}
53104
return
@@ -61,10 +112,10 @@ extension WPTabBarController {
61112
}, openURL: { [weak self] url in
62113
let webViewController = WebViewControllerFactory.controller(url: url, source: "show_story_example")
63114
let navController = UINavigationController(rootViewController: webViewController)
64-
self?.presentedViewController?.present(navController, animated: true)
115+
self?.rootViewController.presentedViewController?.present(navController, animated: true)
65116
})
66117

67-
present(intro, animated: true, completion: {
118+
rootViewController.present(intro, animated: true, completion: {
68119
StoriesIntroViewController.trackShown()
69120
})
70121
} else {
@@ -75,7 +126,7 @@ extension WPTabBarController {
75126

76127
do {
77128
let controller = try StoryEditor.editor(blog: blog, context: ContextManager.shared.mainContext, updated: {_ in })
78-
present(controller, animated: true, completion: nil)
129+
rootViewController.present(controller, animated: true, completion: nil)
79130
} catch {
80131
assertionFailure("Story editor should not fail since this button is hidden on iPads.")
81132
}

0 commit comments

Comments
 (0)