From 3812b5821ca3b7d225d6be00394c923a3d21698b Mon Sep 17 00:00:00 2001 From: Christopher Brind Date: Thu, 5 Sep 2024 14:38:36 +0100 Subject: [PATCH] defer loading the tab switcher button until view did load (#3326) Task/Issue URL: https://app.asana.com/0/414709148257752/1208092544762425/f Tech Design URL: CC: @bwaresiak **Description**: Defer loading the tab switcher button until view did load to avoid Lottie trying to do something with the view hierarchy when not available. **Steps to test this PR**: 1. On the phone, open, close and re-order tabs. Make sure tab switcher button reflects correct state. 3. On the iPad, open, close and re-order tabs. Make sure tab switcher button reflects correct state. 4. Enable "app lock" from settings. Background app. Ensure blank snapshot view is correct. Foreground app and open / close tabs. 5. Launch the app using a link from cold and while in the background. --- DuckDuckGo/BlankSnapshotViewController.swift | 4 +++- DuckDuckGo/MainViewController.swift | 5 +++-- DuckDuckGo/TabsBarViewController.swift | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/DuckDuckGo/BlankSnapshotViewController.swift b/DuckDuckGo/BlankSnapshotViewController.swift index 14ccee9272..ab4c6b2471 100644 --- a/DuckDuckGo/BlankSnapshotViewController.swift +++ b/DuckDuckGo/BlankSnapshotViewController.swift @@ -35,7 +35,7 @@ class BlankSnapshotViewController: UIViewController { let menuButton = MenuButton() - let tabSwitcherButton = TabSwitcherButton() + var tabSwitcherButton: TabSwitcherButton! let appSettings: AppSettings var viewCoordinator: MainViewCoordinator! @@ -54,6 +54,8 @@ class BlankSnapshotViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + tabSwitcherButton = TabSwitcherButton() + viewCoordinator = MainViewFactory.createViewHierarchy(view) if appSettings.currentAddressBarPosition.isBottom { viewCoordinator.moveAddressBarToPosition(.bottom) diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index a17d4fed82..ca18ab0e12 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -136,8 +136,8 @@ class MainViewController: UIViewController { }() weak var tabSwitcherController: TabSwitcherViewController? - let tabSwitcherButton = TabSwitcherButton() - + var tabSwitcherButton: TabSwitcherButton! + /// Do not reference directly, use `presentedMenuButton` let menuButton = MenuButton() var presentedMenuButton: MenuButton { @@ -639,6 +639,7 @@ class MainViewController: UIViewController { } private func initTabButton() { + tabSwitcherButton = TabSwitcherButton() tabSwitcherButton.delegate = self viewCoordinator.toolbarTabSwitcherButton.customView = tabSwitcherButton viewCoordinator.toolbarTabSwitcherButton.isAccessibilityElement = true diff --git a/DuckDuckGo/TabsBarViewController.swift b/DuckDuckGo/TabsBarViewController.swift index ce8e51325e..317efa98a9 100644 --- a/DuckDuckGo/TabsBarViewController.swift +++ b/DuckDuckGo/TabsBarViewController.swift @@ -52,7 +52,7 @@ class TabsBarViewController: UIViewController { weak var delegate: TabsBarDelegate? private weak var tabsModel: TabsModel? - let tabSwitcherButton = TabSwitcherButton() + var tabSwitcherButton: TabSwitcherButton! private let longPressTabGesture = UILongPressGestureRecognizer() private weak var pressedCell: TabsBarCell? @@ -72,6 +72,8 @@ class TabsBarViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + tabSwitcherButton = TabSwitcherButton() + decorate() tabSwitcherButton.delegate = self