Skip to content

Commit

Permalink
Merge branch 'release/v121' into mergify/bp/release/v121/pr-17587
Browse files Browse the repository at this point in the history
# Conflicts:
#	Client/Frontend/Browser/BrowserViewController.swift
#	Client/Frontend/Fakespot/FakespotState.swift
#	Client/Frontend/FeltPrivacy/BrowserViewControllerState.swift
  • Loading branch information
thatswinnie committed Dec 6, 2023
2 parents f861f3a + dc0bec6 commit a90160a
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 114 deletions.
2 changes: 2 additions & 0 deletions BrowserKit/Sources/Redux/StoreSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import Foundation

public protocol AnyStoreSubscriber: AnyObject {
func subscribeToRedux()
func unsubscribeFromRedux()
func newState(state: Any)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,32 @@ class FakeReduxViewController: UIViewController, StoreSubscriber {

override func viewDidLoad() {
super.viewDidLoad()
subscribeToRedux()
view.addSubview(label)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
unsubscribeFromRedux()
}

// MARK: - Redux

func subscribeToRedux() {
store.subscribe(self)
store.dispatch(FakeReduxAction.requestInitialValue)
view.addSubview(label)
}

func unsubscribeFromRedux() {
store.unsubscribe(self)
}

func newState(state: FakeReduxState) {
label.text = "\(state.counter)"
}

// MARK: - Helper functions

func increaseCounter() {
store.dispatch(FakeReduxAction.increaseCounter)
}
Expand Down
28 changes: 28 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@
7BEB64441C7345600092C02E /* L10nSuite2SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3632D31C2983F000D12AF9 /* L10nSuite2SnapshotTests.swift */; };
7BEB64451C7345600092C02E /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B60B0071BDE3AE10090C984 /* SnapshotHelper.swift */; };
7BEFC6801BFF68C30059C952 /* QuickActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BEFC67F1BFF68C30059C952 /* QuickActions.swift */; };
810FF3542B178343009F062C /* FeltPrivacyMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810FF3532B178343009F062C /* FeltPrivacyMiddleware.swift */; };
810FF3562B1783B0009F062C /* FeltPrivacyManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810FF3552B1783B0009F062C /* FeltPrivacyManager.swift */; };
810FF3582B1784E7009F062C /* FeltPrivacyAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810FF3572B1784E7009F062C /* FeltPrivacyAction.swift */; };
810FF35A2B178556009F062C /* FeltPrivacyState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 810FF3592B178556009F062C /* FeltPrivacyState.swift */; };
81CAE4DB2B1A2C220040C78A /* BrowserViewControllerState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81CAE4DA2B1A2C220040C78A /* BrowserViewControllerState.swift */; };
884CA7492344A301002E4711 /* TextContentDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884CA7482344A301002E4711 /* TextContentDetector.swift */; };
8A0017C128A3FF6100FEFC8B /* MessageCardDataAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A0017C028A3FF6100FEFC8B /* MessageCardDataAdaptor.swift */; };
8A01891C275E9C2A00923EFE /* ClearHistorySheetProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01891B275E9C2A00923EFE /* ClearHistorySheetProvider.swift */; };
Expand Down Expand Up @@ -5007,12 +5012,17 @@
80B54D93BC553D6E6CDFAA0A /* cy */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cy; path = cy.lproj/AuthenticationManager.strings; sourceTree = "<group>"; };
80B8473B933671C9605DC837 /* gl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = gl; path = gl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
80E24B20A5655593E1D9E85B /* zh-TW */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-TW"; path = "zh-TW.lproj/Search.strings"; sourceTree = "<group>"; };
810FF3532B178343009F062C /* FeltPrivacyMiddleware.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeltPrivacyMiddleware.swift; sourceTree = "<group>"; };
810FF3552B1783B0009F062C /* FeltPrivacyManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeltPrivacyManager.swift; sourceTree = "<group>"; };
810FF3572B1784E7009F062C /* FeltPrivacyAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeltPrivacyAction.swift; sourceTree = "<group>"; };
810FF3592B178556009F062C /* FeltPrivacyState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeltPrivacyState.swift; sourceTree = "<group>"; };
81504EA4876ED3D974FDA0F6 /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/AuthenticationManager.strings; sourceTree = "<group>"; };
81584D62B22049E40FC78F93 /* sl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sl; path = sl.lproj/3DTouchActions.strings; sourceTree = "<group>"; };
816D458CBEAE2A6721134028 /* dsb */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = dsb; path = dsb.lproj/ClearPrivateData.strings; sourceTree = "<group>"; };
81754147A06566E64C025F70 /* nn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nn; path = "nn.lproj/Default Browser.strings"; sourceTree = "<group>"; };
81A244F4A7C6FC8976DC21F0 /* br */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = br; path = br.lproj/InfoPlist.strings; sourceTree = "<group>"; };
81C14765AA7C25DF1817AC04 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Today.strings; sourceTree = "<group>"; };
81CAE4DA2B1A2C220040C78A /* BrowserViewControllerState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowserViewControllerState.swift; sourceTree = "<group>"; };
81DF4C79AE53A2FCA08EEE9C /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = "da.lproj/Default Browser.strings"; sourceTree = "<group>"; };
81E446CF88B278374B416BF5 /* or */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = or; path = or.lproj/AuthenticationManager.strings; sourceTree = "<group>"; };
81F647D98E79EC6406CDFCB4 /* lt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = lt; path = lt.lproj/ClearPrivateData.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8462,6 +8472,18 @@
path = Menu;
sourceTree = "<group>";
};
810FF3522B1782FE009F062C /* FeltPrivacy */ = {
isa = PBXGroup;
children = (
81CAE4DA2B1A2C220040C78A /* BrowserViewControllerState.swift */,
810FF3532B178343009F062C /* FeltPrivacyMiddleware.swift */,
810FF3592B178556009F062C /* FeltPrivacyState.swift */,
810FF3572B1784E7009F062C /* FeltPrivacyAction.swift */,
810FF3552B1783B0009F062C /* FeltPrivacyManager.swift */,
);
path = FeltPrivacy;
sourceTree = "<group>";
};
8A0017BF28A3FED300FEFC8B /* MessageCard */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -10970,6 +10992,7 @@
F84B21F11A0910F600AAB793 /* Frontend */ = {
isa = PBXGroup;
children = (
810FF3522B1782FE009F062C /* FeltPrivacy */,
E1D3FFAF2A66A9BD002D31EF /* Fakespot */,
43D00490296FC44B00CB0F31 /* Autofill */,
C855728029AE7EF900AF32B0 /* SurveySurface */,
Expand Down Expand Up @@ -12758,6 +12781,7 @@
1DEBC55E2AC4ED70006E4801 /* RemoteTabsPanel.swift in Sources */,
435D660523D794B90046EFA2 /* UpdateViewModel.swift in Sources */,
9658143C29FAB610007339BD /* CreditCardInputFieldHelper.swift in Sources */,
810FF3542B178343009F062C /* FeltPrivacyMiddleware.swift in Sources */,
215B457F27D7FD4B00E5E800 /* LegacyTabGroupData.swift in Sources */,
E12BD0B028AC3A7E0029AAF0 /* UIEdgeInsets+Extension.swift in Sources */,
C2D80BE72AADE38100CDF7A9 /* CredentialAutofillCoordinator.swift in Sources */,
Expand Down Expand Up @@ -12847,6 +12871,7 @@
8A07910F278F62F2005529CB /* AdjustHelper.swift in Sources */,
E1442FC2294782C3003680B0 /* NSAttributedString+Extension.swift in Sources */,
967A028E28FA026F003C35E3 /* SceneDelegate.swift in Sources */,
810FF3562B1783B0009F062C /* FeltPrivacyManager.swift in Sources */,
C8B07A4128199500000AFCE7 /* NimbusFlaggableFeature.swift in Sources */,
0B62EFD21AD63CD100ACB9CD /* Clearables.swift in Sources */,
431C0CA925C890E500395CE4 /* DefaultBrowserOnboardingViewModel.swift in Sources */,
Expand Down Expand Up @@ -12899,6 +12924,7 @@
2178A6A0291454B5002EC290 /* ReaderModeThemeButton.swift in Sources */,
39F4C10A2045DB2E00746155 /* FocusHelper.swift in Sources */,
E4CD9F2D1A6DC91200318571 /* TabLocationView.swift in Sources */,
81CAE4DB2B1A2C220040C78A /* BrowserViewControllerState.swift in Sources */,
C8BD87602A0C248000CD803A /* OnboardingButtonsModel.swift in Sources */,
0BB5B2881AC0A2B90052877D /* SnackBar.swift in Sources */,
E1442FCF294782D9003680B0 /* UIView+Screenshot.swift in Sources */,
Expand Down Expand Up @@ -13244,6 +13270,7 @@
E1ADE23C2B0649F200FD17AA /* FakespotState.swift in Sources */,
2816F0001B33E05400522243 /* UIConstants.swift in Sources */,
21E78A7228F9A93100F8D687 /* UIDeviceInterface.swift in Sources */,
810FF35A2B178556009F062C /* FeltPrivacyState.swift in Sources */,
EBB89508219398E500EB91A0 /* ContentBlocker+Safelist.swift in Sources */,
437A9B6A2681257F00FB41C1 /* LegacyInactiveTabViewModel.swift in Sources */,
C838FD5E289981240068F60B /* WallpaperURLProvider.swift in Sources */,
Expand Down Expand Up @@ -13357,6 +13384,7 @@
59A68E0B4ABBF55E14819668 /* BookmarksPanel.swift in Sources */,
BD4B2DE429BB4D9A005FAA50 /* TimerSnackBar.swift in Sources */,
21EA466A2B04130500AAAB2D /* TabsState.swift in Sources */,
810FF3582B1784E7009F062C /* FeltPrivacyAction.swift in Sources */,
D04D1B862097859B0074B35F /* DownloadToast.swift in Sources */,
C29B64EE2AD937D500F3244B /* QRCodeNavigationHandler.swift in Sources */,
8A19ACB42A3290D9001C2147 /* ContentBlockerSetting.swift in Sources */,
Expand Down
47 changes: 8 additions & 39 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class BrowserViewController: UIViewController,
static let ActionSheetTitleMaxLength = 120
}

typealias SubscriberStateType = BrowserViewControllerState

private let KVOs: [KVOConstants] = [
.estimatedProgress,
.loading,
Expand Down Expand Up @@ -80,7 +82,7 @@ class BrowserViewController: UIViewController,
let tabManager: TabManager
let ratingPromptManager: RatingPromptManager
lazy var isTabTrayRefactorEnabled: Bool = TabTrayFlagManager.isRefactorEnabled
private var fakespotState: FakespotState?
private var browserViewControllerState: BrowserViewControllerState?

// Header stack view can contain the top url bar, top reader mode, top ZoomPageBar
var header: BaseAlphaStackView = .build { _ in }
Expand Down Expand Up @@ -206,9 +208,7 @@ class BrowserViewController: UIViewController,
}

deinit {
if isReduxIntegrationEnabled {
store.unsubscribe(self)
}
unsubscribeFromRedux()
}

override var prefersStatusBarHidden: Bool {
Expand Down Expand Up @@ -466,48 +466,30 @@ class BrowserViewController: UIViewController,

// MARK: - Redux

<<<<<<< HEAD
private func subscribeRedux() {
guard isReduxIntegrationEnabled else { return }
store.dispatch(ActiveScreensStateAction.showScreen(.fakespot))
=======
func subscribeToRedux() {
store.dispatch(ActiveScreensStateAction.showScreen(.browserViewController))
>>>>>>> f8565a9a1 (Refactor FXIOS-7812 [v121] Fakespot - iPad - sidebar open/close state resets itself when user changes from landscape to portrait mode (#17587))

store.subscribe(self, transform: {
$0.select(FakespotState.init)
$0.select(BrowserViewControllerState.init)
})
}

<<<<<<< HEAD
func newState(state: FakespotState) {
=======
func unsubscribeFromRedux() {
store.unsubscribe(self)
}

func newState(state: BrowserViewControllerState) {
>>>>>>> f8565a9a1 (Refactor FXIOS-7812 [v121] Fakespot - iPad - sidebar open/close state resets itself when user changes from landscape to portrait mode (#17587))
ensureMainThread { [weak self] in
guard let self else { return }

fakespotState = state
browserViewControllerState = state

// opens or close sidebar/bottom sheet to match the saved state
<<<<<<< HEAD
if state.isOpenOnProductPage {
guard let productURL = urlBar.currentURL else { return }
handleFakespotFlow(productURL: productURL)
} else {
_ = dismissFakespotIfNeeded()
=======
if state.fakespotState.isOpen {
guard let productURL = urlBar.currentURL else { return }
handleFakespotFlow(productURL: productURL)
} else if !state.fakespotState.isOpen {
dismissFakespotIfNeeded()
>>>>>>> f8565a9a1 (Refactor FXIOS-7812 [v121] Fakespot - iPad - sidebar open/close state resets itself when user changes from landscape to portrait mode (#17587))
}
}
}
Expand Down Expand Up @@ -570,7 +552,7 @@ class BrowserViewController: UIViewController,
// Send settings telemetry for Fakespot
FakespotUtils().addSettingTelemetry()

subscribeRedux()
subscribeToRedux()
}

private func setupAccessibleActions() {
Expand Down Expand Up @@ -777,13 +759,9 @@ class BrowserViewController: UIViewController,
var fakespotNeedsUpdate = false
if urlBar.currentURL != nil {
fakespotNeedsUpdate = contentStackView.isSidebarVisible != FakespotUtils().shouldDisplayInSidebar(viewSize: size)
<<<<<<< HEAD
if isReduxIntegrationEnabled, let fakespotState = fakespotState {
fakespotNeedsUpdate = fakespotNeedsUpdate && fakespotState.isOpenOnProductPage
=======

if let fakespotState = browserViewControllerState?.fakespotState {
fakespotNeedsUpdate = fakespotNeedsUpdate && fakespotState.isOpen
>>>>>>> f8565a9a1 (Refactor FXIOS-7812 [v121] Fakespot - iPad - sidebar open/close state resets itself when user changes from landscape to portrait mode (#17587))
}

if fakespotNeedsUpdate {
Expand Down Expand Up @@ -1737,19 +1715,10 @@ class BrowserViewController: UIViewController,
navigationHandler?.updateFakespotSidebar(productURL: url,
sidebarContainer: contentStackView,
parentViewController: self)
<<<<<<< HEAD
} else if product.product != nil,
!tab.isPrivate,
FakespotUtils().shouldDisplayInSidebar(),
isReduxIntegrationEnabled,
let fakespotState = fakespotState,
fakespotState.isOpenOnProductPage {
=======
} else if FakespotUtils().shouldDisplayInSidebar(),
let fakespotState = browserViewControllerState?.fakespotState,
fakespotState.isOpen {
// Sidebar should be displayed and Fakespot is open, display Fakespot
>>>>>>> f8565a9a1 (Refactor FXIOS-7812 [v121] Fakespot - iPad - sidebar open/close state resets itself when user changes from landscape to portrait mode (#17587))
handleFakespotFlow(productURL: url)
} else if let fakespotState = browserViewControllerState?.fakespotState,
fakespotState.sidebarOpenForiPadLandscape {
Expand Down
16 changes: 10 additions & 6 deletions Client/Frontend/Browser/Tabs/RemoteTabs/RemoteTabsPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ class RemoteTabsPanel: UIViewController,
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }

deinit {
if isReduxIntegrationEnabled {
store.dispatch(ActiveScreensStateAction.closeScreen(.remoteTabsPanel))
store.unsubscribe(self)
}
unsubscribeFromRedux()
}

// MARK: - Actions
Expand Down Expand Up @@ -96,7 +93,7 @@ class RemoteTabsPanel: UIViewController,

listenForThemeChange(view)
setupLayout()
subscribeRedux()
subscribeToRedux()
applyTheme()
}

Expand Down Expand Up @@ -128,7 +125,7 @@ class RemoteTabsPanel: UIViewController,

// MARK: - Redux

private func subscribeRedux() {
func subscribeToRedux() {
guard isReduxIntegrationEnabled else { return }
store.dispatch(ActiveScreensStateAction.showScreen(.remoteTabsPanel))
store.dispatch(RemoteTabsPanelAction.panelDidAppear)
Expand All @@ -137,6 +134,13 @@ class RemoteTabsPanel: UIViewController,
})
}

func unsubscribeFromRedux() {
if isReduxIntegrationEnabled {
store.dispatch(ActiveScreensStateAction.closeScreen(.remoteTabsPanel))
store.unsubscribe(self)
}
}

func newState(state: RemoteTabsPanelState) {
ensureMainThread { [weak self] in
guard let self else { return }
Expand Down
41 changes: 23 additions & 18 deletions Client/Frontend/Browser/Tabs/TabDisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TabDisplayViewController: UIViewController,
private var backgroundPrivacyOverlay: UIView = .build()
private lazy var emptyPrivateTabsView: EmptyPrivateTabsView = .build()

// MARK: Redux state
var tabsState: TabsState

init(isPrivateMode: Bool,
Expand All @@ -43,30 +42,15 @@ class TabDisplayViewController: UIViewController,
}

deinit {
store.dispatch(ActiveScreensStateAction.closeScreen(.tabsPanel))
store.unsubscribe(self)
unsubscribeFromRedux()
}

override func viewDidLoad() {
super.viewDidLoad()
setupView()
listenForThemeChange(view)
applyTheme()
subscribeRedux()
}

private func subscribeRedux() {
store.dispatch(ActiveScreensStateAction.showScreen(.tabsPanel))
store.dispatch(TabPanelAction.tabPanelDidLoad(tabsState.isPrivateMode))
store.subscribe(self, transform: {
return $0.select(TabsState.init)
})
}

func newState(state: TabsState) {
tabsState = state
tabDisplayView.newState(state: tabsState)
shouldShowEmptyView(tabsState.isPrivateTabsEmpty)
subscribeToRedux()
}

func setupView() {
Expand Down Expand Up @@ -116,6 +100,27 @@ class TabDisplayViewController: UIViewController,
tabDisplayView.applyTheme(theme: themeManager.currentTheme)
}

// MARK: - Redux

func subscribeToRedux() {
store.dispatch(ActiveScreensStateAction.showScreen(.tabsPanel))
store.dispatch(TabPanelAction.tabPanelDidLoad(tabsState.isPrivateMode))
store.subscribe(self, transform: {
return $0.select(TabsState.init)
})
}

func unsubscribeFromRedux() {
store.dispatch(ActiveScreensStateAction.closeScreen(.tabsPanel))
store.unsubscribe(self)
}

func newState(state: TabsState) {
tabsState = state
tabDisplayView.newState(state: tabsState)
shouldShowEmptyView(tabsState.isPrivateTabsEmpty)
}

// MARK: EmptyPrivateTabsViewDelegate
func didTapLearnMore(urlRequest: URLRequest) {}
}
Loading

0 comments on commit a90160a

Please sign in to comment.