Skip to content

Commit ae28fb8

Browse files
initial work on the grid photos ui
1 parent 16affbe commit ae28fb8

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Gallery/GalleryView.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import SwiftUI
88
struct GalleryView: View {
99

1010
@Injected(\.colors) private var colors
11+
@Injected(\.fonts) private var fonts
1112

1213
var message: ChatMessage
1314
@Binding var isShown: Bool
1415
@State private var selected: Int
1516
@State private var loadedImages = [Int: UIImage]()
17+
@State private var gridShown = false
1618

1719
init(
1820
message: ChatMessage,
@@ -56,6 +58,7 @@ struct GalleryView: View {
5658
}
5759
}
5860
.tabViewStyle(.page(indexDisplayMode: .never))
61+
.background(Color(colors.background1))
5962

6063
if let image = loadedImages[selected] {
6164
HStack {
@@ -65,11 +68,23 @@ struct GalleryView: View {
6568
Spacer()
6669

6770
Text("\(selected + 1) of \(sources.count)")
71+
.font(fonts.bodyBold)
6872

6973
Spacer()
74+
75+
Button {
76+
gridShown = true
77+
} label: {
78+
Image(systemName: "square.grid.3x3.fill")
79+
}
80+
.standardPadding()
7081
}
82+
.foregroundColor(Color(colors.text))
7183
}
7284
}
85+
.sheet(isPresented: $gridShown) {
86+
GridPhotosView(loadedImages: loadedImages)
87+
}
7388
}
7489
}
7590

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import StreamChat
6+
import SwiftUI
7+
8+
struct GridPhotosView: View {
9+
10+
var loadedImages: [Int: UIImage]
11+
12+
let columns = [GridItem(.adaptive(minimum: 120), spacing: 2)]
13+
14+
private var sorted: [UIImage] {
15+
let keys = loadedImages.keys.sorted()
16+
return keys.compactMap { index in
17+
loadedImages[index]
18+
}
19+
}
20+
21+
var body: some View {
22+
ScrollView {
23+
LazyVGrid(columns: columns, spacing: 2) {
24+
ForEach(sorted, id: \.self) { image in
25+
Image(uiImage: image)
26+
.resizable()
27+
.aspectRatio(1, contentMode: .fill)
28+
.clipped()
29+
}
30+
}
31+
.padding(.horizontal, 2)
32+
.animation(nil)
33+
}
34+
}
35+
}

