-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
camera: add ability to preview media taken with camera
- Loading branch information
1 parent
b733799
commit 50a4190
Showing
6 changed files
with
338 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
damus.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.