Skip to content

Commit

Permalink
Add FXIOS-10164 [Homepage] Pocket Footer + Header
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin committed Oct 16, 2024
1 parent f4bf071 commit 19a604d
Show file tree
Hide file tree
Showing 24 changed files with 658 additions and 130 deletions.
38 changes: 28 additions & 10 deletions firefox-ios/Client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-asn1.git",
"state" : {
"revision" : "df5d2fcd22e3f480e3ef85bf23e277a4a0ef524d",
"version" : "1.2.0"
"revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6",
"version" : "1.3.0"
}
},
{
Expand All @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "9f95b4d033a4edd3814b48608db3f2ca90c7218b",
"version" : "3.7.0"
"revision" : "21f7878f2b39d46fd8ba2b06459ccb431cdf876c",
"version" : "3.8.1"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class BrowserCoordinator: BaseCoordinator,

// MARK: - PrivateHomepageDelegate

func homePanel(with url: URL, visitType: VisitType, isGoogleTopSite: Bool) {
browserViewController.homePanel(didSelectURL: url, visitType: visitType, isGoogleTopSite: isGoogleTopSite)
}

func homePanelDidRequestToOpenInNewTab(with url: URL, isPrivate: Bool, selectNewTab: Bool) {
browserViewController.homePanelDidRequestToOpenInNewTab(
url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum GeneralBrowserActionType: ActionType {
case showBackForwardList
case showTrackingProtectionDetails
case showTabsLongPressActions
case showReloadLongPressAction
case showReloadLoøhomepagengPressAction
case showMenu
case showLocationViewLongPressActionSheet
case stopLoadingWebsite
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation

/// Holds the various navigation that
class NavigationBrowserAction: Action {
let url: URL?
init(urlToVisit: URL? = nil,
windowUUID: WindowUUID,
actionType: ActionType) {
self.urlToVisit = urlToVisit
super.init(windowUUID: windowUUID,
actionType: actionType)
}
}

enum NavigationBrowserActionType: ActionType {
case tapOnCustomizeHomepage
case tapOnCell
case tapOnLink
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation

/// Holds the cases that the browser coordinator can navigate to
/// This type exists as a field on the BrowserViewControllerState
enum BrowserNavigationDestination {
case customizeHomepage
case link
}

struct NavigationDestination: Equatable {
let destination: BrowserNavigationType
let urlToVisit: URL?

init(
_ destination: BrowserNavigationDestination,
urlToVisit: URL? = nil
) {
self.destination = destination
self.urlToVisit = urlToVisit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
var displayView: DisplayType? // use default value when re-creating
var buttonTapped: UIButton?
var microsurveyState: MicrosurveyPromptState
var navigationDestination: NavigationDestination?

init(appState: AppState, uuid: WindowUUID) {
guard let bvcState = store.state.screenState(
Expand Down Expand Up @@ -99,7 +100,8 @@ struct BrowserViewControllerState: ScreenState, Equatable {
navigateTo: NavigationType? = nil,
displayView: DisplayType? = nil,
buttonTapped: UIButton? = nil,
microsurveyState: MicrosurveyPromptState
microsurveyState: MicrosurveyPromptState,
navigationDestination: NavigationDestination? = nil
) {
self.searchScreenState = searchScreenState
self.showDataClearanceFlow = showDataClearanceFlow
Expand All @@ -113,6 +115,7 @@ struct BrowserViewControllerState: ScreenState, Equatable {
self.displayView = displayView
self.buttonTapped = buttonTapped
self.microsurveyState = microsurveyState
self.navigationDestination = navigationDestination
}

static let reducer: Reducer<Self> = { state, action in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,8 @@ class BrowserViewController: UIViewController,
handleNavigationActions(for: state)
case _ where state.displayView != nil:
handleDisplayActions(for: state)
case _ where state.navigationDestination != nil:
handleNavigation(to: state.navigationDestination)
default: break
}
}
Expand All @@ -2047,6 +2049,19 @@ class BrowserViewController: UIViewController,
store.dispatch(action)
}

private func handleNavigation(to type: NavigationDestination) {
switch type.destination {
case .customizeHomepage:
navigationHandler?.show(settings: .homePage)
case .link:
guard let url = type.urlToVisit else {
logger.log("Url is nil, when there should ", level: .warning, category: .coordinator)
return
}
homePanel(didSelectURL: type.urlToVisit, visitType: .link, isGoogleTopSite: false)
}
}

private func handleDisplayActions(for state: BrowserViewControllerState) {
guard let displayState = state.displayView else { return }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class LegacyGridTabViewController: UIViewController,
collectionView.register(cellType: LegacyTabCell.self)
collectionView.register(cellType: LegacyInactiveTabCell.self)
collectionView.register(
LabelButtonHeaderView.self,
LegacyLabelButtonHeaderView.self,
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: LegacyGridTabViewController.independentTabsHeaderIdentifier)
tabDisplayManager = LegacyTabDisplayManager(collectionView: collectionView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LabelButtonHeaderViewModel {
}

// Firefox home view controller header view
class LabelButtonHeaderView: UICollectionReusableView, ReusableCell {
class LegacyLabelButtonHeaderView: UICollectionReusableView, ReusableCell {
struct UX {
static let inBetweenSpace: CGFloat = 12
static let bottomSpace: CGFloat = 10
Expand Down Expand Up @@ -159,7 +159,7 @@ class LabelButtonHeaderView: UICollectionReusableView, ReusableCell {
}

// MARK: - Theme
extension LabelButtonHeaderView: ThemeApplicable {
extension LegacyLabelButtonHeaderView: ThemeApplicable {
func applyTheme(theme: Theme) {
let titleColor = viewModel?.textColor ?? theme.colors.textPrimary
let moreButtonColor = viewModel?.textColor ?? theme.colors.textAccent
Expand All @@ -170,7 +170,7 @@ extension LabelButtonHeaderView: ThemeApplicable {
}

// MARK: - Notifiable
extension LabelButtonHeaderView: Notifiable {
extension LegacyLabelButtonHeaderView: Notifiable {
func handleNotifications(_ notification: Notification) {
switch notification.name {
case .DynamicFontChanged:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ final class HeaderAction: Action {

enum HeaderActionType: ActionType {
case toggleHomepageMode
case tapLearnMore
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ final class HomepageDiffableDataSource:

enum HomeItem: Hashable {
case header
case pocket(PocketItem)
case pocketDiscover(String)
case pocket(PocketStoryState)
case pocketDiscover(PocketDiscoverState)
case customizeHomepage

static var cellTypes: [ReusableCell.Type] {
Expand All @@ -43,7 +43,7 @@ final class HomepageDiffableDataSource:

let stories: [HomeItem] = state.pocketState.pocketData.compactMap { .pocket($0) }
snapshot.appendItems(stories, toSection: .pocket)
let discoverItem = state.pocketState.pocketDiscoverTitle
let discoverItem = state.pocketState.pocketDiscover
if !discoverItem.isEmpty {
snapshot.appendItems([.pocketDiscover(discoverItem)], toSection: .pocket)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import Foundation

enum HomepageNavigationDestination: Equatable, CaseIterable {
case customizeHomepage
case learnMore
case link
}

struct NavigationDestination: Equatable {
let destination: HomepageNavigationDestination
let urlToVisit: URL?

init(
_ destination: HomepageNavigationDestination,
urlToVisit: URL? = nil
) {
self.destination = destination
self.urlToVisit = urlToVisit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ final class HomepageSectionLayoutProvider {

let section = NSCollectionLayoutSection(group: group)

let headerFooterSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),
heightDimension: .estimated(UX.PocketConstants.headerFooterHeight))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
elementKind: UICollectionView.elementKindSectionHeader,
alignment: .top)
let footer = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerFooterSize,
elementKind: UICollectionView.elementKindSectionFooter,
alignment: .bottom)
section.boundarySupplementaryItems = [header, footer]

let leadingInset = UX.leadingInset(traitCollection: traitCollection)
section.contentInsets = NSDirectionalEdgeInsets(top: 0,
leading: leadingInset,
Expand Down
Loading

0 comments on commit 19a604d

Please sign in to comment.