Last active
July 24, 2019 12:12
-
-
Save bok-/7112f1a39de7c0a67054ba745d94af92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// GridTest.swift | |
// | |
import SwiftUI | |
struct GridTest: View { | |
var items: [String] | |
var body: some View { | |
NavigationView { | |
List { | |
ForEach(0..<3) { index in | |
GeometryReader { geometry in | |
HStack { | |
self.items[safe: index * 2] | |
.map { | |
Text($0) | |
.frame(width: geometry.size.width / 2, height: geometry.size.width / 2) | |
} | |
self.items[safe: index * 2 + 1] | |
.map { | |
Text($0) | |
.frame(width: geometry.size.width / 2, height: geometry.size.width / 2) | |
} | |
} | |
} | |
} | |
} | |
.listStyle(.grouped) | |
.navigationBarTitle("Grid Test", displayMode: .inline) | |
} | |
} | |
} | |
#if DEBUG | |
struct GridTest_Previews: PreviewProvider { | |
static var previews: some View { | |
GridTest(items: [ "First Label", "Second Label", "Third Label", "Fourth Label", "Fifth Label" ]) | |
} | |
} | |
#endif | |
extension Collection { | |
subscript(safe index: Index) -> Iterator.Element? { | |
guard index >= startIndex && index < endIndex else { return nil } | |
return self[index] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment