Skip to content

Commit

Permalink
Refactor FXIOS-11245 Replace ActionToast usage in RemoteTabsTableView…
Browse files Browse the repository at this point in the history
…Controller with ButtonToast (#24475)

* Replace ActionToast with ButtonToast

* Fixed indentation for ButtonToastViewModel declaration

* Fix toast appearing unexpectedly after tab deletion

* make buttonToast and show method private after feedback
  • Loading branch information
bmihai23 authored Feb 4, 2025
1 parent b4f3172 commit bfe841a
Showing 1 changed file with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class RemoteTabsTableViewController: UITableViewController,
return UILongPressGestureRecognizer(target: self, action: #selector(longPress))
}()

private var buttonToast: ButtonToast?

// MARK: - Initializer

init(state: RemoteTabsPanelState,
Expand Down Expand Up @@ -155,6 +157,24 @@ class RemoteTabsTableViewController: UITableViewController,
emptyView.applyTheme(theme: themeManager.getCurrentTheme(for: windowUUID))
}

private func show(toast: Toast,
afterWaiting delay: DispatchTimeInterval = Toast.UX.toastDelayBefore,
duration: DispatchTimeInterval? = Toast.UX.toastDismissAfter) {
if let buttonToast = toast as? ButtonToast {
self.buttonToast = buttonToast
}

toast.showToast(viewController: self, delay: delay, duration: duration) { toast in
[
toast.leadingAnchor.constraint(equalTo: self.view.leadingAnchor,
constant: Toast.UX.toastSidePadding),
toast.trailingAnchor.constraint(equalTo: self.view.trailingAnchor,
constant: -Toast.UX.toastSidePadding),
toast.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor)
]
}
}

// MARK: - Refreshing TableView

func addRefreshControl() {
Expand Down Expand Up @@ -316,13 +336,16 @@ class RemoteTabsTableViewController: UITableViewController,

// Creating a modal with an undo button that will allow the user to undo closing the last remote tab
// they attempted to close
ActionToast(
text: .TabsTray.CloseTabsToast.SingleTabTitle,
bottomContainer: view,
theme: themeManager.getCurrentTheme(for: windowUUID),
buttonTitle: .UndoString,
buttonAction: self.undo
).show()
let viewModel = ButtonToastViewModel(labelText: .TabsTray.CloseTabsToast.SingleTabTitle,
buttonText: .UndoString)
let toast = ButtonToast(viewModel: viewModel,
theme: themeManager.getCurrentTheme(for: windowUUID),
completion: { didTapUndoButton in
if didTapUndoButton {
self.undo()
}
})
show(toast: toast)

self.remoteTabsPanel?.remoteTabsClientAndTabsDataSourceDidCloseURL(deviceId: fxaDeviceId, url: tab.URL)

Expand Down

0 comments on commit bfe841a

Please sign in to comment.