Skip to content

Commit

Permalink
Refactor FXIOS-10221 [Homepage] Naming conventions for old homepage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin authored Oct 7, 2024
1 parent 5b09e36 commit adf7fcf
Show file tree
Hide file tree
Showing 32 changed files with 252 additions and 229 deletions.
9 changes: 6 additions & 3 deletions BrowserKit/Sources/Common/Logger/LoggerCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ public enum LoggerCategory: String {
/// Related to address and credit card autofill
case autofill

/// Related to the certificate handler
case certificate

/// Related to coordinator navigation
case coordinator

/// Related to experiments, nimbus and the messaging framework.
case experiments

/// Related to homepage UI and it's data management.
case homepage
/// Related to old homepage UI and it's data management. To be replaced by the homepage rebuild project.
case legacyHomepage

/// Related to new homepage UI and it's data management for the homepage rebuild project.
case newHomepage
case homepage

/// Related to errors around image fetches, and includes all image types (`SiteImageType`, and general images).
case images
Expand Down
56 changes: 28 additions & 28 deletions firefox-ios/Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

70 changes: 37 additions & 33 deletions firefox-ios/Client/Coordinators/Browser/BrowserCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class BrowserCoordinator: BaseCoordinator,
MainMenuCoordinatorDelegate {
var browserViewController: BrowserViewController
var webviewController: WebviewViewController?
var legacyHomepageViewController: LegacyHomepageViewController?
var homepageViewController: HomepageViewController?
var newHomepageViewController: NewHomepageViewController?
var privateViewController: PrivateHomepageViewController?
var errorViewController: NativeErrorPageViewController?

Expand Down Expand Up @@ -103,33 +103,37 @@ class BrowserCoordinator: BaseCoordinator,

// MARK: - BrowserDelegate

func showHomepage(inline: Bool,
toastContainer: UIView,
homepanelDelegate: HomePanelDelegate,
libraryPanelDelegate: LibraryPanelDelegate,
statusBarScrollDelegate: StatusBarScrollDelegate,
overlayManager: OverlayModeManager) {
let homepageController = getHomepage(inline: inline,
toastContainer: toastContainer,
homepanelDelegate: homepanelDelegate,
libraryPanelDelegate: libraryPanelDelegate,
statusBarScrollDelegate: statusBarScrollDelegate,
overlayManager: overlayManager)

guard browserViewController.embedContent(homepageController) else { return }
self.homepageViewController = homepageController
homepageController.scrollToTop()
func showLegacyHomepage(
inline: Bool,
toastContainer: UIView,
homepanelDelegate: HomePanelDelegate,
libraryPanelDelegate: LibraryPanelDelegate,
statusBarScrollDelegate: StatusBarScrollDelegate,
overlayManager: OverlayModeManager
) {
let legacyHomepageViewController = getHomepage(
inline: inline,
toastContainer: toastContainer,
homepanelDelegate: homepanelDelegate,
libraryPanelDelegate: libraryPanelDelegate,
statusBarScrollDelegate: statusBarScrollDelegate,
overlayManager: overlayManager
)

guard browserViewController.embedContent(legacyHomepageViewController) else { return }
self.legacyHomepageViewController = legacyHomepageViewController
legacyHomepageViewController.scrollToTop()
// We currently don't support full page screenshot of the homepage
screenshotService.screenshotableView = nil
}

func showNewHomepage() {
let homepageController = NewHomepageViewController(windowUUID: windowUUID)
func showHomepage() {
let homepageController = HomepageViewController(windowUUID: windowUUID)
guard browserViewController.embedContent(homepageController) else {
logger.log("Unable to embed new homepage", level: .debug, category: .coordinator)
return
}
self.newHomepageViewController = homepageController
self.homepageViewController = homepageController
}

func showPrivateHomepage(overlayManager: OverlayModeManager) {
Expand Down Expand Up @@ -192,23 +196,23 @@ class BrowserCoordinator: BaseCoordinator,
homepanelDelegate: HomePanelDelegate,
libraryPanelDelegate: LibraryPanelDelegate,
statusBarScrollDelegate: StatusBarScrollDelegate,
overlayManager: OverlayModeManager) -> HomepageViewController {
if let homepageViewController = homepageViewController {
homepageViewController.configure(isZeroSearch: inline)
return homepageViewController
overlayManager: OverlayModeManager) -> LegacyHomepageViewController {
if let legacyHomepageViewController = legacyHomepageViewController {
legacyHomepageViewController.configure(isZeroSearch: inline)
return legacyHomepageViewController
} else {
let homepageViewController = HomepageViewController(
let legacyHomepageViewController = LegacyHomepageViewController(
profile: profile,
isZeroSearch: inline,
toastContainer: toastContainer,
tabManager: tabManager,
overlayManager: overlayManager)
homepageViewController.homePanelDelegate = homepanelDelegate
homepageViewController.libraryPanelDelegate = libraryPanelDelegate
homepageViewController.statusBarScrollDelegate = statusBarScrollDelegate
homepageViewController.browserNavigationHandler = self
legacyHomepageViewController.homePanelDelegate = homepanelDelegate
legacyHomepageViewController.libraryPanelDelegate = libraryPanelDelegate
legacyHomepageViewController.statusBarScrollDelegate = statusBarScrollDelegate
legacyHomepageViewController.browserNavigationHandler = self

return homepageViewController
return legacyHomepageViewController
}
}

Expand Down Expand Up @@ -828,9 +832,9 @@ class BrowserCoordinator: BaseCoordinator,
// Clean up views and ensure BVC for the window is freed
browserViewController.view.endEditing(true)
browserViewController.dismissUrlBar()
homepageViewController?.view.removeFromSuperview()
homepageViewController?.removeFromParent()
homepageViewController = nil
legacyHomepageViewController?.view.removeFromSuperview()
legacyHomepageViewController?.removeFromParent()
legacyHomepageViewController = nil
browserViewController.contentContainer.subviews.forEach { $0.removeFromSuperview() }
browserViewController.removeFromParent()
case .libraryOpened:
Expand Down
16 changes: 9 additions & 7 deletions firefox-ios/Client/Coordinators/Browser/BrowserDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ protocol BrowserDelegate: AnyObject {
/// - libraryPanelDelegate: The library panel delegate for the homepage
/// - statusBarScrollDelegate: The delegate that takes care of the status bar overlay scroll
/// - overlayManager: The overlay manager for the homepage
func showHomepage(inline: Bool,
toastContainer: UIView,
homepanelDelegate: HomePanelDelegate,
libraryPanelDelegate: LibraryPanelDelegate,
statusBarScrollDelegate: StatusBarScrollDelegate,
overlayManager: OverlayModeManager)
func showLegacyHomepage(
inline: Bool,
toastContainer: UIView,
homepanelDelegate: HomePanelDelegate,
libraryPanelDelegate: LibraryPanelDelegate,
statusBarScrollDelegate: StatusBarScrollDelegate,
overlayManager: OverlayModeManager
)

/// Show the new homepage to the user as part of the homepage rebuild project
func showNewHomepage()
func showHomepage()

/// Show the private homepage to the user as part of felt privacy
func showPrivateHomepage(overlayManager: OverlayModeManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension BrowserViewController {
guard let tab = tabManager.selectedTab,
let url = tab.canonicalURL?.displayURL else { return }

if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
addBookmark(url: url.absoluteString, title: tab.title)
}
}
Expand All @@ -60,7 +60,7 @@ extension BrowserViewController {
store.dispatch(GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.reloadWebsite))
} else {
if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
tab.reload()
}
}
Expand All @@ -77,7 +77,7 @@ extension BrowserViewController {
store.dispatch(GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.reloadWebsiteNoCache))
} else {
if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
tab.reload(bypassCache: true)
}
}
Expand All @@ -94,7 +94,7 @@ extension BrowserViewController {
store.dispatch(GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.navigateBack))
} else {
if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
tab.goBack()
}
}
Expand All @@ -111,7 +111,7 @@ extension BrowserViewController {
store.dispatch(GeneralBrowserAction(windowUUID: windowUUID,
actionType: GeneralBrowserActionType.navigateForward))
} else {
if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
tab.goForward()
}
}
Expand All @@ -134,7 +134,7 @@ extension BrowserViewController {
private func findInPage(withText text: String) {
guard let tab = tabManager.selectedTab else { return }

if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
self.tab(tab, didSelectFindInPageForSelection: text)
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ extension BrowserViewController {
func zoomIn() {
guard let currentTab = tabManager.selectedTab else { return }

if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
currentTab.zoomIn()
}
}
Expand All @@ -350,7 +350,7 @@ extension BrowserViewController {
func zoomOut() {
guard let currentTab = tabManager.selectedTab else { return }

if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
currentTab.zoomOut()
}
}
Expand All @@ -359,7 +359,7 @@ extension BrowserViewController {
func resetZoom() {
guard let currentTab = tabManager.selectedTab else { return }

if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
currentTab.resetZoom()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ extension BrowserViewController: URLBarDelegate {

func urlBarDidPressScrollToTop(_ urlBar: URLBarView) {
guard let selectedTab = tabManager.selectedTab else { return }
if !contentContainer.hasHomepage {
if !contentContainer.hasLegacyHomepage {
// Only scroll to top if we are not showing the home view controller
selectedTab.webView?.scrollView.setContentOffset(CGPoint.zero, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ extension BrowserViewController: WKUIDelegate {
type: WKMediaCaptureType,
decisionHandler: @escaping (WKPermissionDecision) -> Void) {
// If the tab isn't the selected one or we're on the homepage, do not show the media capture prompt
guard tabManager.selectedTab?.webView == webView, !contentContainer.hasHomepage else {
guard tabManager.selectedTab?.webView == webView, !contentContainer.hasLegacyHomepage else {
decisionHandler(.deny)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ class BrowserViewController: UIViewController,

func frontEmbeddedContent(_ viewController: ContentContainable) {
contentContainer.update(content: viewController)
statusBarOverlay.resetState(isHomepage: contentContainer.hasHomepage)
statusBarOverlay.resetState(isHomepage: contentContainer.hasLegacyHomepage)
}

/// Embed a ContentContainable inside the content container
Expand All @@ -1282,7 +1282,7 @@ class BrowserViewController: UIViewController,
viewController.willMove(toParent: self)
contentContainer.add(content: viewController)
viewController.didMove(toParent: self)
statusBarOverlay.resetState(isHomepage: contentContainer.hasHomepage)
statusBarOverlay.resetState(isHomepage: contentContainer.hasLegacyHomepage)

UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: nil)
return true
Expand All @@ -1308,14 +1308,16 @@ class BrowserViewController: UIViewController,
}

if featureFlags.isFeatureEnabled(.homepageRebuild, checking: .buildOnly) {
browserDelegate?.showNewHomepage()
browserDelegate?.showHomepage()
} else {
browserDelegate?.showHomepage(inline: inline,
toastContainer: contentContainer,
homepanelDelegate: self,
libraryPanelDelegate: self,
statusBarScrollDelegate: statusBarOverlay,
overlayManager: overlayManager)
browserDelegate?.showLegacyHomepage(
inline: inline,
toastContainer: contentContainer,
homepanelDelegate: self,
libraryPanelDelegate: self,
statusBarScrollDelegate: statusBarOverlay,
overlayManager: overlayManager
)
}
}

Expand Down
20 changes: 10 additions & 10 deletions firefox-ios/Client/Frontend/Components/ContentContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import UIKit

enum ContentType {
case webview
case homepage
case legacyHomepage
case privateHomepage
case nativeErrorPage
case newHomepage
case webview
}

protocol ContentContainable: UIViewController {
Expand All @@ -25,16 +25,16 @@ class ContentContainer: UIView {
return contentController?.view
}

var hasHomepage: Bool {
return type == .homepage
var hasLegacyHomepage: Bool {
return type == .legacyHomepage
}

var hasPrivateHomepage: Bool {
return type == .privateHomepage
}

var hasNewHomepage: Bool {
return type == .newHomepage
var hasHomepage: Bool {
return type == .homepage
}

var hasWebView: Bool {
Expand All @@ -51,12 +51,12 @@ class ContentContainer: UIView {
/// - Returns: True when we can add the view controller to the container
func canAdd(content: ContentContainable) -> Bool {
switch type {
case .homepage:
return !(content is HomepageViewController)
case .legacyHomepage:
return !(content is LegacyHomepageViewController)
case .nativeErrorPage:
return !(content is NativeErrorPageViewController)
case .newHomepage:
return !(content is NewHomepageViewController)
case .homepage:
return !(content is HomepageViewController)
case .privateHomepage:
return !(content is PrivateHomepageViewController)
case .webview:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ extension HistoryHighlightsViewModel: HistoryHighlightsDelegate {
self.historyItems = self.historyHighlightsDataAdaptor.getHistoryHighlights()
self.logger.log("HistoryHighlights didLoadNewData and section shouldShow \(self.shouldShow)",
level: .debug,
category: .homepage)
category: .legacyHomepage)
guard self.isEnabled else { return }
self.delegate?.reloadView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import UIKit

typealias HomepageSection = NewHomepageDiffableDataSource.HomeSection
typealias HomepageItem = NewHomepageDiffableDataSource.HomeItem
typealias HomepageSection = HomepageDiffableDataSource.HomeSection
typealias HomepageItem = HomepageDiffableDataSource.HomeItem

/// Holds the data source configuration for the new homepage as part of the rebuild project
final class NewHomepageDiffableDataSource:
final class HomepageDiffableDataSource:
UICollectionViewDiffableDataSource<HomepageSection, HomepageItem> {
enum HomeSection: Int, Hashable {
case header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Foundation
import Common

/// Holds section layout logic for the new homepage as part of the rebuild project
final class NewHomepageSectionLayoutProvider {
final class HomepageSectionLayoutProvider {
private var logger: Logger

init(logger: Logger = DefaultLogger.shared) {
Expand All @@ -19,7 +19,7 @@ final class NewHomepageSectionLayoutProvider {
self.logger.log(
"Section should not have been nil, something went wrong",
level: .fatal,
category: .newHomepage
category: .homepage
)
return nil
}
Expand Down
Loading

0 comments on commit adf7fcf

Please sign in to comment.