Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion WordPress/Classes/System/Root View/ReaderPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {

// TODO: (reader) update to allow seamless transitions between split view and tabs
@objc func prepareForTabBarPresentation() -> UINavigationController {
guard AccountHelper.isDotcomAvailable() else {
return UINavigationController(rootViewController: ReaderLoggedOutViewController())
}

sidebar.onViewDidLoad = { [weak self] in
self?.showInitialSelection()
}

sidebarViewModel.isCompact = true
sidebarViewModel.restoreSelection(defaultValue: nil)
mainNavigationController = UINavigationController(rootViewController: sidebar) // Loads sidebar lazily
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ extension WordPressAppDelegate {
ReaderTopicService(coreDataStack: ContextManager.shared).clearInUseFlags()
ReaderPostService(coreDataStack: ContextManager.shared).clearSavedPostFlags()
ReaderSearchSuggestionService(coreDataStack: ContextManager.sharedInstance()).deleteAllSuggestions()
UserDefaults.standard.readerSidebarSelection = nil
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import UIKit
import SwiftUI
import WordPressUI

final class ReaderLoggedOutViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .systemBackground

let stateView = UIHostingView(view: EmptyStateView {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not using UIHostingViewController, which may require less set up code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason is this:

Button(Strings.signIn) { [weak self] in
    self?.buttonSignInTapped()
}.buttonStyle(.primary)

Task {
            await WordPressDotComAuthenticator().signIn(from: self, context: .default)
        }

I needed a reference to the containing UIViewController to have something I could start the login from. There are other ways to workaround this, but I found this to be the least worst.

Label(Strings.title, systemImage: "person.crop.circle.badge.plus")
} description: {
Text(Strings.details)
} actions: {
Button(Strings.signIn) { [weak self] in
self?.buttonSignInTapped()
}.buttonStyle(.primary)
})

view.addSubview(stateView)
stateView.pinEdges()
}

private func buttonSignInTapped() {
Task {
await WordPressDotComAuthenticator().signIn(from: self, context: .default)
}
}
}

private enum Strings {
static let title = NSLocalizedString("reader.loggedOut.title", value: "Join the conversation", comment: "Reader logged-out screen title")
static let details = NSLocalizedString("reader.loggedOut.details", value: "Sign in with a WordPress.com account to follow your favorite blogs", comment: "Reader logged-out screen details")
static let signIn = NSLocalizedString("reader.loggedOut.signIn", value: "Sign In", comment: "Reader logged-out screen sign in button")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ extension ReaderStreamViewController {
// Convenience type for Reader's headers
typealias ReaderHeader = UIView & ReaderStreamHeader

func headerForStream(_ topic: ReaderAbstractTopic?, isLoggedIn: Bool, container: UITableViewController) -> UIView? {
func headerForStream(_ topic: ReaderAbstractTopic?, container: UITableViewController) -> UIView? {
if let topic, ReaderHelpers.topicIsFollowing(topic) {
return ReaderHeaderView.makeForFollowing()
}
if let topic,
let header = headerForStream(topic) {
configure(header, topic: topic, isLoggedIn: isLoggedIn, delegate: self)
configure(header, topic: topic, delegate: self)
return header
}
return nil
}

func configure(_ header: ReaderHeader?, topic: ReaderAbstractTopic, isLoggedIn: Bool, delegate: ReaderStreamHeaderDelegate) {
func configure(_ header: ReaderHeader?, topic: ReaderAbstractTopic, delegate: ReaderStreamHeaderDelegate) {
header?.configureHeader(topic)
header?.enableLoggedInFeatures(isLoggedIn)
header?.delegate = delegate
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import AutomatticTracks
private let recentlyBlockedSitePostObjectIDs = NSMutableArray()
private let heightForFooterView = CGFloat(34.0)
private let estimatedHeightsCache = NSCache<AnyObject, AnyObject>()
private var isLoggedIn = false
private var isFeed = false
private var syncIsFillingGap = false
private var indexPathForGapMarker: IndexPath?
Expand Down Expand Up @@ -464,7 +463,7 @@ import AutomatticTracks
guard !isEmbeddedInDiscover else {
return
}
guard let headerView = headerForStream(readerTopic, isLoggedIn: isLoggedIn, container: tableViewController) else {
guard let headerView = headerForStream(readerTopic, container: tableViewController) else {
tableView.tableHeaderView = nil
return
}
Expand Down Expand Up @@ -518,9 +517,6 @@ import AutomatticTracks
tableViewController.refreshControl = nil
}

// Rather than repeatedly creating a service to check if the user is logged in, cache it here.
isLoggedIn = AccountHelper.isDotcomAvailable()

configureTitleForTopic()
configureShareButtonIfNeeded()
hideResultsStatus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,4 @@ import WordPressShared
titleLabel.text = topic.title
detailLabel.text = listTopic.owner
}

@objc open func enableLoggedInFeatures(_ enable: Bool) {
// noop
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class ReaderSiteHeaderView: UITableViewHeaderFooterView, ReaderStreamHeader {
fatalError("init(coder:) has not been implemented")
}

func enableLoggedInFeatures(_ enable: Bool) {
headerViewModel.isFollowHidden = !enable
}

func configureHeader(_ topic: ReaderAbstractTopic) {
guard let siteTopic = topic as? ReaderSiteTopic else {
assertionFailure("This header should only be used for site topics.")
Expand Down Expand Up @@ -96,12 +92,10 @@ struct ReaderSiteHeader: View {
if viewModel.site?.isExternal == false {
countsDisplay
}
if !viewModel.isFollowHidden {
ReaderFollowButton(isFollowing: viewModel.isFollowingSite,
isEnabled: viewModel.isFollowEnabled,
size: .regular) {
viewModel.updateFollowStatus()
}
ReaderFollowButton(isFollowing: viewModel.isFollowingSite,
isEnabled: viewModel.isFollowEnabled,
size: .regular) {
viewModel.updateFollowStatus()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
Expand Down Expand Up @@ -145,7 +139,6 @@ class ReaderSiteHeaderViewModel: ObservableObject {
@Published var postCount: String
@Published var followerCount: String
@Published var isFollowingSite: Bool
@Published var isFollowHidden: Bool
@Published var isFollowEnabled: Bool

private let onFollowTap: (_ completion: @escaping () -> Void) -> Void
Expand All @@ -156,7 +149,6 @@ class ReaderSiteHeaderViewModel: ObservableObject {
postCount: String = "",
followerCount: String = "",
isFollowingSite: Bool = false,
isFollowHidden: Bool = false,
isFollowEnabled: Bool = true,
onFollowTap: @escaping (_ completion: @escaping () -> Void) -> Void = { _ in }) {
self.title = title
Expand All @@ -165,7 +157,6 @@ class ReaderSiteHeaderViewModel: ObservableObject {
self.postCount = postCount
self.followerCount = followerCount
self.isFollowingSite = isFollowingSite
self.isFollowHidden = isFollowHidden
self.isFollowEnabled = isFollowEnabled
self.onFollowTap = onFollowTap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ import Foundation

@objc public protocol ReaderStreamHeader {
weak var delegate: ReaderStreamHeaderDelegate? {get set}
func enableLoggedInFeatures(_ enable: Bool)
func configureHeader(_ topic: ReaderAbstractTopic)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ import WordPressShared
WPStyleGuide.applyTagsReaderButtonStyle(followButton)
}

@objc open func enableLoggedInFeatures(_ enable: Bool) {

}

fileprivate func adjustInsetsForTextDirection() {
followButton.flipInsetsForRightToLeftLayoutDirection()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ private struct ReaderSidebarSection<Content: View>: View {
Image(systemName: isExpanded ? "chevron.down" : "chevron.right")
.font(.system(size: 14).weight(.semibold))
.foregroundStyle(AppColor.brand)
.frame(width: 14)
}
.contentShape(Rectangle())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,32 @@ private struct SidebarView: View {
@ViewBuilder
private var more: some View {
#if IS_JETPACK
Label {
Text(Strings.notifications)
} icon: {
if notificationsButtonViewModel.counter > 0 {
Image(systemName: "bell.badge")
.foregroundStyle(.red, Color(UIAppColor.brand))
} else {
Image(systemName: "bell")
if AccountHelper.isDotcomAvailable() {
Label {
Text(Strings.notifications)
} icon: {
if notificationsButtonViewModel.counter > 0 {
Image(systemName: "bell.badge")
.foregroundStyle(.red, Color(UIAppColor.brand))
} else {
Image(systemName: "bell")
}
}
}
.accessibilityIdentifier("sidebar_notifications")
.tag(SidebarSelection.notifications)
.accessibilityIdentifier("sidebar_notifications")
.tag(SidebarSelection.notifications)

Label(Strings.reader, systemImage: "eyeglasses")
.tag(SidebarSelection.reader)
.accessibilityIdentifier("sidebar_reader")
Label(Strings.reader, systemImage: "eyeglasses")
.tag(SidebarSelection.reader)
.accessibilityIdentifier("sidebar_reader")

if RemoteFeatureFlag.domainManagement.enabled() {
Button(action: { viewModel.navigate(.domains) }) {
Label(Strings.domains, systemImage: "network")
if RemoteFeatureFlag.domainManagement.enabled() {
Button(action: { viewModel.navigate(.domains) }) {
Label(Strings.domains, systemImage: "network")
}
.accessibilityIdentifier("sidebar_domains")
}
.accessibilityIdentifier("sidebar_domains")
}

Button(action: { viewModel.navigate(.help) }) {
Label(Strings.help, systemImage: "questionmark.circle")
}
Expand Down