Allow Uploading Photos and Videos from Camera

Changelog-Added: Upload Photos and Videos from Camera
Closes: #840
This commit is contained in:
Joel Klabo
2023-03-29 20:04:20 -07:00
committed by William Casarin
parent b9fc3f90d1
commit 81683f980a
2 changed files with 22 additions and 1 deletions

View File

@@ -46,5 +46,9 @@
<key>NSAllowsArbitraryLoads</key> <key>NSAllowsArbitraryLoads</key>
<true/> <true/>
</dict> </dict>
<key>NSCameraUsageDescription</key>
<string>Damus needs access to your camera if you want to upload photos from it</string>
<key>NSMicrophoneUsageDescription</key>
<string>Damus needs access to your microphone if you want to upload recorded videos from it</string>
</dict> </dict>
</plist> </plist>

View File

@@ -19,6 +19,7 @@ struct PostView: View {
@FocusState var focus: Bool @FocusState var focus: Bool
@State var showPrivateKeyWarning: Bool = false @State var showPrivateKeyWarning: Bool = false
@State var attach_media: Bool = false @State var attach_media: Bool = false
@State var attach_camera: Bool = false
@State var error: String? = nil @State var error: String? = nil
@StateObject var image_upload: ImageUploadModel = ImageUploadModel() @StateObject var image_upload: ImageUploadModel = ImageUploadModel()
@@ -80,11 +81,20 @@ struct PostView: View {
}) })
} }
var CameraButton: some View {
Button(action: {
attach_camera = true
}, label: {
Image(systemName: "camera")
})
}
var AttachmentBar: some View { var AttachmentBar: some View {
HStack(alignment: .center) { HStack(alignment: .center) {
ImageButton ImageButton
.disabled(image_upload.progress != nil) CameraButton
} }
.disabled(image_upload.progress != nil)
} }
var PostButton: some View { var PostButton: some View {
@@ -221,6 +231,13 @@ struct PostView: View {
handle_upload(media: .video(url)) handle_upload(media: .video(url))
} }
} }
.sheet(isPresented: $attach_camera) {
ImagePicker(sourceType: .camera, damusState: damus_state) { img in
handle_upload(media: .image(img))
} onVideoPicked: { url in
handle_upload(media: .video(url))
}
}
.onAppear() { .onAppear() {
if let replying_to { if let replying_to {
if damus_state.drafts.replies[replying_to] == nil { if damus_state.drafts.replies[replying_to] == nil {