Skip to content

Commit

Permalink
Add ability to preview media taken with camera
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan committed Dec 22, 2023
1 parent 2846b93 commit 2e3fbdb
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
4 changes: 4 additions & 0 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
9C83F89329A937B900136C08 /* TextViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C83F89229A937B900136C08 /* TextViewWrapper.swift */; };
9CA876E229A00CEA0003B9A3 /* AttachMediaUtility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */; };
ADFE73552AD4793100EC7326 /* QRScanNSECView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADFE73542AD4793100EC7326 /* QRScanNSECView.swift */; };
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */; };
BA37598A2ABCCDE40018D73B /* ImageResizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA3759892ABCCDE30018D73B /* ImageResizer.swift */; };
BA37598D2ABCCE500018D73B /* PhotoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */; };
BA37598E2ABCCE500018D73B /* VideoCaptureProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */; };
Expand Down Expand Up @@ -1119,6 +1120,7 @@
9C83F89229A937B900136C08 /* TextViewWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextViewWrapper.swift; sourceTree = "<group>"; };
9CA876E129A00CE90003B9A3 /* AttachMediaUtility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachMediaUtility.swift; sourceTree = "<group>"; };
ADFE73542AD4793100EC7326 /* QRScanNSECView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRScanNSECView.swift; sourceTree = "<group>"; };
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraMediaView.swift; sourceTree = "<group>"; };
BA3759892ABCCDE30018D73B /* ImageResizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageResizer.swift; sourceTree = "<group>"; };
BA37598B2ABCCE500018D73B /* PhotoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoCaptureProcessor.swift; sourceTree = "<group>"; };
BA37598C2ABCCE500018D73B /* VideoCaptureProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoCaptureProcessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2329,6 +2331,7 @@
children = (
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */,
BA0F0A6E2B36207E001641B2 /* CameraMediaView.swift */,
);
path = Camera;
sourceTree = "<group>";
Expand Down Expand Up @@ -2949,6 +2952,7 @@
4C1A9A2529DDDF2600516EAC /* ZapSettingsView.swift in Sources */,
4C2CDDF7299D4A5E00879FD5 /* Debouncer.swift in Sources */,
3AAA95CC298E07E900F3D526 /* DeepLPlan.swift in Sources */,
BA0F0A6F2B36207E001641B2 /* CameraMediaView.swift in Sources */,
4FE60CDD295E1C5E00105A1F /* Wallet.swift in Sources */,
3AA247FF297E3D900090C62D /* RepostsView.swift in Sources */,
3AE45AF6297BB2E700C1D842 /* LibreTranslateServer.swift in Sources */,
Expand Down
89 changes: 89 additions & 0 deletions damus/Views/Camera/CameraMediaView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// MediaViewer.swift
// damus
//
// Created by Suhail Saqan on 12/22/23.
//

import SwiftUI
import Kingfisher

// MARK: - Camera Media Viewer
struct CameraMediaView: View {
let video_controller: VideoController
let urls: [MediaUrl]

@Environment(\.presentationMode) var presentationMode

@State private var selectedIndex = 0
@State var showMenu = true

let settings: UserSettingsStore

var tabViewIndicator: some View {
HStack(spacing: 10) {
ForEach(urls.indices, id: \.self) { index in
Capsule()
.fill(index == selectedIndex ? Color(UIColor.label) : Color.secondary)
.frame(width: 7, height: 7)
.onTapGesture {
selectedIndex = index
}
}
}
.padding()
.background(.regularMaterial)
.clipShape(Capsule())
}

var body: some View {
ZStack {
Color(.systemBackground)
.ignoresSafeArea()

TabView(selection: $selectedIndex) {
ForEach(urls.indices, id: \.self) { index in
ZoomableScrollView {
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
}
.ignoresSafeArea()
.tag(index)
}
}
.ignoresSafeArea()
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
.gesture(TapGesture(count: 2).onEnded {
// Prevents menu from hiding on double tap
})
.gesture(TapGesture(count: 1).onEnded {
showMenu.toggle()
})
.overlay(
GeometryReader { geo in
VStack {
if showMenu {
NavDismissBarView()
Spacer()

if (urls.count > 1) {
tabViewIndicator
}
}
}
.animation(.easeInOut, value: showMenu)
.padding(.bottom, geo.safeAreaInsets.bottom == 0 ? 12 : 0)
}
)
}
}
}

struct CameraMediaView_Previews: PreviewProvider {
static var previews: some View {
let url: MediaUrl = .image(URL(string: "https://jb55.com/red-me.jpg")!)
CameraMediaView(video_controller: test_damus_state.video, urls: [url], settings: test_damus_state.settings)
}
}
11 changes: 10 additions & 1 deletion damus/Views/Camera/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,16 @@ struct CameraView: View {

HStack(alignment: .center) {
if !model.mediaItems.isEmpty {
NavigationLink(destination: Text(model.mediaItems.map { $0.url.absoluteString }.joined(separator: ", "))) {
NavigationLink(destination: CameraMediaView(video_controller: damus_state.video, urls: model.mediaItems.map { mediaItem in
switch mediaItem.type {
case .image:
return .image(mediaItem.url)
case .video:
return .video(mediaItem.url)
}
}, settings: damus_state.settings)
.navigationBarBackButtonHidden(true)
) {
capturedPhotoThumbnail
}
.frame(width: 100, alignment: .leading)
Expand Down

0 comments on commit 2e3fbdb

Please sign in to comment.