-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
MySiteViewController.swift
746 lines (598 loc) · 26.1 KB
/
MySiteViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
import WordPressAuthenticator
import UIKit
class MySiteViewController: UIViewController, NoResultsViewHost {
private enum Section: Int, CaseIterable {
case siteMenu
case dashboard
var title: String {
switch self {
case .siteMenu:
return NSLocalizedString("Site Menu", comment: "Title for the site menu view on the My Site screen")
case .dashboard:
return NSLocalizedString("Dashboard", comment: "Title for dashboard view on the My Site screen")
}
}
}
private var isShowingDashboard: Bool {
return segmentedControl.selectedSegmentIndex == Section.dashboard.rawValue
}
@objc
private(set) lazy var scrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.refreshControl = refreshControl
return scrollView
}()
private lazy var stackView: UIStackView = {
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.alignment = .fill
stackView.distribution = .fill
stackView.spacing = 0
return stackView
}()
private lazy var segmentedControlContainerView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private lazy var segmentedControl: UISegmentedControl = {
let segmentedControl = UISegmentedControl(items: Section.allCases.map { $0.title })
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
segmentedControl.addTarget(self, action: #selector(segmentedControlValueChanged(_:)), for: .valueChanged)
segmentedControl.selectedSegmentIndex = 0
return segmentedControl
}()
private lazy var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(pulledToRefresh), for: .valueChanged)
return refreshControl
}()
private let meScenePresenter: ScenePresenter
private let blogService: BlogService
// MARK: - Initializers
init(meScenePresenter: ScenePresenter, blogService: BlogService? = nil) {
self.meScenePresenter = meScenePresenter
self.blogService = blogService ?? BlogService(managedObjectContext: ContextManager.shared.mainContext)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("Initializer not implemented!")
}
deinit {
NotificationCenter.default.removeObserver(self)
}
// MARK: - Blog
/// Convenience setter and getter for the blog. This calculated property takes care of showing the appropriate VC, depending
/// on whether there's a blog to show or not.
///
var blog: Blog? {
set {
guard let newBlog = newValue else {
showBlogDetailsForMainBlogOrNoSites()
return
}
addSitePickerIfNeeded(for: newBlog)
showBlogDetails(for: newBlog)
updateSegmentedControl(for: newBlog)
}
get {
return sitePickerViewController?.blog
}
}
private(set) var sitePickerViewController: SitePickerViewController?
private(set) var blogDetailsViewController: BlogDetailsViewController?
private(set) var blogDashboardViewController: BlogDashboardViewController?
/// When we display a no results view, we'll do so in a scrollview so that
/// we can allow pull to refresh to sync the user's list of sites.
///
private var noResultsScrollView: UIScrollView?
private var noResultsRefreshControl: UIRefreshControl?
// MARK: - View Lifecycle
override func viewDidLoad() {
setupView()
setupConstraints()
setupNavigationItem()
subscribeToPostSignupNotifications()
subscribeToModelChanges()
subscribeToContentSizeCategory()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if blog == nil {
showBlogDetailsForMainBlogOrNoSites()
}
setupTransparentNavBar()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
setupOpaqueNavBar()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
workaroundLargeTitleCollapseBug()
if AppConfiguration.showsWhatIsNew {
WPTabBarController.sharedInstance()?.presentWhatIsNew(on: self)
}
FancyAlertViewController.presentCustomAppIconUpgradeAlertIfNecessary(from: self)
trackNoSitesVisibleIfNeeded()
setupTransparentNavBar()
}
private func subscribeToContentSizeCategory() {
NotificationCenter.default.addObserver(self,
selector: #selector(didChangeDynamicType),
name: UIContentSizeCategory.didChangeNotification,
object: nil)
}
private func subscribeToPostSignupNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(launchSiteCreationFromNotification), name: .createSite, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(showAddSelfHostedSite), name: .addSelfHosted, object: nil)
}
private func updateSegmentedControl(for blog: Blog) {
// The segmented control should be hidden if the blog is not a WP.com/Atomic/Jetpack site, or if the device is an iPad
segmentedControlContainerView.isHidden = !FeatureFlag.mySiteDashboard.enabled || !blog.isAccessibleThroughWPCom() || !splitViewControllerIsHorizontallyCompact
}
private func setupView() {
view.backgroundColor = .listBackground
configureSegmentedControlFont()
}
/// This method builds a layout with the following view hierarchy:
///
/// - Scroll view
/// - Stack view
/// - Segmented control container view
/// - Segmented control
/// - Child view controller
///
private func setupConstraints() {
view.addSubview(scrollView)
view.pinSubviewToAllEdges(scrollView)
scrollView.addSubview(stackView)
scrollView.pinSubviewToAllEdges(stackView)
segmentedControlContainerView.addSubview(segmentedControl)
stackView.addArrangedSubviews([segmentedControlContainerView])
NSLayoutConstraint.activate([
stackView.widthAnchor.constraint(equalTo: view.widthAnchor),
segmentedControl.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor,
constant: Constants.segmentedControlXOffset),
segmentedControl.centerXAnchor.constraint(equalTo: segmentedControlContainerView.centerXAnchor),
segmentedControl.topAnchor.constraint(equalTo: segmentedControlContainerView.topAnchor,
constant: Constants.segmentedControlYOffset),
segmentedControl.bottomAnchor.constraint(equalTo: segmentedControlContainerView.bottomAnchor)
])
}
// MARK: - Navigation Item
/// In iPad and iOS 14, the large-title bar is collapsed when the VC is first loaded. Call this method from
/// `viewDidAppear(_:)` to quickly refresh the navigation bar so that it's expanded.
///
private func workaroundLargeTitleCollapseBug() {
guard !splitViewControllerIsHorizontallyCompact else {
return
}
navigationController?.navigationBar.sizeToFit()
}
private func setupNavigationItem() {
navigationItem.largeTitleDisplayMode = .always
navigationItem.title = NSLocalizedString("My Site", comment: "Title of My Site tab")
// Workaround:
//
// Without the next line, the large title was being lost when going into a child VC with a small
// title and pressing "Back" in the navigation bar.
//
// I'm not sure if this makes sense - it doesn't to me right now, so I'm adding instructions to
// test the issue which will be helpful for removing the issue if the workaround is no longer
// needed.
//
// To see the issue in action, comment the line, run the App, go into "Stats" (or any other
// child VC that has a small title in the navigation bar), check that the title is small,
// press back, and check that this VC has a large title. If this VC still has a
// large title, you can remove the following line.
//
extendedLayoutIncludesOpaqueBars = true
// Set the nav bar
navigationController?.navigationBar.accessibilityIdentifier = "my-site-navigation-bar"
}
private func setupTransparentNavBar() {
navigationController?.navigationBar.scrollEdgeAppearance?.configureWithTransparentBackground()
}
private func setupOpaqueNavBar() {
navigationController?.navigationBar.scrollEdgeAppearance?.configureWithOpaqueBackground()
}
// MARK: - Account
private func defaultAccount() -> WPAccount? {
let context = ContextManager.sharedInstance().mainContext
let service = AccountService(managedObjectContext: context)
return service.defaultWordPressComAccount()
}
// MARK: - Main Blog
/// Convenience method to retrieve the main blog for an account when none is selected.
///
/// - Returns:the main blog for an account (last selected, or first blog in list).
///
private func mainBlog() -> Blog? {
return blogService.lastUsedOrFirstBlog()
}
/// This VC is prepared to either show the details for a blog, or show a no-results VC configured to let the user know they have no blogs.
/// There's no scenario where this is shown empty, for an account that HAS blogs.
///
/// In order to adhere to this logic, if this VC is shown without a blog being set, we will try to load the "main" blog (ie in order: the last used blog,
/// the account's primary blog, or the first blog we find for the account).
///
private func showBlogDetailsForMainBlogOrNoSites() {
guard let mainBlog = mainBlog() else {
showNoSites()
return
}
addSitePickerIfNeeded(for: mainBlog)
showBlogDetails(for: mainBlog)
updateSegmentedControl(for: mainBlog)
}
@objc
private func syncBlogs() {
guard let account = defaultAccount() else {
return
}
let finishSync = { [weak self] in
self?.noResultsRefreshControl?.endRefreshing()
}
blogService.syncBlogs(for: account) {
finishSync()
} failure: { (error) in
finishSync()
}
}
@objc
private func pulledToRefresh() {
blogDetailsViewController?.pulledToRefresh(with: refreshControl) { [weak self] in
guard let self = self else {
return
}
self.sitePickerViewController?.blogDetailHeaderView.blog = self.blog
}
}
// MARK: - Segmented Control
@objc private func segmentedControlValueChanged(_ sender: Any) {
guard let blog = blog,
let section = Section(rawValue: segmentedControl.selectedSegmentIndex) else {
return
}
switch section {
case .siteMenu:
hideDashboard()
showBlogDetails(for: blog)
case .dashboard:
hideBlogDetails()
showDashboard(for: blog)
}
}
// MARK: - Child VC logic
private func embedChildInStackView(_ child: UIViewController) {
addChild(child)
stackView.addArrangedSubview(child.view)
child.didMove(toParent: self)
}
// MARK: - No Sites UI logic
private func hideNoSites() {
// Only track if the no sites view is currently visible
if noResultsViewController.view.superview != nil {
WPAnalytics.track(.mySiteNoSitesViewHidden)
}
hideNoResults()
cleanupNoResultsView()
}
private func showNoSites() {
guard AccountHelper.isLoggedIn else {
WordPressAppDelegate.shared?.windowManager.showFullscreenSignIn()
return
}
hideBlogDetails()
blogDetailsViewController = nil
guard noResultsViewController.view.superview == nil else {
return
}
addMeButtonToNavigationBar(email: defaultAccount()?.email, meScenePresenter: meScenePresenter)
makeNoResultsScrollView()
configureNoResultsView()
addNoResultsViewAndConfigureConstraints()
}
private func trackNoSitesVisibleIfNeeded() {
guard noResultsViewController.view.superview != nil else {
return
}
WPAnalytics.track(.mySiteNoSitesViewDisplayed)
}
private func makeNoResultsScrollView() {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.backgroundColor = .basicBackground
view.addSubview(scrollView)
view.pinSubviewToAllEdges(scrollView)
let refreshControl = UIRefreshControl()
scrollView.refreshControl = refreshControl
refreshControl.addTarget(self, action: #selector(syncBlogs), for: .valueChanged)
noResultsRefreshControl = refreshControl
noResultsScrollView = scrollView
}
private func configureNoResultsView() {
noResultsViewController.configure(title: NSLocalizedString(
"Create a new site for your business, magazine, or personal blog; or connect an existing WordPress installation.",
comment: "Text shown when the account has no sites."),
buttonTitle: NSLocalizedString(
"Add new site",
comment: "Title of button to add a new site."),
image: "mysites-nosites")
noResultsViewController.actionButtonHandler = { [weak self] in
self?.presentInterfaceForAddingNewSite()
WPAnalytics.track(.mySiteNoSitesViewActionTapped)
}
}
private func addNoResultsViewAndConfigureConstraints() {
guard let scrollView = noResultsScrollView else {
return
}
addChild(noResultsViewController)
scrollView.addSubview(noResultsViewController.view)
noResultsViewController.view.frame = scrollView.frame
guard let nrv = noResultsViewController.view else {
return
}
nrv.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
nrv.widthAnchor.constraint(equalTo: view.widthAnchor),
nrv.centerXAnchor.constraint(equalTo: view.centerXAnchor),
nrv.topAnchor.constraint(equalTo: scrollView.topAnchor),
nrv.bottomAnchor.constraint(equalTo: view.safeBottomAnchor)
])
noResultsViewController.didMove(toParent: self)
}
private func cleanupNoResultsView() {
noResultsRefreshControl?.removeFromSuperview()
noResultsRefreshControl = nil
noResultsScrollView?.refreshControl = nil
noResultsScrollView?.removeFromSuperview()
noResultsScrollView = nil
}
// MARK: - Add Site Alert
@objc
func presentInterfaceForAddingNewSite() {
let canAddSelfHostedSite = AppConfiguration.showAddSelfHostedSiteButton
let addSite = {
self.launchSiteCreation(source: "my_site_no_sites")
}
guard canAddSelfHostedSite else {
addSite()
return
}
let addSiteAlert = AddSiteAlertFactory().makeAddSiteAlert(source: "my_site_no_sites",
canCreateWPComSite: defaultAccount() != nil,
createWPComSite: {
addSite()
}, canAddSelfHostedSite: canAddSelfHostedSite, addSelfHostedSite: {
WordPressAuthenticator.showLoginForSelfHostedSite(self)
})
if let sourceView = noResultsViewController.actionButton,
let popoverPresentationController = addSiteAlert.popoverPresentationController {
popoverPresentationController.sourceView = sourceView
popoverPresentationController.sourceRect = sourceView.bounds
popoverPresentationController.permittedArrowDirections = .up
}
present(addSiteAlert, animated: true)
}
@objc
func didChangeDynamicType() {
configureSegmentedControlFont()
}
private func configureSegmentedControlFont() {
let font = WPStyleGuide.fontForTextStyle(.subheadline)
segmentedControl.setTitleTextAttributes([NSAttributedString.Key.font: font], for: .normal)
}
@objc
func launchSiteCreationFromNotification() {
self.launchSiteCreation(source: "signup_epilogue")
}
func launchSiteCreation(source: String) {
let wizardLauncher = SiteCreationWizardLauncher()
guard let wizard = wizardLauncher.ui else {
return
}
present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])
}
@objc
private func showAddSelfHostedSite() {
WordPressAuthenticator.showLoginForSelfHostedSite(self)
}
// MARK: - Blog Details UI Logic
private func hideBlogDetails() {
guard let blogDetailsViewController = blogDetailsViewController else {
return
}
remove(blogDetailsViewController)
}
/// Shows the specified `BlogDetailsSubsection` for a `Blog`.
///
/// - Parameters:
/// - subsection: The specific subsection to show.
///
func showBlogDetailsSubsection(_ subsection: BlogDetailsSubsection) {
blogDetailsViewController?.showDetailView(for: subsection)
}
/// Shows a `BlogDetailsViewController` for the specified `Blog`. If the VC doesn't exist, this method also takes care
/// of creating it.
///
/// - Parameters:
/// - blog: The blog to show the details of.
///
private func showBlogDetails(for blog: Blog) {
hideNoSites()
let blogDetailsViewController = self.blogDetailsViewController(for: blog)
addMeButtonToNavigationBar(email: blog.account?.email, meScenePresenter: meScenePresenter)
embedChildInStackView(blogDetailsViewController)
blogDetailsViewController.showInitialDetailsForBlog()
}
private func blogDetailsViewController(for blog: Blog) -> BlogDetailsViewController {
guard let blogDetailsViewController = blogDetailsViewController else {
let blogDetailsViewController = makeBlogDetailsViewController(for: blog)
self.blogDetailsViewController = blogDetailsViewController
return blogDetailsViewController
}
blogDetailsViewController.switch(to: blog)
return blogDetailsViewController
}
private func makeBlogDetailsViewController(for blog: Blog) -> BlogDetailsViewController {
let blogDetailsViewController = BlogDetailsViewController(meScenePresenter: meScenePresenter)
blogDetailsViewController.blog = blog
return blogDetailsViewController
}
private func addSitePickerIfNeeded(for blog: Blog) {
guard sitePickerViewController == nil else {
return
}
let sitePickerViewController = makeSitePickerViewController(for: blog)
self.sitePickerViewController = sitePickerViewController
addChild(sitePickerViewController)
stackView.insertArrangedSubview(sitePickerViewController.view, at: 0)
sitePickerViewController.didMove(toParent: self)
}
private func makeSitePickerViewController(for blog: Blog) -> SitePickerViewController {
let sitePickerViewController = SitePickerViewController(blog: blog, meScenePresenter: meScenePresenter)
sitePickerViewController.onBlogSwitched = { [weak self] blog in
guard let self = self else {
return
}
if !blog.isAccessibleThroughWPCom() && self.isShowingDashboard {
self.segmentedControl.selectedSegmentIndex = Section.siteMenu.rawValue
self.segmentedControl.sendActions(for: .valueChanged)
}
self.updateSegmentedControl(for: blog)
self.updateChildViewController(for: blog)
}
return sitePickerViewController
}
private func updateChildViewController(for blog: Blog) {
guard let section = Section(rawValue: segmentedControl.selectedSegmentIndex) else {
return
}
switch section {
case .siteMenu:
blogDetailsViewController?.blog = blog
blogDetailsViewController?.showInitialDetailsForBlog()
blogDetailsViewController?.tableView.reloadData()
blogDetailsViewController?.preloadMetadata()
case .dashboard:
blogDashboardViewController?.update(blog: blog)
}
}
func presentCreateSheet() {
blogDetailsViewController?.createButtonCoordinator?.showCreateSheet()
}
// MARK: Dashboard UI Logic
private func hideDashboard() {
guard let blogDashboardViewController = blogDashboardViewController else {
return
}
remove(blogDashboardViewController)
}
/// Shows a `BlogDashboardViewController` for the specified `Blog`. If the VC doesn't exist, this method also takes care
/// of creating it.
///
/// - Parameters:
/// - blog: The blog to show the details of.
///
private func showDashboard(for blog: Blog) {
let blogDashboardViewController = self.blogDashboardViewController ?? BlogDashboardViewController(blog: blog)
embedChildInStackView(blogDashboardViewController)
self.blogDashboardViewController = blogDashboardViewController
}
// MARK: - Model Changes
private func subscribeToModelChanges() {
NotificationCenter.default.addObserver(
self,
selector: #selector(handleDataModelChange(notification:)),
name: .NSManagedObjectContextObjectsDidChange,
object: ContextManager.shared.mainContext)
}
@objc
private func handleDataModelChange(notification: NSNotification) {
if let blog = blog {
handlePossibleDeletion(of: blog, notification: notification)
} else {
handlePossiblePrimaryBlogCreation(notification: notification)
}
}
// MARK: - Model Changes: Blog Deletion
/// This method takes care of figuring out if the selected blog was deleted, and to address any side effect
/// of the selected blog being deleted.
///
private func handlePossibleDeletion(of selectedBlog: Blog, notification: NSNotification) {
guard let deletedObjects = notification.userInfo?[NSDeletedObjectsKey] as? Set<NSManagedObject>,
deletedObjects.contains(selectedBlog) else {
return
}
self.blog = nil
}
// MARK: - Model Changes: Blog Creation
/// This method ensures that the received notification includes inserted blogs.
/// It's useful because when we call `lastUsedOrFirstBlog()` a chain of calls that ends with:
///
/// `AccountService.defaultWordPressComAccount()`
/// > `AccountService.accountWithUUID()`
/// > `NSManagedObjectContext.executeFetchRequest(...)`.
///
/// The issue is that `executeFetchRequest` updates the managed object context, thus triggering
/// a `NSManagedObjectContextObjectsDidChange` notification, which caused a neverending
/// loop in the observer in this VC.
///
private func verifyThatBlogsWereInserted(in notification: NSNotification) -> Bool {
guard let insertedObjects = notification.userInfo?[NSInsertedObjectsKey] as? Set<NSManagedObject>,
insertedObjects.contains(where: { $0 as? Blog != nil }) else {
return false
}
return true
}
/// This method takes care of figuring out if a primary blog was created, in order to show the details for such
/// blog.
///
private func handlePossiblePrimaryBlogCreation(notification: NSNotification) {
// WORKAROUND: At first sight this guard should not be needed.
// Please read the documentation for this method carefully.
guard verifyThatBlogsWereInserted(in: notification) else {
return
}
guard let blog = blogService.lastUsedOrFirstBlog() else {
return
}
self.blog = blog
}
private enum Constants {
static let segmentedControlXOffset: CGFloat = 20
static let segmentedControlYOffset: CGFloat = 24
}
}
extension MySiteViewController: WPSplitViewControllerDetailProvider {
func initialDetailViewControllerForSplitView(_ splitView: WPSplitViewController) -> UIViewController? {
guard let blogDetailsViewController = blogDetailsViewController as? WPSplitViewControllerDetailProvider else {
let emptyViewController = UIViewController()
WPStyleGuide.configureColors(view: emptyViewController.view, tableView: nil)
return emptyViewController
}
return blogDetailsViewController.initialDetailViewControllerForSplitView(splitView)
}
}
// MARK: - My site detail views
extension MySiteViewController {
func showDetailView(for section: BlogDetailsSubsection) {
blogDetailsViewController?.showDetailView(for: section)
}
}
// MARK: - UIViewControllerTransitioningDelegate
//
extension MySiteViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
guard presented is FancyAlertViewController else {
return nil
}
return FancyAlertPresentationController(presentedViewController: presented, presenting: presenting)
}
}