Skip to content

Commit

Permalink
Merge pull request #21771 from wordpress-mobile/issue/21761-reader-im…
Browse files Browse the repository at this point in the history
…provements-remote-flag

Reader: Update `readerImprovements` flag to be remote
  • Loading branch information
wargcm authored Oct 14, 2023
2 parents c284461 + 58e56b8 commit 222d738
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 50 deletions.
5 changes: 0 additions & 5 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum FeatureFlag: Int, CaseIterable {
case commentModerationUpdate
case compliancePopover
case domainFocus
case readerImprovements // pcdRpT-3Eb-p2
case mediaModernization

/// Returns a boolean indicating if the feature is enabled
Expand Down Expand Up @@ -42,8 +41,6 @@ enum FeatureFlag: Int, CaseIterable {
return true
case .domainFocus:
return true
case .readerImprovements:
return false
case .mediaModernization:
return false
}
Expand Down Expand Up @@ -88,8 +85,6 @@ extension FeatureFlag {
return "Compliance Popover"
case .domainFocus:
return "Domain Focus"
case .readerImprovements:
return "Reader Improvements v1"
case .mediaModernization:
return "Media Modernization"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum RemoteFeatureFlag: Int, CaseIterable {
case jetpackSocialImprovements
case domainManagement
case plansInSiteCreation
case readerImprovements // pcdRpT-3Eb-p2

var defaultValue: Bool {
switch self {
Expand Down Expand Up @@ -62,6 +63,8 @@ enum RemoteFeatureFlag: Int, CaseIterable {
return false
case .plansInSiteCreation:
return false
case .readerImprovements:
return false
}
}

Expand Down Expand Up @@ -106,6 +109,8 @@ enum RemoteFeatureFlag: Int, CaseIterable {
return "domain_management"
case .plansInSiteCreation:
return "plans_in_site_creation"
case .readerImprovements:
return "reader_improvements"
}
}

Expand Down Expand Up @@ -149,6 +154,8 @@ enum RemoteFeatureFlag: Int, CaseIterable {
return "Domain Management"
case .plansInSiteCreation:
return "Plans in Site Creation"
case .readerImprovements:
return "Reader Improvements v1"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

/// The actual header
private lazy var header: UIView & ReaderDetailHeader = {
guard FeatureFlag.readerImprovements.enabled else {
guard RemoteFeatureFlag.readerImprovements.enabled() else {
return ReaderDetailHeaderView.loadFromNib()
}
return ReaderDetailNewHeaderViewHost()
Expand Down Expand Up @@ -533,7 +533,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

/// Configure the webview
private func configureWebView() {
webView.usesSansSerifStyle = FeatureFlag.readerImprovements.enabled
webView.usesSansSerifStyle = RemoteFeatureFlag.readerImprovements.enabled()
webView.navigationDelegate = self
}

Expand Down Expand Up @@ -606,7 +606,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

headerContainerView.pinSubviewToAllEdges(header)

if !FeatureFlag.readerImprovements.enabled {
if !RemoteFeatureFlag.readerImprovements.enabled() {
headerContainerView.heightAnchor.constraint(equalTo: header.heightAnchor).isActive = true
}
}
Expand Down Expand Up @@ -677,7 +677,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
toolbarContainerView.pinSubviewToAllEdges(toolbar)
toolbarSafeAreaView.backgroundColor = toolbar.backgroundColor

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
toolbarHeightConstraint.constant = Constants.preferredToolbarHeight
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ReaderDetailToolbar: UIView, NibLoadable {

private var likeButtonTitle: String {
guard let post,
FeatureFlag.readerImprovements.enabled else {
RemoteFeatureFlag.readerImprovements.enabled() else {
return likeLabel(count: likeCount)
}
return post.isLiked ? Constants.likedButtonTitle : Constants.likeButtonTitle
Expand Down Expand Up @@ -163,7 +163,7 @@ class ReaderDetailToolbar: UIView, NibLoadable {
WPStyleGuide.applyReaderCardActionButtonStyle(likeButton)

// TODO: Apply changes on the XIB directly once the `readerImprovements` flag is removed.
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
stackView.distribution = .fillEqually
stackView.spacing = 16.0
stackViewLeadingConstraint.constant = 16.0
Expand Down Expand Up @@ -226,7 +226,7 @@ class ReaderDetailToolbar: UIView, NibLoadable {
/// `imagePlacement` to `.top`.
///
/// TODO: remove unused styles once the `readerImprovements` flag is removed.
guard FeatureFlag.readerImprovements.enabled else {
guard RemoteFeatureFlag.readerImprovements.enabled() else {
return
}

Expand Down Expand Up @@ -298,7 +298,7 @@ class ReaderDetailToolbar: UIView, NibLoadable {
let animationDuration = 0.3
let imageView = UIImageView(image: Constants.likedImage)

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
/// When using `UIButton.Configuration`, calling `bringSubviewToFront` somehow does not work.
/// To work around this, let's add the faux image to the image view instead, so it can be
/// properly placed in front of the masking view.
Expand All @@ -317,7 +317,7 @@ class ReaderDetailToolbar: UIView, NibLoadable {
likeImageView.pinSubviewToAllEdges(mask)
mask.translatesAutoresizingMaskIntoConstraints = false

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
likeImageView.bringSubviewToFront(imageView)
} else {
likeButton.bringSubviewToFront(imageView)
Expand Down Expand Up @@ -426,8 +426,8 @@ class ReaderDetailToolbar: UIView, NibLoadable {
}

let commentCount = post.commentCount()?.intValue ?? 0
let commentTitle = FeatureFlag.readerImprovements.enabled ? Constants.commentButtonTitle : commentLabel(count: commentCount)
let showTitle: Bool = FeatureFlag.readerImprovements.enabled || traitCollection.horizontalSizeClass != .compact
let commentTitle = RemoteFeatureFlag.readerImprovements.enabled() ? Constants.commentButtonTitle : commentLabel(count: commentCount)
let showTitle: Bool = RemoteFeatureFlag.readerImprovements.enabled() || traitCollection.horizontalSizeClass != .compact

likeButton.setTitle(likeButtonTitle, for: .normal)
likeButton.setTitle(likeButtonTitle, for: .highlighted)
Expand Down Expand Up @@ -496,7 +496,7 @@ private extension ReaderDetailToolbar {
static let buttonImagePadding: CGFloat = 4.0

static var likeImage: UIImage? {
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
// reduce gridicon images to 20x20 since they don't have intrinsic padding.
return UIImage(named: "icon-reader-like")?
.resizedImage(WPStyleGuide.Detail.actionBarIconSize, interpolationQuality: .default)
Expand All @@ -506,7 +506,7 @@ private extension ReaderDetailToolbar {
}

static var likedImage: UIImage? {
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
// reduce gridicon images to 20x20 since they don't have intrinsic padding.
return UIImage(named: "icon-reader-liked")?
.resizedImage(WPStyleGuide.Detail.actionBarIconSize, interpolationQuality: .default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private extension ReaderCrossPostCell {
// MARK: - Appearance

func applyStyles() {
let readerImprovements = FeatureFlag.readerImprovements.enabled
let readerImprovements = RemoteFeatureFlag.readerImprovements.enabled()
backgroundColor = .clear
contentView.backgroundColor = readerImprovements ? .systemBackground : .listBackground
borderView?.backgroundColor = readerImprovements ? .systemBackground : .listForeground
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class ReaderFollowedSitesViewController: UIViewController, UIViewControllerResto
}

private func followButton(title: String) -> UIButton {
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
let button = UIButton()
button.isSelected = true
WPStyleGuide.applyReaderFollowButtonStyle(button)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ReaderRecommendedSiteCardCell: UITableViewCell {
weak var delegate: ReaderRecommendedSitesCardCellDelegate?

private var readerImprovements: Bool {
FeatureFlag.readerImprovements.enabled
RemoteFeatureFlag.readerImprovements.enabled()
}

override func awakeFromNib() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class ReaderShowMenuAction {
}

// Save post
if FeatureFlag.readerImprovements.enabled, let vc = vc as? ReaderStreamViewController {
if RemoteFeatureFlag.readerImprovements.enabled(), let vc = vc as? ReaderStreamViewController {
let buttonTitle = post.isSavedForLater ? ReaderPostMenuButtonTitles.removeSavedPost: ReaderPostMenuButtonTitles.savePost

alertController.addActionWithTitle(buttonTitle, style: .default) { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extension ReaderStreamViewController {
return nil
}

return FeatureFlag.readerImprovements.enabled ? nibViews.last : nibViews.first
return RemoteFeatureFlag.readerImprovements.enabled() ? nibViews.last : nibViews.first
}

if ReaderHelpers.isTopicList(topic) {
return Bundle.main.loadNibNamed("ReaderListStreamHeader", owner: nil, options: nil)?.first as? ReaderListStreamHeader
}

if ReaderHelpers.isTopicSite(topic) && !isContentFiltered {
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
return ReaderSiteHeaderView()
} else {
return Bundle.main.loadNibNamed("ReaderSiteStreamHeader", owner: nil, options: nil)?.first as? ReaderSiteStreamHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ import Combine
return
}

let isNewSiteHeader = ReaderHelpers.isTopicSite(topic) && !isContentFiltered && FeatureFlag.readerImprovements.enabled
let isNewSiteHeader = ReaderHelpers.isTopicSite(topic) && !isContentFiltered && RemoteFeatureFlag.readerImprovements.enabled()
let headerView = {
guard isNewSiteHeader else {
return header
Expand Down Expand Up @@ -719,11 +719,11 @@ import Combine

if ReaderHelpers.isTopicTag(topic) {
// don't display any title for the tag stream for the new design.
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
return
}
title = NSLocalizedString("Topic", comment: "Topic page title")
} else if FeatureFlag.readerImprovements.enabled && ReaderHelpers.topicType(topic) == .site {
} else if RemoteFeatureFlag.readerImprovements.enabled() && ReaderHelpers.topicType(topic) == .site {
title = ""
} else {
title = topic.title
Expand Down Expand Up @@ -1651,7 +1651,7 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate {
return cell
}

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
let cell = tableConfiguration.postCardCell(tableView)
let viewModel = ReaderPostCardCellViewModel(contentProvider: post,
isLoggedIn: isLoggedIn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ReaderTopicsTableCardCell: UITableViewCell {
weak var delegate: ReaderTopicsTableCardCellDelegate?

private var readerImprovements: Bool {
FeatureFlag.readerImprovements.enabled
RemoteFeatureFlag.readerImprovements.enabled()
}

// Subclasses should configure these properties
Expand Down Expand Up @@ -144,7 +144,7 @@ extension ReaderTopicsTableCardCell: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return FeatureFlag.readerImprovements.enabled ? 16 : 0
return RemoteFeatureFlag.readerImprovements.enabled() ? 16 : 0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class ReaderTableConfiguration {
}

func estimatedRowHeight() -> CGFloat {
return FeatureFlag.readerImprovements.enabled ? rowHeight : oldRowHeight
return RemoteFeatureFlag.readerImprovements.enabled() ? rowHeight : oldRowHeight
}

func crossPostCell(_ tableView: UITableView) -> ReaderCrossPostCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import WordPressShared
}

@objc func applyStyles() {
WPStyleGuide.applyReaderStreamHeaderTitleStyle(titleLabel, usesNewStyle: FeatureFlag.readerImprovements.enabled)
WPStyleGuide.applyReaderStreamHeaderTitleStyle(titleLabel, usesNewStyle: RemoteFeatureFlag.readerImprovements.enabled())
}

open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
Expand All @@ -32,7 +32,7 @@ import WordPressShared

@objc open func configureHeader(_ topic: ReaderAbstractTopic) {
titleLabel.text = {
guard FeatureFlag.readerImprovements.enabled else {
guard RemoteFeatureFlag.readerImprovements.enabled() else {
return topic.title
}
return topic.title.split(separator: "-").map { $0.capitalized }.joined(separator: " ")
Expand Down
12 changes: 6 additions & 6 deletions WordPress/Classes/ViewRelated/Reader/ReaderTopicsCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ReaderTopicsCardCell: UITableViewCell, NibLoadable {
weak var delegate: ReaderTopicsTableCardCellDelegate?

static var defaultNibName: String {
FeatureFlag.readerImprovements.enabled ? "ReaderTopicsNewCardCell" : String(describing: self)
RemoteFeatureFlag.readerImprovements.enabled() ? "ReaderTopicsNewCardCell" : String(describing: self)
}

func configure(_ data: [ReaderAbstractTopic]) {
Expand All @@ -44,13 +44,13 @@ class ReaderTopicsCardCell: UITableViewCell, NibLoadable {
collectionView.register(ReaderTopicCardCollectionViewCell.self,
forCellWithReuseIdentifier: ReaderTopicCardCollectionViewCell.cellReuseIdentifier())

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
configureForNewDesign()
}
}

private func applyStyles() {
let usesNewDesign = FeatureFlag.readerImprovements.enabled
let usesNewDesign = RemoteFeatureFlag.readerImprovements.enabled()
headerLabel.font = usesNewDesign ? WPStyleGuide.fontForTextStyle(.footnote) : WPStyleGuide.serifFontForTextStyle(.title2)

containerView.backgroundColor = usesNewDesign ? .secondarySystemBackground : .listForeground
Expand Down Expand Up @@ -110,7 +110,7 @@ class ReaderTopicsCardCell: UITableViewCell, NibLoadable {
extension ReaderTopicsCardCell: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ReaderTopicCardCollectionViewCell.cellReuseIdentifier(), for: indexPath) as? ReaderTopicCardCollectionViewCell else {
return UICollectionViewCell()
}
Expand Down Expand Up @@ -182,15 +182,15 @@ extension ReaderTopicsCardCell: UICollectionViewDelegateFlowLayout {

var size = title.size(withAttributes: attributes)
size.height += (CellConstants.marginY * 2)
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
size.height += 2 // to account for the top & bottom border width
}

// Prevent 1 token from being too long
let maxWidth = collectionView.bounds.width * CellConstants.maxWidthMultiplier
let width = min(size.width, maxWidth)
size.width = width + (CellConstants.marginX * 2)
if FeatureFlag.readerImprovements.enabled {
if RemoteFeatureFlag.readerImprovements.enabled() {
size.width += 2 // to account for the leading & trailing border width
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReaderInterestsStyleGuide {
public class func applyCompactCellLabelStyle(label: UILabel) {
label.font = Self.compactCellLabelTitleFont
label.textColor = .text
label.backgroundColor = FeatureFlag.readerImprovements.enabled ? .clear : .quaternaryBackground
label.backgroundColor = RemoteFeatureFlag.readerImprovements.enabled() ? .clear : .quaternaryBackground
}

// MARK: - Next Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ReaderTopicCollectionViewCoordinator: NSObject {
}

private lazy var metrics: ReaderInterestsStyleGuide.Metrics = {
return FeatureFlag.readerImprovements.enabled ? .latest : .legacy
return RemoteFeatureFlag.readerImprovements.enabled() ? .latest : .legacy
}()

weak var delegate: ReaderTopicCollectionViewCoordinatorDelegate?
Expand Down Expand Up @@ -182,7 +182,7 @@ extension ReaderTopicCollectionViewCoordinator: UICollectionViewDelegateFlowLayo

configure(cell: cell, with: title)

if layout.isExpanded || FeatureFlag.readerImprovements.enabled {
if layout.isExpanded || RemoteFeatureFlag.readerImprovements.enabled() {
cell.label.backgroundColor = .clear
}

Expand Down
Loading

0 comments on commit 222d738

Please sign in to comment.