diff --git a/Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift b/Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift index 4b47204..8ec1421 100644 --- a/Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift +++ b/Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift @@ -31,3 +31,13 @@ public extension View { .animation(transition.animation, value: loading) } } + +extension View { + @ViewBuilder func `if`(_ condition: Bool, transform: (Self) -> T) -> some View where T : View { + if condition { + transform(self) + } else { + self + } + } +} diff --git a/Sources/SkeletonUI/Skeleton/SkeletonForEach.swift b/Sources/SkeletonUI/Skeleton/SkeletonForEach.swift index 7e5d3d8..bd569cd 100644 --- a/Sources/SkeletonUI/Skeleton/SkeletonForEach.swift +++ b/Sources/SkeletonUI/Skeleton/SkeletonForEach.swift @@ -15,6 +15,7 @@ public struct SkeletonForEach: View where Data: RandomAccessColle public var body: some View { ForEach(0 ..< (data.isEmpty ? quantity : data.count), id: \.self) { index in self.content(self.data.isEmpty, self.data.isEmpty ? nil : self.data.map { $0 }[index]) + .if(self.data.isEmpty) { $0.id(UUID()) } } } }