Sources/StreamChatSwiftUI/ChatChannel/Gallery/ShareButtonView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SwiftUI
77
/// View for presenting a button which has a share action.
88
struct ShareButtonView: View {
99
@Injected(\.colors) var colors
10+
@Injected(\.fonts) var fonts
1011

1112
var content: [Any]
1213
@State var isSharePresented = false
@@ -16,6 +17,7 @@ struct ShareButtonView: View {
1617
self.isSharePresented = true
1718
}, label: {
1819
Image(systemName: "square.and.arrow.up")
20+
.font(fonts.bodyBold)
1921
})
2022
.foregroundColor(Color(colors.text))
2123
.sheet(isPresented: $isSharePresented) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Copyright © 2021 Stream.io Inc. All rights reserved.
3+
//
4+
5+
import SwiftUI
6+
7+
struct TitleWithCloseButton: View {
8+
9+
@Injected(\.fonts) private var fonts
10+
11+
var title: String
12+
@Binding var isShown: Bool
13+
14+
var body: some View {
15+
ZStack {
16+
HStack {
17+
Spacer()
18+
Button {
19+
isShown = false
20+
} label: {
21+
DiscardButtonView()
22+
}
23+
}
24+
25+
Text(title)
26+
.font(fonts.bodyBold)
27+
}
28+
}
29+
}

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
84335014274BAB15007A1B81 /* ViewFactoryExamples.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */; };
1414
84335016274BABF3007A1B81 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335015274BABF3007A1B81 /* NewChatView.swift */; };
1515
84335018274BAD4B007A1B81 /* NewChatViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84335017274BAD4B007A1B81 /* NewChatViewModel.swift */; };
16+
8434E58127707F19001E1B83 /* GridPhotosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E58027707F19001E1B83 /* GridPhotosView.swift */; };
17+
8434E583277088D9001E1B83 /* TitleWithCloseButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */; };
1618
8465FBBE2746873A00AF091E /* StreamChatSwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */; };
1719
8465FCB427468A8D00AF091E /* StreamChat in Frameworks */ = {isa = PBXBuildFile; productRef = 8465FCB327468A8D00AF091E /* StreamChat */; };
1820
8465FCB727468B0600AF091E /* NukeUI in Frameworks */ = {isa = PBXBuildFile; productRef = 8465FCB627468B0600AF091E /* NukeUI */; };
@@ -290,6 +292,8 @@
290292
84335013274BAB15007A1B81 /* ViewFactoryExamples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewFactoryExamples.swift; sourceTree = "<group>"; };
291293
84335015274BABF3007A1B81 /* NewChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatView.swift; sourceTree = "<group>"; };
292294
84335017274BAD4B007A1B81 /* NewChatViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatViewModel.swift; sourceTree = "<group>"; };
295+
8434E58027707F19001E1B83 /* GridPhotosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridPhotosView.swift; sourceTree = "<group>"; };
296+
8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleWithCloseButton.swift; sourceTree = "<group>"; };
293297
8465FBB52746873A00AF091E /* StreamChatSwiftUI.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StreamChatSwiftUI.framework; sourceTree = BUILT_PRODUCTS_DIR; };
294298
8465FBBD2746873A00AF091E /* StreamChatSwiftUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StreamChatSwiftUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
295299
8465FCBC27468B6900AF091E /* DemoAppSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DemoAppSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -685,6 +689,7 @@
685689
children = (
686690
8465FCFA2746A95600AF091E /* ActionItemView.swift */,
687691
84F2908D276B92A40045472D /* GalleryHeaderView.swift */,
692+
8434E582277088D9001E1B83 /* TitleWithCloseButton.swift */,
688693
);
689694
path = CommonViews;
690695
sourceTree = "<group>";
@@ -1066,6 +1071,7 @@
10661071
isa = PBXGroup;
10671072
children = (
10681073
84F29089276B90610045472D /* GalleryView.swift */,
1074+
8434E58027707F19001E1B83 /* GridPhotosView.swift */,
10691075
8465FD032746A95600AF091E /* VideoPlayerView.swift */,
10701076
84F2908B276B91700045472D /* ZoomableScrollView.swift */,
10711077
84F2908F276CC1280045472D /* ShareButtonView.swift */,
@@ -1285,6 +1291,7 @@
12851291
8465FDBD2746A95700AF091E /* ChatChannelHelperViews.swift in Sources */,
12861292
8465FD8D2746A95700AF091E /* AddedImageAttachmentsView.swift in Sources */,
12871293
8465FDAA2746A95700AF091E /* DateFormatter+Extensions.swift in Sources */,
1294+
8434E58127707F19001E1B83 /* GridPhotosView.swift in Sources */,
12881295
8465FD742746A95700AF091E /* ViewFactory.swift in Sources */,
12891296
8465FDC12746A95700AF091E /* NoChannelsView.swift in Sources */,
12901297
8465FDA32746A95700AF091E /* ViewExtensions.swift in Sources */,
@@ -1298,6 +1305,7 @@
12981305
8465FD882746A95700AF091E /* SendMessageButton.swift in Sources */,
12991306
8465FDC82746A95700AF091E /* ChatChannelListItem.swift in Sources */,
13001307
8465FDA62746A95700AF091E /* LazyView.swift in Sources */,
1308+
8434E583277088D9001E1B83 /* TitleWithCloseButton.swift in Sources */,
13011309
8465FDB52746A95700AF091E /* Cache.swift in Sources */,
13021310
84DEC8EA2761089A00172876 /* MessageThreadHeaderViewModifier.swift in Sources */,
13031311
8465FD9B2746A95700AF091E /* DefaultMessageActions.swift in Sources */,

0 commit comments

Comments
 (0)