Skip to content

Commit

Permalink
Merge branch 'main' into pm-13902/update-sdk-ssh-key
Browse files Browse the repository at this point in the history
  • Loading branch information
fedemkr committed Oct 29, 2024
2 parents 06153c7 + e956d81 commit 6528f5b
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 60 deletions.
3 changes: 2 additions & 1 deletion BitwardenShared/UI/Platform/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ extension AppCoordinator: SettingsCoordinatorDelegate {
navigate(to: .tab(.vault(.list)))
showToast(
Localizations.loginsImported,
subtitle: Localizations.rememberToDeleteYourImportedPasswordFileFromYourComputer
subtitle: Localizations.rememberToDeleteYourImportedPasswordFileFromYourComputer,
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

// MARK: - AnyCoordinator

/// A type erased wrapper for a coordinator.
Expand All @@ -20,8 +22,8 @@ open class AnyCoordinator<Route, Event>: Coordinator {
/// A closure that wraps the `showLoadingOverlay(_:)` method.
private let doShowLoadingOverlay: (LoadingOverlayState) -> Void

/// A closure that wraps the `showToast(title:subtitle:)` method.
private let doShowToast: (String, String?) -> Void
/// A closure that wraps the `showToast(title:subtitle:additionalBottomPadding:)` method.
private let doShowToast: (String, String?, CGFloat) -> Void

/// A closure that wraps the `start()` method.
private let doStart: () -> Void
Expand All @@ -44,7 +46,7 @@ open class AnyCoordinator<Route, Event>: Coordinator {
}
doShowAlert = { coordinator.showAlert($0, onDismissed: $1) }
doShowLoadingOverlay = { coordinator.showLoadingOverlay($0) }
doShowToast = { coordinator.showToast($0, subtitle: $1) }
doShowToast = { coordinator.showToast($0, subtitle: $1, additionalBottomPadding: $2) }
doStart = { coordinator.start() }
}

Expand Down Expand Up @@ -74,8 +76,8 @@ open class AnyCoordinator<Route, Event>: Coordinator {
doHideLoadingOverlay()
}

open func showToast(_ title: String, subtitle: String? = nil) {
doShowToast(title, subtitle)
open func showToast(_ title: String, subtitle: String? = nil, additionalBottomPadding: CGFloat = 0) {
doShowToast(title, subtitle, additionalBottomPadding)
}

open func start() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

/// A protocol for an object that performs navigation via routes.
@MainActor
public protocol Coordinator<Route, Event>: AnyObject {
Expand Down Expand Up @@ -52,9 +54,10 @@ public protocol Coordinator<Route, Event>: AnyObject {
///
/// - Parameters:
/// - title: The title text displayed in the toast.
/// - title: The subtitle text displayed in the toast.
/// - subtitle: The subtitle text displayed in the toast.
/// - additionalBottomPadding: Additional padding to apply to the bottom of the toast.
///
func showToast(_ title: String, subtitle: String?)
func showToast(_ title: String, subtitle: String?, additionalBottomPadding: CGFloat)

/// Starts the coordinator, displaying its content.
///
Expand Down Expand Up @@ -176,10 +179,18 @@ extension Coordinator where Self: HasNavigator {
///
/// - Parameters:
/// - title: The title text displayed in the toast.
/// - title: The subtitle text displayed in the toast.
///
func showToast(_ title: String, subtitle: String? = nil) {
navigator?.showToast(Toast(title: title, subtitle: subtitle))
/// - subtitle: The subtitle text displayed in the toast.
/// - additionalBottomPadding: Additional padding to apply to the bottom of the toast.
///
func showToast(
_ title: String,
subtitle: String? = nil,
additionalBottomPadding: CGFloat = 0
) {
navigator?.showToast(
Toast(title: title, subtitle: subtitle),
additionalBottomPadding: additionalBottomPadding
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ extension Navigator {

/// Shows the toast.
///
/// - Parameter toast: The toast to display.
/// - Parameters:
/// - toast: The toast to display.
/// - additionalBottomPadding: Additional padding to apply to the bottom of the toast.
///
func showToast(_ toast: Toast) {
func showToast(_ toast: Toast, additionalBottomPadding: CGFloat = 0) {
guard let rootViewController else { return }
ToastDisplayHelper.show(in: rootViewController, toast: toast)
ToastDisplayHelper.show(
in: rootViewController,
toast: toast,
additionalBottomPadding: additionalBottomPadding
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ enum ToastDisplayHelper {
/// - Parameters:
/// - parentViewController: The parent view controller that the toast should be shown above.
/// - toast: The toast to display.
/// - additionalBottomPadding: Additional padding to apply to the bottom of the toast.
/// - duration: The number of seconds the toast should display for.
///
static func show(in parentViewController: UIViewController, toast: Toast, duration: TimeInterval = 3) {
static func show(
in parentViewController: UIViewController,
toast: Toast,
additionalBottomPadding: CGFloat = 0,
duration: TimeInterval = 3
) {
guard parentViewController.view.window?.viewWithTag(toastTag) == nil,
let window = parentViewController.view.window
else { return }
Expand All @@ -33,7 +39,7 @@ enum ToastDisplayHelper {

// Position the toast view on the window with appropriate bottom padding above the tab bar.
window.addSubview(viewController.view)
let bottomPadding = getSafeArea(from: parentViewController).bottom + 16
let bottomPadding = getSafeArea(from: parentViewController).bottom + 16 + additionalBottomPadding
viewController.view.translatesAutoresizingMaskIntoConstraints = false
viewController.view.bottomAnchor.constraint(equalTo: window.bottomAnchor, constant: -bottomPadding)
.isActive = true
Expand Down
15 changes: 10 additions & 5 deletions BitwardenShared/UI/Platform/Application/Views/ToastView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ struct ToastView: View {
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
.id(toast.id)
.padding(.horizontal, 16)
.padding(.vertical, 14)
.padding(.vertical, 12)
.foregroundColor(Asset.Colors.textReversed.swiftUIColor)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Asset.Colors.backgroundAlert.swiftUIColor)
.clipShape(RoundedRectangle(cornerRadius: 8))
.shadow(color: .black.opacity(0.1), radius: 8, x: 0, y: 2)
.shadow(color: .black.opacity(0.05), radius: 4, x: 0, y: 4)
.accessibilityElement(children: .combine)
.padding(.horizontal, 16)
.padding(.horizontal, 12)
.task(id: toast.id) {
do {
try await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
Expand All @@ -85,6 +85,9 @@ struct ToastView: View {
// No-op: Skip the animation if the task/sleep is cancelled.
}
}
.onDisappear {
self.toast = nil
}
}
}
}
Expand All @@ -94,13 +97,15 @@ struct ToastView: View {
extension View {
/// Adds a toast view in an overlay at the bottom of the view.
///
/// - Parameter toast: A binding to the toast to show.
/// - Parameters:
/// - toast: A binding to the toast to show.
/// - additionalBottomPadding: Additional bottom padding to apply to the toast.
/// - Returns: A view that displays a toast.
///
func toast(_ toast: Binding<Toast?>) -> some View {
func toast(_ toast: Binding<Toast?>, additionalBottomPadding: CGFloat = 0) -> some View {
overlay(alignment: .bottom) {
ToastView(toast: toast)
.padding(.bottom, 28)
.padding(.bottom, 12 + additionalBottomPadding)
.animation(.easeInOut, value: toast.wrappedValue)
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ struct FoldersView: View {
.task {
await store.perform(.streamFolders)
}
.toast(store.binding(
get: \.toast,
send: FoldersAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: FoldersAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
}

// MARK: Private views
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions BitwardenShared/UI/Tools/Send/Send/SendList/SendListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,13 @@ struct SendListView: View {
store.send(.addItemPressed)
}
}
.toast(store.binding(
get: \.toast,
send: SendListAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: SendListAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
.task { await store.perform(.loadData) }
.task { await store.perform(.streamSendList) }
.task(id: store.state.searchText) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ private struct VaultAutofillListSearchableView: View {
.task(id: store.state.searchText) {
await store.perform(.search(store.state.searchText))
}
.toast(store.binding(
get: \.toast,
send: VaultAutofillListAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: VaultAutofillListAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
}

// MARK: Private Views
Expand Down
3 changes: 2 additions & 1 deletion BitwardenShared/UI/Vault/Vault/VaultCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ extension VaultCoordinator: ImportLoginsCoordinatorDelegate {
stackNavigator?.dismiss {
self.showToast(
Localizations.loginsImported,
subtitle: Localizations.rememberToDeleteYourImportedPasswordFileFromYourComputer
subtitle: Localizations.rememberToDeleteYourImportedPasswordFileFromYourComputer,
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
}
}
Expand Down
11 changes: 7 additions & 4 deletions BitwardenShared/UI/Vault/Vault/VaultGroup/VaultGroupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ struct VaultGroupView: View {
.task {
await store.perform(.streamShowWebIcons)
}
.toast(store.binding(
get: \.toast,
send: VaultGroupAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: VaultGroupAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
}

// MARK: Private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ private struct VaultItemSelectionSearchableView: View {
.task(id: store.state.searchText) {
await store.perform(.search(store.state.searchText))
}
.toast(store.binding(
get: \.toast,
send: VaultItemSelectionAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: VaultItemSelectionAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
.background(Color(asset: Asset.Colors.backgroundPrimary).ignoresSafeArea())
}

Expand Down
19 changes: 7 additions & 12 deletions BitwardenShared/UI/Vault/Vault/VaultList/VaultListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ private struct SearchableVaultListView: View {
.hidden(!isSearching)
}
.background(Asset.Colors.backgroundPrimary.swiftUIColor.ignoresSafeArea())
.toast(store.binding(
get: \.toast,
send: VaultListAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: VaultListAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
.onChange(of: store.state.url) { newValue in
guard let url = newValue else { return }
openURL(url)
Expand All @@ -54,15 +57,7 @@ private struct SearchableVaultListView: View {
.onChange(of: isSearching) { newValue in
store.send(.searchStateChanged(isSearching: newValue))
}
.toast(store.binding(
get: \.toast,
send: VaultListAction.toastShown
))
.animation(.default, value: isSearching)
.toast(store.binding(
get: \.toast,
send: VaultListAction.toastShown
))
}

// MARK: Private Properties
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions BitwardenShared/UI/Vault/VaultItem/ViewItem/ViewItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ struct ViewItemView: View {
.background(Asset.Colors.backgroundPrimary.swiftUIColor.ignoresSafeArea())
.navigationTitle(navigationTitle)
.navigationBarTitleDisplayMode(.inline)
.toast(store.binding(
get: \.toast,
send: ViewItemAction.toastShown
))
.toast(
store.binding(
get: \.toast,
send: ViewItemAction.toastShown
),
additionalBottomPadding: FloatingActionButton.bottomOffsetPadding
)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
closeToolbarButton {
Expand Down
2 changes: 1 addition & 1 deletion GlobalTestHelpers/MockCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MockCoordinator<Route, Event>: Coordinator {
loadingOverlaysShown.append(state)
}

func showToast(_ title: String, subtitle: String?) {
func showToast(_ title: String, subtitle: String?, additionalBottomPadding: CGFloat) {
toastsShown.append(Toast(title: title, subtitle: subtitle))
}

Expand Down

0 comments on commit 6528f5b

Please sign in to comment.