Skip to content

Instantly share code, notes, and snippets.

@thexande
Created July 11, 2020 19:39
Show Gist options
  • Save thexande/98ccc93ef169d230fa14737114f88f8e to your computer and use it in GitHub Desktop.
Save thexande/98ccc93ef169d230fa14737114f88f8e to your computer and use it in GitHub Desktop.
A Swift UI playground displaying a bug when using geometry reader in lazy v grid.
import SwiftUI
import PlaygroundSupport
let ipsum = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
extension CGFloat {
static var random: CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
}
extension UIColor {
static var random: UIColor {
return UIColor(red: .random, green: .random, blue: .random, alpha: 1.0)
}
}
struct Main: View {
var body: some View {
ScrollView {
LazyVGrid(columns: .init(repeating: .init(.flexible()), count: 2)) {
ForEach(0..<6) { _ in
ZStack {
Rectangle()
.foregroundColor(Color(UIColor.random))
VStack {
Rectangle()
.frame(minHeight: 72)
Text(ipsum)
.fixedSize(horizontal: false, vertical: true)
.padding()
}
}.clipShape(RoundedRectangle(cornerRadius: 10))
}
}.padding()
}.frame(width: 400, height: 600)
}
}
PlaygroundPage.current.setLiveView(Main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment