Untitled
unknown
plain_text
3 years ago
20 kB
13
Indexable
//
// PhotoSelectorView.swift
// Garageworks-iOS-Revamp
//
// Created by DigitalFlake Kapil Dongre on 13/01/23.
//
import SwiftUI
import Foundation
import UIKit
enum PhotoSheetType: Identifiable { /// 1.
var id: UUID {
UUID()
}
case gallery
case camera
}
struct DocumentVaultView: View {
@Environment(\.presentationMode) var presentationMode
@State private var image = UIImage(systemName: "xmark")!
private var url: URL {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths[0].appendingPathComponent("image.jpg")
}
//@State private var showingActionSheet = false
@State private var selection = "None"
/// 2.
@State private var showingType: PhotoSheetType?
@State private var showingActionSheet = false
@State private var isShowPhotoLibrary = false
@State private var rcFront = UIImage()
@State private var rcRear = UIImage()
@State private var drivingLicenceFront = UIImage()
@State private var drivingLicenceRear = UIImage()
@State private var pucFront = UIImage()
@State private var pucRear = UIImage()
var body: some View {
GeometryReader{geometry in
VStack {
HStack(spacing: 20){
Button(){
print("Back navigationCross button pressed")
self.presentationMode.wrappedValue.dismiss()
}label: {
Image("arrow-left")
.resizable()
.frame(width: 20, height: 20)
}
Text("Document Vault")
.font(.system(size: 16, weight: .regular))
Spacer()
}
.padding(.leading, 20)
VStack{
VStack(alignment: .leading, spacing: 20){
//MARK: RC image
VStack(alignment: .leading){
Text("Rc Book")
.padding(.leading, 20)
HStack{
VStack(spacing: 15){
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.rcFront)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
// .onAppear(){
// //url.loadImage(image as UIImage?)
// }
.onTapGesture {
print("Rc item1 pressed")
self.showingActionSheet = true
let document = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let imgUrl = document.appendingPathComponent("RCFront", isDirectory: true)
//url.saveImage(image)
}
}
.padding(.leading, 20)
.padding(.trailing, 15)
Text("Front")
}
VStack{
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.rcRear)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
.onTapGesture {
print("Rc item1 pressed")
self.showingActionSheet = true
}
}
.padding(.trailing, 20)
Text("Rear")
}
}
}
//MARK: Driving Licence
VStack(alignment: .leading){
Text("Driving Licence")
.padding(.leading, 20)
HStack{
VStack{
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.drivingLicenceFront)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
.onTapGesture {
print("Rc item1 pressed")
self.showingActionSheet = true
}
}
.padding(.leading, 20)
.padding(.trailing, 15)
Text("Front")
}
VStack{
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.drivingLicenceRear)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
.onTapGesture {
print("Rc item1 pressed")
self.showingActionSheet = true
}
}
.padding(.trailing, 20)
Text("Rear")
}
}
}
//MARK: PUC
VStack(alignment: .leading){
Text("PUC")
.padding(.leading, 20)
HStack{
VStack{
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.pucFront)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
.onTapGesture {
print("puc item1 pressed")
self.showingActionSheet = true
}
}
.padding(.leading, 20)
.padding(.trailing, 15)
Text("Front")
}
VStack{
ZStack{
//default image
Image("thumbnailAdd")
.frame(width: geometry.size.width * 0.4, height: 70)
.background()
//Set image
Image(uiImage: self.pucRear)
.resizable()
//.scaledToFill()
.scaledToFit()
.frame(width: geometry.size.width * 0.4, height: 70)
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
// .background()
.cornerRadius(10)
.onTapGesture {
print("puc item2 pressed")
self.showingActionSheet = true
}
}
.padding(.trailing, 20)
Text("Rear")
}
}
}
//MARK: Upload Insurance
VStack(alignment: .leading){
Text("Insurance Policy")
.padding(.leading, 20)
Button(action: {
print("Upload insurance")
}, label: {
HStack{
Image("addPdf")
.resizable()
.frame(width: 50, height: 50)
.padding(.trailing, 15)
.padding(.leading, 20)
Text("Upload Policy Document")
.foregroundColor(.black)
Spacer()
}
.frame(width: geometry.size.width * 0.9, height: 90)
.background()
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(style: StrokeStyle(lineWidth: 1, dash: [10.0]))
.foregroundColor(.orange))
})
.padding([.leading, .trailing], 20)
//.frame(width: geometry.size.width * 0.9, height: 90)
}
}
.padding(.top, 25)
Spacer()
}.frame(maxWidth: UIScreen.main.bounds.width, maxHeight: UIScreen.main.bounds.height).background(Color(red: 0.945, green: 0.949, blue: 0.992)).cornerRadius(25, corners: [.topLeft, .topRight]).edgesIgnoringSafeArea(.bottom)
}
.actionSheet(isPresented: $showingActionSheet) {
ActionSheet(
title: Text("Select a Action"),
buttons: [
.default(Text("Select photo from gallery")) {
showingType = .gallery
isShowPhotoLibrary = true
},
.default(Text("Capture photo from camera")) {
//selection = "Open Camera"
showingType = .camera
isShowPhotoLibrary = true
},
.cancel(Text("Cancel"))
]
)
}
.sheet(isPresented: $isShowPhotoLibrary) { //type in
if showingType == .gallery {
ImagePickerView(sourceType: .photoLibrary, showingType: $showingType, selectedRCfront: self.$rcFront)
}
else {
ImagePickerView(sourceType: .camera, showingType: $showingType, selectedRCfront: self.$rcFront)
}
}
}.onAppear {
//url.loadImage(image)
}
}
// func saveImages(_ image1: UIImage?){
//
// //To create the documents folder
// let document = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
//
// print("document path: \(document)")
//
// let imgUrl = document.appendingPathComponent("RCFront", isDirectory: true)
// print("Image Path with name",imgUrl.path)
//
// //If we wre not getting the image path then
//// if !FileManager.default.fileExists(atPath: imgUrl.path){
//// do{
//// try image1.jpegComp
////
//// }catch{
////
////
//// }
//
//
// }
}
//extension URL {
// func loadImage(_ image: inout UIImage?) {
// if let data = try? Data(contentsOf: self), let loaded = UIImage(data: data) {
// image = loaded
// } else {
// image = nil
// }
// }
//
// func saveImage(_ image: UIImage?) {
// if let image = image {
// if let data = image.jpegData(compressionQuality: 1.0) {
// try? data.write(to: self)
// }
// } else {
// try? FileManager.default.removeItem(at: self)
// }
// }
// }
struct PhotoSelectorView_Previews: PreviewProvider {
static var previews: some View {
DocumentVaultView()
}
}
Editor is loading...