Skip to content

Commit 2e3fbdb

Browse files
committed
Add ability to preview media taken with camera
1 parent 2846b93 commit 2e3fbdb

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

damus.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@
417417
9C83F89329A937B900136C08 /* TextViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C83F89229A937B900136C08 /* TextViewWrapper.swift */; };
418418
9CA876E229A00CEA0003B9A3 /* AttachMediaUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */; };
419419
ADFE73552AD4793100EC7326 /* QRScanNSECView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFE73542AD4793100EC7326 /* QRScanNSECView.swift */; };
420+
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */; };
420421
BA37598A2ABCCDE40018D73B /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759892ABCCDE30018D73B /* ImageResizer.swift */; };
421422
BA37598D2ABCCE500018D73B /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */; };
422423
BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */; };
@@ -1119,6 +1120,7 @@
11191120
9C83F89229A937B900136C08 /* TextViewWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewWrapper.swift; sourceTree = "<group>"; };
11201121
9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachMediaUtility.swift; sourceTree = "<group>"; };
11211122
ADFE73542AD4793100EC7326 /* QRScanNSECView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScanNSECView.swift; sourceTree = "<group>"; };
1123+
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraMediaView.swift; sourceTree = "<group>"; };
11221124
BA3759892ABCCDE30018D73B /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
11231125
BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
11241126
BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
@@ -2329,6 +2331,7 @@
23292331
children = (
23302332
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
23312333
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */,
2334+
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */,
23322335
);
23332336
path = Camera;
23342337
sourceTree = "<group>";
@@ -2949,6 +2952,7 @@
29492952
4C1A9A2529DDDF2600516EAC /* ZapSettingsView.swift in Sources */,
29502953
4C2CDDF7299D4A5E00879FD5 /* Debouncer.swift in Sources */,
29512954
3AAA95CC298E07E900F3D526 /* DeepLPlan.swift in Sources */,
2955+
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */,
29522956
4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */,
29532957
3AA247FF297E3D900090C62D /* RepostsView.swift in Sources */,
29542958
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)