mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-23 06:46:03 +00:00
Fix ToastView progress bar animation
This commit is contained in:
1 parent
0112e512c0
commit
80b81ae228
1 file changed
+27
-2
@@ -13,10 +13,12 @@ let toastViewSize = CGSize(width: 340, height: 65)
|
|||||||
let toastCornerRadius: CGFloat = 22
|
let toastCornerRadius: CGFloat = 22
|
||||||
let toastTrailingPadding: CGFloat = 20
|
let toastTrailingPadding: CGFloat = 20
|
||||||
let toastSlideDistance: CGFloat = 420
|
let toastSlideDistance: CGFloat = 420
|
||||||
|
let toastSlideAnimationDuration: TimeInterval = 0.5
|
||||||
|
|
||||||
struct QuickDropToastView: View {
|
struct QuickDropToastView: View {
|
||||||
@ObservedObject var settings = Settings.sharedInstance
|
@ObservedObject var settings = Settings.sharedInstance
|
||||||
@ObservedObject var receiveModel: ReceiveModel
|
@ObservedObject var receiveModel: ReceiveModel
|
||||||
|
let animateProgressVisibility: Bool
|
||||||
|
|
||||||
@Environment(\.colorScheme) var colorScheme
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
@@ -28,9 +30,11 @@ struct QuickDropToastView: View {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
receiveModel: ReceiveModel,
|
receiveModel: ReceiveModel,
|
||||||
|
animateProgressVisibility: Bool = true,
|
||||||
onCancel: @escaping () -> Void = {}
|
onCancel: @escaping () -> Void = {}
|
||||||
) {
|
) {
|
||||||
self.receiveModel = receiveModel
|
self.receiveModel = receiveModel
|
||||||
|
self.animateProgressVisibility = animateProgressVisibility
|
||||||
self.onCancel = onCancel
|
self.onCancel = onCancel
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +138,12 @@ struct QuickDropToastView: View {
|
|||||||
CapsuleProgress(value: progress)
|
CapsuleProgress(value: progress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.animation(.easeInOut, value: receiveModel.progress == nil)
|
.animation(
|
||||||
|
animateProgressVisibility
|
||||||
|
? .easeInOut
|
||||||
|
: .easeInOut.delay(toastSlideAnimationDuration),
|
||||||
|
value: receiveModel.progress == nil
|
||||||
|
)
|
||||||
|
|
||||||
Button(action: onCancel) {
|
Button(action: onCancel) {
|
||||||
Image(systemName: "xmark")
|
Image(systemName: "xmark")
|
||||||
@@ -286,6 +295,7 @@ struct QuickDropToastHostView: View {
|
|||||||
let onCancel: () -> Void
|
let onCancel: () -> Void
|
||||||
|
|
||||||
@State private var didRenderOnce = false
|
@State private var didRenderOnce = false
|
||||||
|
@State private var hasFinishedSlideIn = false
|
||||||
|
|
||||||
private let slideAnimation = Animation.smooth
|
private let slideAnimation = Animation.smooth
|
||||||
private let fadeAnimation = Animation.easeInOut
|
private let fadeAnimation = Animation.easeInOut
|
||||||
@@ -298,7 +308,11 @@ struct QuickDropToastHostView: View {
|
|||||||
let hiddenBlur: CGFloat = isSlide ? 0 : 8
|
let hiddenBlur: CGFloat = isSlide ? 0 : 8
|
||||||
let animation = isSlide ? slideAnimation : fadeAnimation
|
let animation = isSlide ? slideAnimation : fadeAnimation
|
||||||
|
|
||||||
QuickDropToastView(receiveModel: receiveModel, onCancel: onCancel)
|
QuickDropToastView(
|
||||||
|
receiveModel: receiveModel,
|
||||||
|
animateProgressVisibility: hasFinishedSlideIn,
|
||||||
|
onCancel: onCancel
|
||||||
|
)
|
||||||
.frame(width: toastViewSize.width, height: toastViewSize.height)
|
.frame(width: toastViewSize.width, height: toastViewSize.height)
|
||||||
.offset(x: isVisible ? 0 : hiddenOffset)
|
.offset(x: isVisible ? 0 : hiddenOffset)
|
||||||
.opacity(isVisible ? 1 : hiddenOpacity)
|
.opacity(isVisible ? 1 : hiddenOpacity)
|
||||||
@@ -314,7 +328,18 @@ struct QuickDropToastHostView: View {
|
|||||||
didRenderOnce = true
|
didRenderOnce = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.task(id: isVisible) {
|
||||||
|
hasFinishedSlideIn = !isVisible || !isSlide
|
||||||
|
|
||||||
|
guard isVisible, isSlide else { return }
|
||||||
|
|
||||||
|
try? await Task.sleep(nanoseconds: UInt64(toastSlideAnimationDuration * 1_000_000_000))
|
||||||
|
guard !Task.isCancelled else { return }
|
||||||
|
|
||||||
|
hasFinishedSlideIn = true
|
||||||
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
|
hasFinishedSlideIn = false
|
||||||
didRenderOnce = false
|
didRenderOnce = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user