Skip to content

Commit 0047954

Browse files
author
Vladislav Prusakov
authored
Merge pull request #2 from OmarJalilo/main
Add List Skeleton and modifiable Corner Radius
2 parents b8fd68a + 4730e4e commit 0047954

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

Example/Example/ExampleView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct ExampleView: View {
5151
.setSkeleton(
5252
self.$isSkeletonActive,
5353
animation: Animation.default,
54-
transition: AnyTransition.opacity
54+
transition: AnyTransition.opacity,
55+
cornerRadius: 12
5556
)
5657

5758
self.skeletonControlButton

Sources/EasySkeleton/EasySkeleton.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ public extension View {
110110
_ isActive: Binding<Bool>,
111111
animationType: SkeletonData.AnimationType = .gradient(Color.skeleton.makeGradient()),
112112
animation: Animation? = nil,
113-
transition: AnyTransition? = nil
113+
transition: AnyTransition? = nil,
114+
cornerRadius: CGFloat = 0
114115
) -> some View {
115116
self.transformEnvironment(\.skeleton) { skeleton in
116117
skeleton.skeletonActive = isActive.animation(animation)
117118
skeleton.animationType = animationType
119+
skeleton.cornerRadius = cornerRadius
118120
animation.flatMap { skeleton.animation = $0 }
119121
transition.flatMap { skeleton.transition = $0 }
120122
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// List+Skeleton.swift
3+
//
4+
//
5+
// Created by Jalil Fierro on 23/07/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct SkeletonListModifier<V: View>: ViewModifier {
11+
12+
@Environment(\.skeleton) private var skeleton
13+
14+
let itemsCount: Int
15+
let autoSkeletonable: Bool
16+
@ViewBuilder var content: (Int) -> V
17+
18+
@ViewBuilder
19+
func body(content: Content) -> some View {
20+
if skeleton.isSkeletonActive {
21+
List(0..<itemsCount, id: \.self) { index in
22+
if autoSkeletonable {
23+
self.content(index)
24+
.skeletonable()
25+
} else {
26+
self.content(index)
27+
}
28+
}
29+
} else {
30+
content
31+
}
32+
}
33+
}
34+
35+
public extension List where Content: View {
36+
func skeletonList<V: View>(
37+
itemsCount: Int,
38+
autoSkeletonable: Bool = true,
39+
@ViewBuilder content: @escaping (Int) -> V
40+
) -> some View {
41+
self.modifier(
42+
SkeletonListModifier(
43+
itemsCount: itemsCount,
44+
autoSkeletonable: autoSkeletonable,
45+
content: content
46+
)
47+
)
48+
}
49+
}

0 commit comments

Comments
 (0)