camera: add ability to preview media taken with camera
Closes: https://github.com/damus-io/damus/pull/1254 Reviewed-by: William Casarin <jb55@jb55.com> Signed-off-by: William Casarin <jb55@jb55.com> Changelog-Added: Add ability to preview media taken with camera
This commit is contained in:
committed by
William Casarin
parent
ca779d472d
commit
c67741983e
89
damus/Views/Camera/CameraMediaView.swift
Normal file
89
damus/Views/Camera/CameraMediaView.swift
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user