Skip to content

Commit

Permalink
update project file
Browse files Browse the repository at this point in the history
  • Loading branch information
suhailsaqan committed Oct 28, 2023
1 parent dd1474f commit 32ca6fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 209 deletions.
7 changes: 4 additions & 3 deletions damus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
BA4AB0AE2A63B9270070A32A /* AddEmojiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */; };
BA4AB0B02A63B94D0070A32A /* EmojiListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */; };
BA693074295D649800ADDB87 /* UserSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA693073295D649800ADDB87 /* UserSettingsStore.swift */; };
BAA578D52AED7F4000EA8BE3 /* CameraView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAA578D42AED7F4000EA8BE3 /* CameraView.swift */; };
BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; };
D2277EEA2A089BD5006C3807 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2277EE92A089BD5006C3807 /* Router.swift */; };
D71DC1EC2A9129C3006E207C /* PostViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71DC1EB2A9129C3006E207C /* PostViewTests.swift */; };
Expand Down Expand Up @@ -1128,7 +1129,7 @@
BA4AB0AD2A63B9270070A32A /* AddEmojiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddEmojiView.swift; sourceTree = "<group>"; };
BA4AB0AF2A63B94D0070A32A /* EmojiListItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiListItemView.swift; sourceTree = "<group>"; };
BA693073295D649800ADDB87 /* UserSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingsStore.swift; sourceTree = "<group>"; };
BAA8C3262AEC570800696158 /* CameraView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraView.swift; sourceTree = "<group>"; };
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraView.swift; sourceTree = "<group>"; };
BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = "<group>"; };
D2277EE92A089BD5006C3807 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
D71DC1EB2A9129C3006E207C /* PostViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2326,8 +2327,8 @@
BA3759952ABCCF360018D73B /* Camera */ = {
isa = PBXGroup;
children = (
BAA8C3262AEC570800696158 /* CameraView.swift */,
BA3759962ABCCF360018D73B /* CameraPreview.swift */,
BAA578D42AED7F4000EA8BE3 /* CameraView.swift */,
);
path = Camera;
sourceTree = "<group>";
Expand Down Expand Up @@ -2759,6 +2760,7 @@
4CC7AAF8297F1CEE00430951 /* EventProfile.swift in Sources */,
5CF2DCCC2AA3AF0B00984B8D /* RelayPicView.swift in Sources */,
4C687C242A5FA86D0092C550 /* SearchHeaderView.swift in Sources */,
BAA578D52AED7F4000EA8BE3 /* CameraView.swift in Sources */,
64FBD06F296255C400D9D3B2 /* Theme.swift in Sources */,
4C1A9A2329DDDB8100516EAC /* IconLabel.swift in Sources */,
4CA352AC2A76C07F003BB08B /* NewUnmutesNotify.swift in Sources */,
Expand Down Expand Up @@ -2801,7 +2803,6 @@
4C1D4FB12A7958E60024F453 /* VersionInfo.swift in Sources */,
D7FF94002AC7AC5300FD969D /* RelayURL.swift in Sources */,
4C64305C2A945AFF00B0C0E9 /* MusicController.swift in Sources */,
BAA8C3272AEC570800696158 /* CameraView.swift in Sources */,
5053ACA72A56DF3B00851AE3 /* DeveloperSettingsView.swift in Sources */,
F79C7FAD29D5E9620000F946 /* EditPictureControl.swift in Sources */,
4C9F18E229AA9B6C008C55EC /* CustomizeZapView.swift in Sources */,
Expand Down
208 changes: 2 additions & 206 deletions damus/Views/Camera/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,211 +2,7 @@
// CameraView.swift
// damus
//
// Created by Suhail Saqan on 8/5/23.
// Created by Suhail Saqan on 10/28/23.
//

import SwiftUI
import Combine
import AVFoundation

struct CameraView: View {
let damus_state: DamusState
let action: (([MediaItem]) -> Void)

@Environment(\.presentationMode) var presentationMode

@StateObject var model: CameraModel

@State var currentZoomFactor: CGFloat = 1.0

public init(damus_state: DamusState, action: @escaping (([MediaItem]) -> Void)) {
self.damus_state = damus_state
self.action = action
_model = StateObject(wrappedValue: CameraModel())
}

var captureButton: some View {
Button {
if model.isRecording {
withAnimation {
model.stopRecording()
}
} else {
withAnimation {
model.capturePhoto()
}
}
UIImpactFeedbackGenerator(style: .medium).impactOccurred()
} label: {
ZStack {
Circle()
.fill( model.isRecording ? .red : DamusColors.black)
.frame(width: model.isRecording ? 85 : 65, height: model.isRecording ? 85 : 65, alignment: .center)

Circle()
.stroke( model.isRecording ? .red : DamusColors.white, lineWidth: 4)
.frame(width: model.isRecording ? 95 : 75, height: model.isRecording ? 95 : 75, alignment: .center)
}
.frame(alignment: .center)
}
.simultaneousGesture(
LongPressGesture(minimumDuration: 0.5).onEnded({ value in
if (!model.isCameraButtonDisabled) {
withAnimation {
model.startRecording()
model.captureMode = .video
}
}
})
)
.buttonStyle(.plain)
}

var capturedPhotoThumbnail: some View {
ZStack {
if model.thumbnail != nil {
Image(uiImage: model.thumbnail.thumbnailImage!)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 60, height: 60)
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
}
if model.isPhotoProcessing {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: DamusColors.white))
}
}
}

