Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent Camera/Adjusted UI #25

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

}
}