Skip to content

Commit

Permalink
Merge pull request #26 from RazortoothRTC/revert-25-main
Browse files Browse the repository at this point in the history
Revert "Consistent Camera/Adjusted UI"
  • Loading branch information
truedat101 authored Feb 7, 2023
2 parents 05db2d4 + b39c774 commit 0051cfa
Showing 1 changed file with 58 additions and 21 deletions.
79 changes: 58 additions & 21 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Shared
//
// Created by Delta on 24/5/22.
// Edited by Astra on 2/1/23.
// Edited by Astra on 1/27/23.
//

import AVFoundation
Expand Down Expand Up @@ -50,20 +50,53 @@ struct CameraView: View{
camera.Check()
}.frame(width: geometry.size.width, height: geometry.size.height / 1.6, alignment: .center).clipped()
HStack{
Button(action: camera.takePic, label: {

// if taken showing save and again take button...

if camera.isTaken{
Spacer()

ZStack{

Circle()
.fill(Color.white)
.frame(width: 65, height: 65)
Button(action: camera.reTake, label: {

Image(systemName: "arrow.triangle.2.circlepath.camera")
.foregroundColor(.black)
.padding()
.background(Color.white)
.clipShape(Circle())
})
.padding(.trailing,10)

Spacer()

Button(action: {if !camera.isSaved{camera.savePic()}}, label: {
Text(camera.isSaved ? "Saved" : "Save")
.foregroundColor(.black)
.fontWeight(.semibold)
.padding(.vertical,10)
.padding(.horizontal,20)
.background(Color.white)
.clipShape(Capsule())
})
.padding(.leading)

Spacer()
}
else{

Button(action: camera.takePic, label: {

Circle()
.stroke(Color.white,lineWidth: 2)
.frame(width: 75, height: 75)
}
})

ZStack{

Circle()
.fill(Color.white)
.frame(width: 65, height: 65)

Circle()
.stroke(Color.white,lineWidth: 2)
.frame(width: 75, height: 75)
}
})
}
}
.frame(height: 75)
ScrollView(.horizontal, showsIndicators: false) {
Expand Down Expand Up @@ -142,19 +175,18 @@ class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
guard let device = AVCaptureDevice.default(for: AVMediaType.video) else {
return
}

let input = try AVCaptureDeviceInput(device: device)

//checking and adding to session

if self.session.canAddInput(input){
print("input")
self.session.addInput(input)
}

//same for output

if self.session.canAddOutput(output){
print("output")
self.session.addOutput(self.output)
}

Expand All @@ -168,12 +200,17 @@ class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
//take and retake photos

func takePic(){
print("success")
self.output.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)


savePic()
self.output.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)

DispatchQueue.global(qos: .background).async {

self.session.stopRunning()

DispatchQueue.main.async {
withAnimation{self.isTaken.toggle()}
}
}
}

func reTake(){
Expand All @@ -192,6 +229,7 @@ class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
}

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

if error != nil{
return
}
Expand All @@ -204,7 +242,7 @@ class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
}

func savePic(){
print("saving")

guard let image = UIImage(data: self.picData) else{return}

// saving Image...
Expand Down Expand Up @@ -241,4 +279,3 @@ struct CameraPreview: UIViewRepresentable {

}
}

0 comments on commit 0051cfa

Please sign in to comment.