another.im-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift
2024-08-17 14:12:13 +02:00

58 lines
2 KiB
Swift

import AVFoundation
import SwiftUI
struct CameraCellPreview: View {
@Environment(\.router) var router
@EnvironmentObject var store: FileStore
var body: some View {
Group {
if store.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()
.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 store.checkCameraAuthorization()
}
}
}