another.im-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPickerComponents/CameraCellPreview.swift
fmodf b3b3b3aef7 mv-experiment (#1)
Reviewed-on: narayana/conversations-classic-ios#1
Co-authored-by: fmodf <fmodf.ios@gmail.com>
Co-committed-by: fmodf <fmodf.ios@gmail.com>
2024-09-03 15:13:58 +00:00

61 lines
2.2 KiB
Swift

import AVFoundation
import SwiftUI
struct CameraCellPreview: View {
@Environment(\.router) var router
@EnvironmentObject var attachments: AttachmentsStore
var body: some View {
Group {
if attachments.cameraAccessGranted {
ZStack {
CameraView()
.aspectRatio(1, contentMode: .fit)
.frame(maxWidth: .infinity)
Image(systemName: "camera")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
.foregroundColor(.white)
.padding(8)
.background(Color.black.opacity(0.5))
.clipShape(Circle())
.padding(8)
}
.onTapGesture {
router.showScreen(.fullScreenCover) { _ in
CameraPicker { data, type in
attachments.sendCaptured(data, type)
router.dismissEnvironment()
}
.ignoresSafeArea(.all)
}
}
} else {
Button {
openAppSettings()
} label: {
ZStack {
Rectangle()
.fill(Color.Material.Background.light)
.overlay {
VStack {
Image(systemName: "camera")
.foregroundColor(.Material.Elements.active)
.font(.system(size: 30))
Text("Allow camera access")
.foregroundColor(.Material.Text.main)
.font(.body3)
}
}
.frame(height: 100)
}
}
}
}
.task {
await attachments.checkCameraAuthorization()
}
}
}