File tree 3 files changed +54
-2
lines changed
3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ struct ExampleView: View {
51
51
. setSkeleton (
52
52
self . $isSkeletonActive,
53
53
animation: Animation . default,
54
- transition: AnyTransition . opacity
54
+ transition: AnyTransition . opacity,
55
+ cornerRadius: 12
55
56
)
56
57
57
58
self . skeletonControlButton
Original file line number Diff line number Diff line change @@ -110,11 +110,13 @@ public extension View {
110
110
_ isActive: Binding < Bool > ,
111
111
animationType: SkeletonData . AnimationType = . gradient( Color . skeleton. makeGradient ( ) ) ,
112
112
animation: Animation ? = nil ,
113
- transition: AnyTransition ? = nil
113
+ transition: AnyTransition ? = nil ,
114
+ cornerRadius: CGFloat = 0
114
115
) -> some View {
115
116
self . transformEnvironment ( \. skeleton) { skeleton in
116
117
skeleton. skeletonActive = isActive. animation ( animation)
117
118
skeleton. animationType = animationType
119
+ skeleton. cornerRadius = cornerRadius
118
120
animation. flatMap { skeleton. animation = $0 }
119
121
transition. flatMap { skeleton. transition = $0 }
120
122
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments