2024-08-17 10:39:40 +00:00
|
|
|
import AVFoundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct CameraCellPreview: View {
|
|
|
|
@Environment(\.router) var router
|
2024-08-17 11:22:47 +00:00
|
|
|
@EnvironmentObject var store: ConversationStore
|
2024-08-17 10:39:40 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
2024-08-17 11:22:47 +00:00
|
|
|
if store.cameraAccessGranted {
|
2024-08-17 10:39:40 +00:00
|
|
|
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 {
|
2024-08-17 11:22:47 +00:00
|
|
|
await store.checkCameraAuthorization()
|
2024-08-17 10:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|