Skip to content

Commit

Permalink
Refactor FXIOS-9353 #20714 Improving BVC viewDidLoad (#24487)
Browse files Browse the repository at this point in the history
* Try to improve viewDidLoad

* Remove UISearchController init from startpath, wasn't even needed

+ fix some stuff that needs to be on the main thread

* Remove redundant call to updateToolbarStateForTraitCollection

Move telemetry in the telemetry tracking class

* Update

- Move Search bar telemetry to the trackStartUpTelemetry function
- Move updateCreditCardAutofillStatus into main.async
- Remove commented code
- Move setupNotifications back to setupEssentialUI since we dont want race conditions

* Create setupNonEssentialUI function

* Remove non essential UI + change to Task(priority:) for background telemetry queue
  • Loading branch information
lmarceau authored Feb 4, 2025
1 parent 80853e6 commit ac020c0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class BrowserViewController: UIViewController,
let navigationViewProvider = ContextualHintViewProvider(forHintType: .navigation, with: profile)

self.navigationContextHintVC = ContextualHintViewController(with: navigationViewProvider, windowUUID: windowUUID)
self.searchTelemetry = SearchTelemetry(tabManager: tabManager)

super.init(nibName: nil, bundle: nil)
didInit()
Expand Down Expand Up @@ -746,35 +747,20 @@ class BrowserViewController: UIViewController,

override func viewDidLoad() {
super.viewDidLoad()
KeyboardHelper.defaultHelper.addDelegate(self)
trackTelemetry()
setupNotifications()
addSubviews()
listenForThemeChange(view)
setupAccessibleActions()

clipboardBarDisplayHandler = ClipboardBarDisplayHandler(prefs: profile.prefs, tabManager: tabManager)
clipboardBarDisplayHandler?.delegate = self

navigationToolbarContainer.toolbarDelegate = self

scrollController.header = header
scrollController.overKeyboardContainer = overKeyboardContainer
scrollController.bottomContainer = bottomContainer
setupEssentialUI()
subscribeToRedux()

updateToolbarStateForTraitCollection(traitCollection)
Task(priority: .background) {
// App startup telemetry accesses RustLogins to queryLogins, shouldn't be on the app startup critical path
self.trackStartupTelemetry()
}
}

private func setupEssentialUI() {
addSubviews()
setupConstraints()

// Setup UIDropInteraction to handle dragging and dropping
// links into the view from other apps.
let dropInteraction = UIDropInteraction(delegate: self)
view.addInteraction(dropInteraction)

searchTelemetry = SearchTelemetry(tabManager: tabManager)

// Awesomebar Location Telemetry
SearchBarSettingsViewModel.recordLocationTelemetry(for: isBottomSearchBar ? .bottom : .top)
setupNotifications()

overlayManager.setURLBar(urlBarView: urlBarView)

Expand All @@ -787,20 +773,31 @@ class BrowserViewController: UIViewController,
statusBarOverlay.hasTopTabs = ToolbarHelper().shouldShowTopTabs(for: traitCollection)
statusBarOverlay.applyTheme(theme: theme)

KeyboardHelper.defaultHelper.addDelegate(self)
listenForThemeChange(view)
setupAccessibleActions()

clipboardBarDisplayHandler = ClipboardBarDisplayHandler(prefs: profile.prefs,
tabManager: tabManager)
clipboardBarDisplayHandler?.delegate = self

navigationToolbarContainer.toolbarDelegate = self
scrollController.header = header
scrollController.overKeyboardContainer = overKeyboardContainer
scrollController.bottomContainer = bottomContainer

// Setup UIDropInteraction to handle dragging and dropping
// links into the view from other apps.
let dropInteraction = UIDropInteraction(delegate: self)
view.addInteraction(dropInteraction)

// Feature flag for credit card until we fully enable this feature
let autofillCreditCardStatus = featureFlags.isFeatureEnabled(
.creditCardAutofillStatus, checking: .buildOnly)
// We need to update autofill status on sync manager as there could be delay from nimbus
// in getting the value. When the delay happens the credit cards might not sync
// as the default value is false
profile.syncManager?.updateCreditCardAutofillStatus(value: autofillCreditCardStatus)
// Credit card initial setup telemetry
creditCardInitialSetupTelemetry()

// Send settings telemetry for Fakespot
FakespotUtils().addSettingTelemetry()

subscribeToRedux()
}

private func setupAccessibleActions() {
Expand Down Expand Up @@ -4362,10 +4359,14 @@ extension BrowserViewController: DevicePickerViewControllerDelegate, Instruction
}

extension BrowserViewController {
func trackTelemetry() {
func trackStartupTelemetry() {
let toolbarLocation: SearchBarPosition = self.isBottomSearchBar ? .bottom : .top
SearchBarSettingsViewModel.recordLocationTelemetry(for: toolbarLocation)
trackAccessibility()
trackNotificationPermission()
appStartupTelemetry.sendStartupTelemetry()
creditCardInitialSetupTelemetry()
FakespotUtils().addSettingTelemetry()
}

func trackAccessibility() {
Expand Down Expand Up @@ -4401,15 +4402,17 @@ extension BrowserViewController {
extras: [Key.isInvertColorsEnabled.rawValue: UIAccessibility.isInvertColorsEnabled.description]
)

let a11yEnabled = UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory.description
let a11yCategory = UIApplication.shared.preferredContentSizeCategory.rawValue.description
TelemetryWrapper.recordEvent(
category: .action,
method: .dynamicTextSize,
object: .app,
extras: [Key.isAccessibilitySizeEnabled.rawValue: a11yEnabled,
Key.preferredContentSizeCategory.rawValue: a11yCategory]
)
ensureMainThread {
let a11yEnabled = UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory.description
let a11yCategory = UIApplication.shared.preferredContentSizeCategory.rawValue.description
TelemetryWrapper.recordEvent(
category: .action,
method: .dynamicTextSize,
object: .app,
extras: [Key.isAccessibilitySizeEnabled.rawValue: a11yEnabled,
Key.preferredContentSizeCategory.rawValue: a11yCategory]
)
}
}

func trackNotificationPermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Shared
/// Data source for handling LoginData objects from a Cursor
class LoginDataSource: NSObject, UITableViewDataSource {
// in case there are no items to run cellForRowAt on, use an empty state view
private let emptyStateView = NoLoginsView()
private lazy var emptyStateView = NoLoginsView()
var viewModel: PasswordManagerViewModel

let boolSettings: (BoolSetting, BoolSetting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class PasswordManagerViewModel {
var hasLoadedBreaches = false
var theme: Theme

init(profile: Profile, searchController: UISearchController, theme: Theme, loginProvider: LoginProvider) {
init(profile: Profile, searchController: UISearchController?, theme: Theme, loginProvider: LoginProvider) {
self.profile = profile
self.searchController = searchController
self.theme = theme
Expand Down
3 changes: 1 addition & 2 deletions firefox-ios/Client/Telemetry/AppStartupTelemetry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ final class AppStartupTelemetry {

// MARK: Logins
func queryLogins() {
let searchController = UISearchController()
let loginsViewModel = PasswordManagerViewModel(
profile: profile,
searchController: searchController,
searchController: nil,
theme: LightTheme(),
loginProvider: profile.logins
)
Expand Down

0 comments on commit ac020c0

Please sign in to comment.