Skip to content

Commit

Permalink
Merge pull request #25 from AdAstraCA/main
Browse files Browse the repository at this point in the history
Consistent Camera/Adjusted UI
  • Loading branch information
truedat101 authored Feb 7, 2023
2 parents fd23016 + 1e92f62 commit 05db2d4
Showing 1 changed file with 21 additions and 58 deletions.
79 changes: 21 additions & 58 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 1/27/23.
// Edited by Astra on 2/1/23.
//

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

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

if camera.isTaken{
Spacer()

Button(action: camera.reTake, label: {

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

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: {
ZStack{

ZStack{

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

Circle()
.stroke(Color.white,lineWidth: 2)
.frame(width: 75, height: 75)
}
})
}
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 @@ -175,18 +142,19 @@ 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 @@ -200,17 +168,12 @@ class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
//take and retake photos

func takePic(){

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

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

self.session.stopRunning()

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

savePic()

}

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

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

if error != nil{
return
}
Expand All @@ -242,7 +204,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 @@ -279,3 +241,4 @@ struct CameraPreview: UIViewRepresentable {

}
}

0 comments on commit 05db2d4

Please sign in to comment.