var closeButton: some View {
Button {
presentationMode.wrappedValue.dismiss()
model.stop()
} label: {
HStack {
Image(systemName: "xmark")
.font(.system(size: 24))
}
.frame(minWidth: 40, minHeight: 40)
}
.accentColor(DamusColors.white)
}

var flipCameraButton: some View {
Button(action: {
model.flipCamera()
}, label: {
HStack {
Image(systemName: "camera.rotate.fill")
.font(.system(size: 20))
}
.frame(minWidth: 40, minHeight: 40)
})
.accentColor(DamusColors.white)
}

var toggleFlashButton: some View {
Button(action: {
model.switchFlash()
}, label: {
HStack {
Image(systemName: model.isFlashOn ? "bolt.fill" : "bolt.slash.fill")
.font(.system(size: 20))
}
.frame(minWidth: 40, minHeight: 40)
})
.accentColor(model.isFlashOn ? .yellow : DamusColors.white)
}

var body: some View {
NavigationView {
GeometryReader { reader in
ZStack {
DamusColors.black.edgesIgnoringSafeArea(.all)

CameraPreview(session: model.session)
.padding(.bottom, 175)
.edgesIgnoringSafeArea(.all)
.gesture(
DragGesture().onChanged({ (val) in
if abs(val.translation.height) > abs(val.translation.width) {
let percentage: CGFloat = -(val.translation.height / reader.size.height)
let calc = currentZoomFactor + percentage
let zoomFactor: CGFloat = min(max(calc, 1), 5)

currentZoomFactor = zoomFactor
model.zoom(with: zoomFactor)
}
})
)
.onAppear {
model.configure()
}
.alert(isPresented: $model.showAlertError, content: {
Alert(title: Text(model.alertError.title), message: Text(model.alertError.message), dismissButton: .default(Text(model.alertError.primaryButtonTitle), action: {
model.alertError.primaryAction?()
}))
})
.overlay(
Group {
if model.willCapturePhoto {
Color.black
}
}
)

VStack {
if !model.isRecording {
HStack {
closeButton

Spacer()

HStack {
flipCameraButton
toggleFlashButton
}
}
.padding(.horizontal, 20)
}

Spacer()

HStack(alignment: .center) {
if !model.mediaItems.isEmpty {
NavigationLink(destination: Text(model.mediaItems.map { $0.url.absoluteString }.joined(separator: ", "))) {
capturedPhotoThumbnail
}
.frame(width: 100, alignment: .leading)
}

Spacer()

captureButton

Spacer()

if !model.mediaItems.isEmpty {
Button(action: {
action(model.mediaItems)
presentationMode.wrappedValue.dismiss()
model.stop()
}) {
Text("Upload")
.frame(width: 100, height: 40, alignment: .center)
.foregroundColor(DamusColors.white)
.overlay {
RoundedRectangle(cornerRadius: 24)
.stroke(DamusColors.white, lineWidth: 2)
}
}
}
}
.frame(height: 100)
.padding([.horizontal, .vertical], 20)
}
}
}
}
}
}
import Foundation

0 comments on commit 32ca6fd

Please sign in to comment.