Skip to content

Commit

Permalink
Fix for CSolanaM#36
Browse files Browse the repository at this point in the history
Two SkeletonForEach in a LazyVGrid causes duplicate IDs
  • Loading branch information
Viktor-by committed Jul 31, 2024
1 parent f025e9b commit de7d906
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ public extension View {
.animation(transition.animation, value: loading)
}
}

extension View {
@ViewBuilder func `if`<T>(_ condition: Bool, transform: (Self) -> T) -> some View where T : View {
if condition {
transform(self)
} else {
self
}
}
}
1 change: 1 addition & 0 deletions Sources/SkeletonUI/Skeleton/SkeletonForEach.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public struct SkeletonForEach<Data, Content>: 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()) }
}
}
}

0 comments on commit de7d906

Please sign in to comment.