mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add a shimmering loader
This commit is contained in:
parent
c57b0bd415
commit
60aa05c567
2 changed files with 55 additions and 0 deletions
|
|
@ -155,6 +155,7 @@ private let enableGrid = UIDevice.isIPad || FeatureFlag.enableGridCardsOnPhone
|
|||
}
|
||||
}
|
||||
}
|
||||
ShimmeringLoader()
|
||||
if prefersListLayout || !enableGrid {
|
||||
HomeFeedListView(prefersListLayout: $prefersListLayout, viewModel: viewModel)
|
||||
} else {
|
||||
|
|
|
|||
54
apple/OmnivoreKit/Sources/Views/ShimmerView.swift
Normal file
54
apple/OmnivoreKit/Sources/Views/ShimmerView.swift
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import SwiftUI
|
||||
|
||||
public struct ShimmeringLoader: View {
|
||||
@State private var phase: CGFloat = 0
|
||||
|
||||
public init() {}
|
||||
|
||||
public var body: some View {
|
||||
ZStack {
|
||||
Color.systemBackground
|
||||
Color.appGraySolid
|
||||
.contentShape(Rectangle())
|
||||
.modifier(AnimatedMask(phase: phase).animation(
|
||||
Animation.linear(duration: 2.0)
|
||||
.repeatForever(autoreverses: false)
|
||||
))
|
||||
.onAppear { phase = 0.8 }
|
||||
}
|
||||
.frame(height: 2)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
/// An animatable modifier to interpolate between `phase` values.
|
||||
struct AnimatedMask: AnimatableModifier {
|
||||
var phase: CGFloat = 0
|
||||
|
||||
var animatableData: CGFloat {
|
||||
get { phase }
|
||||
set { phase = newValue }
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.mask(GradientMask(phase: phase).scaleEffect(3))
|
||||
}
|
||||
}
|
||||
|
||||
/// An animatable gradient between transparent and opaque to use as mask.
|
||||
/// The `phase` parameter shifts the gradient, moving the opaque band.
|
||||
struct GradientMask: View {
|
||||
let phase: CGFloat
|
||||
let centerColor = Color.appGraySolid
|
||||
let edgeColor = Color.clear
|
||||
|
||||
var body: some View {
|
||||
LinearGradient(gradient:
|
||||
Gradient(stops: [
|
||||
.init(color: edgeColor, location: phase),
|
||||
.init(color: centerColor, location: phase + 0.1),
|
||||
.init(color: edgeColor, location: phase + 0.2)
|
||||
]), startPoint: .leading, endPoint: .trailing)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue