Skip to content

Commit fdf27b1

Browse files
authored
Merge pull request #14 from juandahurt/h-grid
feat: add horizontal grid view
2 parents f413576 + 84bb7a2 commit fdf27b1

File tree

10 files changed

+315
-13
lines changed

10 files changed

+315
-13
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ let package = Package(
1414
],
1515
dependencies: [
1616
.package(url: "https://github.com/onevcat/Kingfisher.git", .upToNextMinor(from: "7.2.0")),
17+
.package(url: "https://github.com/GeorgeElsham/ViewExtractor", .branch("main")),
1718
],
1819
targets: [
1920
.target(
2021
name: "Purace",
21-
dependencies: ["Kingfisher"],
22+
dependencies: ["Kingfisher", "ViewExtractor"],
2223
resources: [
2324
.copy("Resources/Fonts/Poppins/Poppins-Regular.ttf"),
2425
.copy("Resources/Fonts/Poppins/Poppins-Medium.ttf"),

PuraceDemo/PuraceDemo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
2F1F7D7328318D9900AA30DB /* TextExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F1F7D7228318D9900AA30DB /* TextExample.swift */; };
1313
2F1F7D7528318EEE00AA30DB /* ButtonExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F1F7D7428318EEE00AA30DB /* ButtonExample.swift */; };
1414
2F27BC9D284814B600B5AC8D /* TabExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F27BC9C284814B600B5AC8D /* TabExample.swift */; };
15+
2F5EFD3C284D23E3005D130A /* HorizontalGridExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F5EFD3B284D23E2005D130A /* HorizontalGridExample.swift */; };
1516
2F77A234283C4AC700F143FB /* ImageExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F77A233283C4AC700F143FB /* ImageExample.swift */; };
1617
2F9321B3282EE49E003DA929 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B2282EE49E003DA929 /* AppDelegate.swift */; };
1718
2F9321B5282EE49E003DA929 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B4282EE49E003DA929 /* SceneDelegate.swift */; };
@@ -31,6 +32,7 @@
3132
2F1F7D7228318D9900AA30DB /* TextExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextExample.swift; sourceTree = "<group>"; };
3233
2F1F7D7428318EEE00AA30DB /* ButtonExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonExample.swift; sourceTree = "<group>"; };
3334
2F27BC9C284814B600B5AC8D /* TabExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabExample.swift; sourceTree = "<group>"; };
35+
2F5EFD3B284D23E2005D130A /* HorizontalGridExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalGridExample.swift; sourceTree = "<group>"; };
3436
2F77A233283C4AC700F143FB /* ImageExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageExample.swift; sourceTree = "<group>"; };
3537
2F9321AF282EE49E003DA929 /* PuraceDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PuraceDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
3638
2F9321B2282EE49E003DA929 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -85,6 +87,7 @@
8587
2FA986782837351B000DB409 /* GridExample.swift */,
8688
2FA9867A28373DD3000DB409 /* SnackbarExample.swift */,
8789
2F27BC9C284814B600B5AC8D /* TabExample.swift */,
90+
2F5EFD3B284D23E2005D130A /* HorizontalGridExample.swift */,
8891
);
8992
path = Complex;
9093
sourceTree = "<group>";
@@ -210,6 +213,7 @@
210213
2F9321B7282EE49E003DA929 /* MenuView.swift in Sources */,
211214
2F9321B3282EE49E003DA929 /* AppDelegate.swift in Sources */,
212215
2F77A234283C4AC700F143FB /* ImageExample.swift in Sources */,
216+
2F5EFD3C284D23E3005D130A /* HorizontalGridExample.swift in Sources */,
213217
2FA9867B28373DD3000DB409 /* SnackbarExample.swift in Sources */,
214218
2F1F7D7528318EEE00AA30DB /* ButtonExample.swift in Sources */,
215219
2FA986792837351B000DB409 /* GridExample.swift in Sources */,

PuraceDemo/PuraceDemo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// HorizontalGridExample.swift
3+
// PuraceDemo
4+
//
5+
// Created by Juan Hurtado on 5/06/22.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
import Purace
11+
12+
struct HorizontalGridExample: View {
13+
let urls = [
14+
URL(string: "https://elturismoencolombia.com/wp-content/uploads/2018/06/popayan_iglesia_santo_domingo_colombia_travel.jpg"),
15+
URL(string: "https://live.staticflickr.com/3678/9998758505_11f317ab55_b.jpg"),
16+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/7/71/Casa_en_donde_vivi%C3%B3_y_muri%C3%B3_el_Maestro_Guillermo_Le%C3%B3n_Valencia.jpg"),
17+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/f/f9/Iglesia_San_Francisco_2.JPG"),
18+
URL(string: "https://c8.alamy.com/zoomses/9/6c76df2a20324b87b4bda7eefe0012f9/dfy7wh.jpg"),
19+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/0/0f/La_Capilla_de_Belen.jpg"),
20+
URL(string: "https://elturismoencolombia.com/wp-content/uploads/2018/06/popayan_iglesia_san_agustin_colombia_travel.jpg"),
21+
]
22+
23+
func image(url: URL?) -> some View {
24+
Color.clear
25+
.background(
26+
PuraceImageView(url: url)
27+
.aspectRatio(contentMode: .fill)
28+
.clipped()
29+
)
30+
.clipped()
31+
}
32+
33+
var body: some View {
34+
PuraceHorizontalGridView {
35+
ForEach(urls.indices) { index in
36+
image(url: urls[index])
37+
}
38+
}.frame(height: UIScreen.main.bounds.height * 0.4)
39+
Spacer()
40+
}
41+
}

PuraceDemo/PuraceDemo/Examples/Complex/TabExample.swift

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ struct TabExample: View {
3030
longitudinalMeters: 750
3131
)
3232

33+
let urls = [
34+
URL(string: "https://elturismoencolombia.com/wp-content/uploads/2018/06/popayan_iglesia_santo_domingo_colombia_travel.jpg"),
35+
URL(string: "https://live.staticflickr.com/3678/9998758505_11f317ab55_b.jpg"),
36+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/7/71/Casa_en_donde_vivi%C3%B3_y_muri%C3%B3_el_Maestro_Guillermo_Le%C3%B3n_Valencia.jpg"),
37+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/f/f9/Iglesia_San_Francisco_2.JPG"),
38+
URL(string: "https://c8.alamy.com/zoomses/9/6c76df2a20324b87b4bda7eefe0012f9/dfy7wh.jpg"),
39+
URL(string: "https://upload.wikimedia.org/wikipedia/commons/0/0f/La_Capilla_de_Belen.jpg"),
40+
URL(string: "https://elturismoencolombia.com/wp-content/uploads/2018/06/popayan_iglesia_san_agustin_colombia_travel.jpg"),
41+
]
42+
43+
func image(url: URL?) -> some View {
44+
Color.clear
45+
.background(
46+
PuraceImageView(url: url)
47+
.aspectRatio(contentMode: .fill)
48+
.clipped()
49+
)
50+
.clipped()
51+
}
52+
3353
var body: some View {
3454
PuraceTabView(titles: ["Acerca de", "Imágenes"]) { index in
3555
Group {
@@ -38,24 +58,17 @@ struct TabExample: View {
3858
VStack {
3959
Map(coordinateRegion: $region, annotationItems: [place]) { item in
4060
MapMarker(coordinate: place.location, tint: .black)
41-
}.frame(height: UIScreen.main.bounds.height * 0.5)
61+
}
4262
Spacer(minLength: 0)
4363
}
4464
default:
45-
ScrollView {
46-
PuraceVerticalGridView(columns: 2, spacing: 1) {
47-
PuraceImageView(url: URL(string: "https://www.biografiasyvidas.com/biografia/c/fotos/caldas_francisco_jose_2.jpg"))
48-
.frame(height: 200)
49-
PuraceImageView(url: URL(string: "https://www.biografiasyvidas.com/biografia/c/fotos/caldas_francisco_jose_2.jpg"))
50-
.frame(height: 200)
51-
PuraceImageView(url: URL(string: "https://www.biografiasyvidas.com/biografia/c/fotos/caldas_francisco_jose_2.jpg"))
52-
.frame(height: 200)
53-
PuraceImageView(url: URL(string: "https://www.biografiasyvidas.com/biografia/c/fotos/caldas_francisco_jose_2.jpg"))
54-
.frame(height: 200)
65+
PuraceHorizontalGridView {
66+
ForEach(urls.indices) { index in
67+
image(url: urls[index])
5568
}
5669
}
5770
}
58-
}.frame(height: UIScreen.main.bounds.height * 0.7)
71+
}.frame(height: UIScreen.main.bounds.height * 0.4)
5972
}.onAppear {
6073
MKMapView.appearance().mapType = .mutedStandard
6174
}

PuraceDemo/PuraceDemo/MenuView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ struct MenuView: View {
4040
NavigationLink("Grid") {
4141
GridExample()
4242
}
43+
NavigationLink("Horizontal Grid") {
44+
HorizontalGridExample()
45+
}
4346
NavigationLink("Tab") {
4447
TabExample()
4548
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// PuraceHGridHorizontalStack.swift
3+
//
4+
//
5+
// Created by Juan Hurtado on 6/06/22.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct PuraceHGridHorizontalStack: View {
12+
let contents: [PuraceHGridStackContent]
13+
14+
var body: some View {
15+
HStack(spacing: 5) {
16+
ForEach(contents) { content in
17+
if case let .subStack(axis: axis, children: contents) = content {
18+
switch axis {
19+
case .vertical:
20+
PuraceHGridVerticalStack(contents: contents)
21+
case .horizontal:
22+
PuraceHGridHorizontalStack(contents: contents)
23+
}
24+
}
25+
26+
if case let .leaf(content: views) = content {
27+
ForEach(views.indices) { index in
28+
views[index]
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// PuraceHGridStackContent.swift
3+
//
4+
//
5+
// Created by Juan Hurtado on 6/06/22.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
enum PuraceHGridStackContent: Identifiable {
12+
var id: String {
13+
UUID().uuidString
14+
}
15+
case subStack(axis: PuraceHGridStackAxis, children: [PuraceHGridStackContent])
16+
case leaf(content: [AnyView])
17+
}
18+
19+
enum PuraceHGridStackAxis {
20+
case horizontal, vertical
21+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// PuraceHGridVerticalStack.swift
3+
//
4+
//
5+
// Created by Juan Hurtado on 6/06/22.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct PuraceHGridVerticalStack: View {
12+
let contents: [PuraceHGridStackContent]
13+
14+
var body: some View {
15+
VStack(spacing: 5) {
16+
ForEach(contents) { content in
17+
if case let .subStack(axis: axis, children: contents) = content {
18+
switch axis {
19+
case .vertical:
20+
PuraceHGridVerticalStack(contents: contents)
21+
case .horizontal:
22+
PuraceHGridHorizontalStack(contents: contents)
23+
}
24+
}
25+
26+
if case let .leaf(content: views) = content {
27+
ForEach(views.indices) { index in
28+
views[index]
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)