Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions iOSClient/GUI/Lucid Banner/ErrorBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,37 @@
import SwiftUI
import LucidBanner

@MainActor
func showErrorBanner(controller: UITabBarController?, errorDescription: String, errorCode: Int, sleepBefore: Double = 1) async {
let scene = SceneManager.shared.getWindow(controller: controller)?.windowScene
await showErrorBanner(scene: scene, errorDescription: errorDescription, errorCode: errorCode, sleepBefore: sleepBefore)
}

@MainActor
func showErrorBanner(scene: UIWindowScene?, errorDescription: String, errorCode: Int, sleepBefore: Double = 1) async {
try? await Task.sleep(nanoseconds: UInt64(sleepBefore * 1e9))
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}

LucidBanner.shared.show(
scene: scene,
subtitle: errorDescription,
footnote: "(Code: \(errorCode))",
vPosition: .top,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
swipeToDismiss: true,
onTap: { _, _ in
LucidBanner.shared.dismiss()
}
) { state in
ErrorBannerView(state: state)
}
}

// MARK: - SwiftUI

struct ErrorBannerView: View {
@ObservedObject var state: LucidBannerState

Expand Down Expand Up @@ -53,56 +84,31 @@ struct ErrorBannerView: View {

@ViewBuilder
func containerView<Content: View>(@ViewBuilder _ content: () -> Content) -> some View {
let contentBase = content()
.contentShape(Rectangle())
.frame(maxWidth: 500)

if #available(iOS 26, *) {
content()
contentBase
.background(
RoundedRectangle(cornerRadius: 22)
.fill(Color.red.opacity(1))
)
.glassEffect(.regular, in: RoundedRectangle(cornerRadius: 22))
.frame(maxWidth: .infinity, alignment: .center)
} else {
content()
contentBase
.background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 22.0))
.overlay(
RoundedRectangle(cornerRadius: 22, style: .continuous)
.stroke(.white.opacity(0.9), lineWidth: 0.6)
)
.shadow(color: .black.opacity(0.5), radius: 10, x: 0, y: 4)
.frame(maxWidth: .infinity, alignment: .center)
}
}
}

// MARK: - Helper

@MainActor
func showErrorBanner(controller: UITabBarController?, errorDescription: String, errorCode: Int, sleepBefore: Double = 1) async {
let scene = SceneManager.shared.getWindow(controller: controller)?.windowScene
await showErrorBanner(scene: scene, errorDescription: errorDescription, errorCode: errorCode, sleepBefore: sleepBefore)
}

@MainActor
func showErrorBanner(scene: UIWindowScene?, errorDescription: String, errorCode: Int, sleepBefore: Double = 1) async {
try? await Task.sleep(nanoseconds: UInt64(sleepBefore * 1e9))
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}

LucidBanner.shared.show(
scene: scene,
subtitle: errorDescription,
footnote: "(Code: \(errorCode))",
vPosition: .top,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
swipeToDismiss: true,
onTap: { _, _ in
LucidBanner.shared.dismiss()
}
) { state in
ErrorBannerView(state: state)
}
}

// MARK: - Preview

#Preview {
Expand Down
94 changes: 47 additions & 47 deletions iOSClient/GUI/Lucid Banner/HudBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,53 @@
import SwiftUI
import LucidBanner

@MainActor
func showHudBanner(scene: UIWindowScene?, title: String? = nil, subtitle: String? = nil, onTap: ((_ token: Int?, _ stage: String?) -> Void)? = nil) -> Int? {
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}

return LucidBanner.shared.show(
scene: scene,
title: title,
subtitle: subtitle,
vPosition: .center,
blocksTouches: true,
onTap: { token, stage in
onTap?(token, stage)
}
) { state in
HudBannerView(state: state)
}
}

@MainActor
func completeHudBannerSuccess(
token: Int?
) {
LucidBanner.shared.update(
stage: .success,
autoDismissAfter: 2,
for: token
)
}

@MainActor
func completeHudBannerError(
subtitle: String? = nil,
token: Int?
) {
LucidBanner.shared.update(
subtitle: subtitle,
stage: .error,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
for: token
)
}

// MARK: - SwiftUI

struct HudBannerView: View {
@ObservedObject var state: LucidBannerState
@State private var displayedProgress: Double = 0
Expand Down Expand Up @@ -157,53 +204,6 @@ struct HudBannerView: View {
}
}

// MARK: - Helper

@MainActor
func showHudBanner(scene: UIWindowScene?, title: String? = nil, subtitle: String? = nil, onTap: ((_ token: Int?, _ stage: String?) -> Void)? = nil) -> Int? {
var scene = scene
if scene == nil {
scene = UIApplication.shared.mainAppWindow?.windowScene
}

return LucidBanner.shared.show(
scene: scene,
title: title,
subtitle: subtitle,
vPosition: .center,
blocksTouches: true,
onTap: { token, stage in
onTap?(token, stage)
}
) { state in
HudBannerView(state: state)
}
}

@MainActor
func completeHudBannerSuccess(
token: Int?
) {
LucidBanner.shared.update(
stage: .success,
autoDismissAfter: 2,
for: token
)
}

@MainActor
func completeHudBannerError(
subtitle: String? = nil,
token: Int?
) {
LucidBanner.shared.update(
subtitle: subtitle,
stage: .error,
autoDismissAfter: NCGlobal.shared.dismissAfterSecond,
for: token
)
}

// MARK: - Preview

#Preview("HudBannerView") {
Expand Down
Loading
Loading