Skip to content

Instantly share code, notes, and snippets.

@karigrooms
Created February 24, 2021 00:10
Show Gist options
  • Save karigrooms/acfe310fb82fc16f46a0e7831fb87552 to your computer and use it in GitHub Desktop.
Save karigrooms/acfe310fb82fc16f46a0e7831fb87552 to your computer and use it in GitHub Desktop.
Blog post: SwiftUI with UICollectionView - 14. Do not use @State inside of a SwiftUI View embedded in a UICollectionViewCell
import SwiftUI
struct Card: View {
typealias Content = CardContent
let content: Content
@State var isHearted: Bool = false
var body: some View {
ZStack(alignment: .topTrailing) {
VStack(alignment: .leading, spacing: 8) {
Image(content.imageName)
.fitToAspectRatio(3/2) // https://gist.github.com/karigrooms/fdf435274f4403abd57b1ed533dcea53
.clipShape(RoundedRectangle(cornerRadius: 4))
Text(content.title)
.font(.headline)
Text(content.description)
.font(.body)
.lineLimit(1)
}
HeartButton(isHearted: isHearted, action: {
self.isHearted.toggle()
}).padding()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment