Improve startup UX with placeholders and prefetch

This commit is contained in:
Micha
2025-11-19 23:28:12 +01:00
parent 562023519a
commit 6b8d458605
4 changed files with 150 additions and 31 deletions

View File

@@ -0,0 +1,51 @@
import SwiftUI
struct ShimmerModifier: ViewModifier {
var active: Bool
@State private var phase: CGFloat = -1
func body(content: Content) -> some View {
content
.overlay(
shimmer
.mask(content)
.opacity(active ? 1 : 0)
)
.onAppear {
guard active else { return }
animate()
}
.onChange(of: active) { isActive in
if isActive {
phase = -1
animate()
}
}
}
private var shimmer: some View {
LinearGradient(
gradient: Gradient(colors: [
.clear,
Color.white.opacity(0.6),
.clear
]),
startPoint: .top,
endPoint: .bottom
)
.rotationEffect(.degrees(70))
.offset(x: phase * 250)
}
private func animate() {
withAnimation(.linear(duration: 1.2).repeatForever(autoreverses: false)) {
phase = 1
}
}
}
extension View {
func shimmering(active: Bool) -> some View {
modifier(ShimmerModifier(active: active))
}
}