another.im-ios/ConversationsClassic/View/Main/Conversation/Attachments/MediaPickerComponents/CameraCellPreview.swift

61 lines
2.2 KiB
Swift
Raw Normal View History

2024-08-17 10:39:40 +00:00
import AVFoundation
import SwiftUI
struct CameraCellPreview: View {
@Environment(\.router) var router
2024-08-18 09:05:43 +00:00
@EnvironmentObject var attachments: AttachmentsStore
2024-08-17 10:39:40 +00:00
var body: some View {
Group {
2024-08-18 09:05:43 +00:00
if attachments.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
2024-08-17 16:25:35 +00:00
CameraPicker { data, type in
2024-08-18 10:26:54 +00:00
attachments.sendCaptured(data, type)
2024-08-17 16:25:35 +00:00
router.dismissEnvironment()
}
.ignoresSafeArea(.all)
2024-08-17 10:39:40 +00:00
}
}
} 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-18 09:05:43 +00:00
await attachments.checkCameraAuthorization()
2024-08-17 10:39:40 +00:00
}
}
}