Less fallback images, dont use shimmering view

This commit is contained in:
Jackson Harper
2023-12-07 16:50:48 +08:00
parent cde5d616e8
commit 80d48094ee
3 changed files with 6 additions and 81 deletions

View File

@ -606,12 +606,7 @@ struct AnimatingCellHeight: AnimatableModifier {
var body: some View {
let horizontalInset = CGFloat(UIDevice.isIPad ? 20 : 10)
VStack(spacing: 0) {
if viewModel.showLoadingBar {
ShimmeringLoader()
} else {
Spacer(minLength: 2)
}
Color.systemBackground.frame(height: 1)
ScrollViewReader { reader in
List(selection: $selection) {
Section(content: {
@ -851,12 +846,7 @@ struct AnimatingCellHeight: AnimatableModifier {
var body: some View {
VStack(alignment: .leading) {
if viewModel.showLoadingBar {
ShimmeringLoader()
} else {
Spacer(minLength: 2)
}
Color.systemBackground.frame(height: 1)
filtersHeader
.onAppear {
withAnimation {

View File

@ -256,27 +256,16 @@ public struct LibraryItemCard: View {
}
}
} else {
fallbackImage
Color.clear
.frame(width: 50, height: 75)
.cornerRadius(5)
.padding(.top, 2)
}
}
.padding(.top, 10)
.cornerRadius(5)
}
var fallbackImage: some View {
HStack {
Text(item.unwrappedTitle.prefix(1))
.font(Font.system(size: 32, weight: .bold))
.frame(alignment: .bottomLeading)
.foregroundColor(Gradient.randomColor(str: item.unwrappedTitle, offset: 1))
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Gradient.randomColor(str: item.unwrappedTitle, offset: 0))
.background(LinearGradient(gradient: Gradient(fromStr: item.unwrappedTitle)!, startPoint: .top, endPoint: .bottom))
.cornerRadius(5)
.frame(width: 50, height: 75)
}
var bylineStr: String {
// It seems like it could be cleaner just having author, instead of
// concating, maybe we fall back

View File

@ -1,54 +0,0 @@
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)
}
}
}