Skip to content

Commit cea8174

Browse files
suhailsaqanjb55
authored andcommitted
Add ability to preview media taken with camera
Closes: #1254 Reviewed-by: William Casarin <[email protected]> Signed-off-by: William Casarin <[email protected]>
1 parent 1700765 commit cea8174

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

damus.xcodeproj/project.pbxproj

+8-6
Original file line numberDiff line numberDiff line change
@@ -425,13 +425,14 @@
425425
B57B4C642B312BFA00A232C0 /* RelayAuthenticationDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57B4C632B312BFA00A232C0 /* RelayAuthenticationDetail.swift */; };
426426
B57B4C662B312C3700A232C0 /* NostrAuth.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57B4C652B312C3700A232C0 /* NostrAuth.swift */; };
427427
B5B4D1432B37D47600844320 /* NdbExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B4D1422B37D47600844320 /* NdbExtensions.swift */; };
428+
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */; };
429+
BA10192F2B449556009C57DA /* CameraPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA10192E2B449556009C57DA /* CameraPreview.swift */; };
428430
BA37598A2ABCCDE40018D73B /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759892ABCCDE30018D73B /* ImageResizer.swift */; };
429431
BA37598D2ABCCE500018D73B /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */; };
430432
BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */; };
431433
BA3759922ABCCEBA0018D73B /* CameraService+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598F2ABCCEBA0018D73B /* CameraService+Extensions.swift */; };
432434
BA3759932ABCCEBA0018D73B /* CameraModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759902ABCCEBA0018D73B /* CameraModel.swift */; };
433435
BA3759942ABCCEBA0018D73B /* CameraService.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759912ABCCEBA0018D73B /* CameraService.swift */; };
434-
BA3759972ABCCF360018D73B /* CameraPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759962ABCCF360018D73B /* CameraPreview.swift */; };
435436
BA4AB0AE2A63B9270070A32A /* AddEmojiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */; };
436437
BA4AB0B02A63B94D0070A32A /* EmojiListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */; };
437438
BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; };
@@ -1314,13 +1315,14 @@
13141315
B57B4C632B312BFA00A232C0 /* RelayAuthenticationDetail.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RelayAuthenticationDetail.swift; sourceTree = "<group>"; };
13151316
B57B4C652B312C3700A232C0 /* NostrAuth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NostrAuth.swift; sourceTree = "<group>"; };
13161317
B5B4D1422B37D47600844320 /* NdbExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NdbExtensions.swift; sourceTree = "<group>"; usesTabs = 0; };
1318+
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraMediaView.swift; sourceTree = "<group>"; };
1319+
BA10192E2B449556009C57DA /* CameraPreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraPreview.swift; sourceTree = "<group>"; };
13171320
BA3759892ABCCDE30018D73B /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
13181321
BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
13191322
BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
13201323
BA37598F2ABCCEBA0018D73B /* CameraService+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CameraService+Extensions.swift"; sourceTree = "<group>"; };
13211324
BA3759902ABCCEBA0018D73B /* CameraModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraModel.swift; sourceTree = "<group>"; };
13221325
BA3759912ABCCEBA0018D73B /* CameraService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraService.swift; sourceTree = "<group>"; };
1323-
BA3759962ABCCF360018D73B /* CameraPreview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraPreview.swift; sourceTree = "<group>"; };
13241326
BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddEmojiView.swift; sourceTree = "<group>"; };
13251327
BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiListItemView.swift; sourceTree = "<group>"; };
13261328
BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; };
@@ -2605,8 +2607,9 @@
26052607
BA3759952ABCCF360018D73B /* Camera */ = {
26062608
isa = PBXGroup;
26072609
children = (
2608-
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
26092610
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */,
2611+
BA10192E2B449556009C57DA /* CameraPreview.swift */,
2612+
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */,
26102613
);
26112614
path = Camera;
26122615
sourceTree = "<group>";
@@ -2616,8 +2619,6 @@
26162619
children = (
26172620
D72A2D042AD9C1B5002AFF62 /* MockDamusState.swift */,
26182621
D72A2D062AD9C1FB002AFF62 /* MockProfiles.swift */,
2619-
BAA8C3262AEC570800696158 /* CameraView.swift */,
2620-
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
26212622
);
26222623
path = Mocking;
26232624
sourceTree = "<group>";
@@ -3019,7 +3020,6 @@
30193020
D7EDED2E2B128E8A0018B19C /* CollectionExtension.swift in Sources */,
30203021
D74AAFD62B155F0C006CF0F4 /* WalletConnect+.swift in Sources */,
30213022
4C216F382871EDE300040376 /* DirectMessageModel.swift in Sources */,
3022-
BA3759972ABCCF360018D73B /* CameraPreview.swift in Sources */,
30233023
4C75EFA627FF87A20006080F /* Nostr.swift in Sources */,
30243024
4CA927672A290F8B0098A105 /* RelativeTime.swift in Sources */,
30253025
4CB883A62975F83C00DC99E7 /* LNUrlPayRequest.swift in Sources */,
@@ -3243,6 +3243,7 @@
32433243
4C1253562A76C8C60004F4B8 /* BroadcastNotify.swift in Sources */,
32443244
4C3BEFD42819DE8F00B3DE84 /* NostrKind.swift in Sources */,
32453245
4C32B9532A9AD44700DC3548 /* Verifier.swift in Sources */,
3246+
BA10192F2B449556009C57DA /* CameraPreview.swift in Sources */,
32463247
4C3EA66028FF5E7700C48A62 /* node_id.c in Sources */,
32473248
4C687C212A5F7ED00092C550 /* DamusBackground.swift in Sources */,
32483249
4CA352A02A76AE80003BB08B /* Notify.swift in Sources */,
@@ -3313,6 +3314,7 @@
33133314
4C1A9A2529DDDF2600516EAC /* ZapSettingsView.swift in Sources */,
33143315
4C2CDDF7299D4A5E00879FD5 /* Debouncer.swift in Sources */,
33153316
3AAA95CC298E07E900F3D526 /* DeepLPlan.swift in Sources */,
3317+
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */,
33163318
4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */,
33173319
3AA247FF297E3D900090C62D /* RepostsView.swift in Sources */,
33183320
3AE45AF6297BB2E700C1D842 /* LibreTranslateServer.swift in Sources */,
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// MediaViewer.swift
3+
// damus
4+
//
5+
// Created by Suhail Saqan on 12/22/23.
6+
//
7+
8+
import SwiftUI
9+
import Kingfisher
10+
11+
// MARK: - Camera Media Viewer
12+
struct CameraMediaView: View {
13+
let video_controller: VideoController
14+
let urls: [MediaUrl]
15+
16+
@Environment(\.presentationMode) var presentationMode
17+
18+
@State private var selectedIndex = 0
19+
@State var showMenu = true
20+
21+
let settings: UserSettingsStore
22+
23+
var tabViewIndicator: some View {
24+
HStack(spacing: 10) {
25+
ForEach(urls.indices, id: \.self) { index in
26+
Capsule()
27+
.fill(index == selectedIndex ? Color(UIColor.label) : Color.secondary)
28+
.frame(width: 7, height: 7)
29+
.onTapGesture {
30+
selectedIndex = index
31+
}
32+
}
33+
}
34+
.padding()
35+
.background(.regularMaterial)
36+
.clipShape(Capsule())
37+
}
38+
39+
var body: some View {
40+
ZStack {
41+
Color(.systemBackground)
42+
.ignoresSafeArea()
43+
44+
TabView(selection: $selectedIndex) {
45+
ForEach(urls.indices, id: \.self) { index in
46+
ZoomableScrollView {
47+
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
48+
.aspectRatio(contentMode: .fit)
49+
.padding(.top, Theme.safeAreaInsets?.top)
50+
.padding(.bottom, Theme.safeAreaInsets?.bottom)
51+
}
52+
.ignoresSafeArea()
53+
.tag(index)
54+
}
55+
}
56+
.ignoresSafeArea()
57+
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
58+
.gesture(TapGesture(count: 2).onEnded {
59+
// Prevents menu from hiding on double tap
60+
})
61+
.gesture(TapGesture(count: 1).onEnded {
62+
showMenu.toggle()
63+
})
64+
.overlay(
65+
GeometryReader { geo in
66+
VStack {
67+
if showMenu {
68+
NavDismissBarView()
69+
Spacer()
70+
71+
if (urls.count > 1) {
72+
tabViewIndicator
73+
}
74+
}
75+
}
76+
.animation(.easeInOut, value: showMenu)
77+
.padding(.bottom, geo.safeAreaInsets.bottom == 0 ? 12 : 0)
78+
}
79+
)
80+
}
81+
}
82+
}
83+
84+
struct CameraMediaView_Previews: PreviewProvider {
85+
static var previews: some View {
86+
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
87+
CameraMediaView(video_controller: test_damus_state.video, urls: [url], settings: test_damus_state.settings)
88+
}
89+
}

damus/Views/Camera/CameraView.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,16 @@ struct CameraView: View {
174174

175175
HStack(alignment: .center) {
176176
if !model.mediaItems.isEmpty {
177-
NavigationLink(destination: Text(model.mediaItems.map { $0.url.absoluteString }.joined(separator: ", "))) {
177+
NavigationLink(destination: CameraMediaView(video_controller: damus_state.video, urls: model.mediaItems.map { mediaItem in
178+
switch mediaItem.type {
179+
case .image:
180+
return .image(mediaItem.url)
181+
case .video:
182+
return .video(mediaItem.url)
183+
}
184+
}, settings: damus_state.settings)
185+
.navigationBarBackButtonHidden(true)
186+
) {
178187
capturedPhotoThumbnail
179188
}
180189
.frame(width: 100, alignment: .leading)

0 commit comments

Comments
 (0)