Skip to content

Commit 50a4190

Browse files
committed
camera: add ability to preview media taken with camera
1 parent b733799 commit 50a4190

File tree

6 files changed

+338
-63
lines changed

6 files changed

+338
-63
lines changed

damus.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@
434434
B5C60C202B530D5100C5ECA7 /* MuteItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C60C1F2B530D5100C5ECA7 /* MuteItem.swift */; };
435435
B5C60C212B530D5600C5ECA7 /* MuteItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C60C1F2B530D5100C5ECA7 /* MuteItem.swift */; };
436436
B5C60C232B532A8700C5ECA7 /* DamusDuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C60C222B532A8700C5ECA7 /* DamusDuration.swift */; };
437+
BA15BB6B2B7833660045B913 /* CameraMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA15BB6A2B7833660045B913 /* CameraMediaView.swift */; };
438+
BA15BB6D2B78336D0045B913 /* CameraView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA15BB6C2B78336D0045B913 /* CameraView.swift */; };
437439
BA37598A2ABCCDE40018D73B /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759892ABCCDE30018D73B /* ImageResizer.swift */; };
438440
BA37598D2ABCCE500018D73B /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */; };
439441
BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */; };
@@ -1353,6 +1355,8 @@
13531355
B5B4D1422B37D47600844320 /* NdbExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NdbExtensions.swift; sourceTree = "<group>"; usesTabs = 0; };
13541356
B5C60C1F2B530D5100C5ECA7 /* MuteItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuteItem.swift; sourceTree = "<group>"; usesTabs = 0; };
13551357
B5C60C222B532A8700C5ECA7 /* DamusDuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DamusDuration.swift; sourceTree = "<group>"; usesTabs = 0; };
1358+
BA15BB6A2B7833660045B913 /* CameraMediaView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraMediaView.swift; sourceTree = "<group>"; };
1359+
BA15BB6C2B78336D0045B913 /* CameraView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraView.swift; sourceTree = "<group>"; };
13561360
BA3759892ABCCDE30018D73B /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
13571361
BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
13581362
BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
@@ -2688,8 +2692,10 @@
26882692
BA3759952ABCCF360018D73B /* Camera */ = {
26892693
isa = PBXGroup;
26902694
children = (
2695+
BA15BB6A2B7833660045B913 /* CameraMediaView.swift */,
26912696
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
26922697
E02429942B7E97740088B16C /* CameraController.swift */,
2698+
BA15BB6C2B78336D0045B913 /* CameraView.swift */,
26932699
);
26942700
path = Camera;
26952701
sourceTree = "<group>";
@@ -3049,6 +3055,7 @@
30493055
4C4793042A993DC000489948 /* midl.c in Sources */,
30503056
0E8A4BB72AE4359200065E81 /* NostrFilter+Hashable.swift in Sources */,
30513057
4C4793012A993CDA00489948 /* mdb.c in Sources */,
3058+
BA15BB6D2B78336D0045B913 /* CameraView.swift in Sources */,
30523059
4CE9FBBA2A6B3C63007E485C /* nostrdb.c in Sources */,
30533060
ADFE73552AD4793100EC7326 /* QRScanNSECView.swift in Sources */,
30543061
4C3AC79D2833036D00E1F516 /* FollowingView.swift in Sources */,
@@ -3134,6 +3141,7 @@
31343141
647D9A8D2968520300A295DE /* SideMenuView.swift in Sources */,
31353142
F7F0BA272978E54D009531F3 /* ParticipantsView.swift in Sources */,
31363143
4CF0ABE32981BC7D00D66079 /* UserView.swift in Sources */,
3144+
BA15BB6B2B7833660045B913 /* CameraMediaView.swift in Sources */,
31373145
4CE0E2AF29A2E82100DB4CA2 /* EventHolder.swift in Sources */,
31383146
B51C1CEA2B55A60A00E312A9 /* AddMuteItemView.swift in Sources */,
31393147
4C5D5C992A6AF8F80024563C /* NdbNote.swift in Sources */,

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

-57
This file was deleted.

damus.xcodeproj/xcshareddata/xcschemes/DamusNotificationService.xcscheme

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
savedToolIdentifier = ""
7878
useCustomWorkingDirectory = "NO"
7979
debugDocumentVersioning = "YES"
80-
askForAppToLaunch = "Yes"
8180
launchAutomaticallySubstyle = "2">
8281
<BuildableProductRunnable
8382
runnableDebuggingMode = "0">
+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+
}

0 commit comments

Comments
 (0)