Editor: Add Take Photo option close #1339

This commit is contained in:
Thomas Ricouard 2023-04-03 13:54:16 +02:00
parent ab51d57648
commit 477dd520b9
22 changed files with 79 additions and 0 deletions

View file

@ -455,6 +455,7 @@
"status.editor.text.placeholder" = "Пра што вы думаеце?";
"status.editor.visibility" = "Бачнасць допісу";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "Пры загрузцы паведамленняў адбылася памылка, паўтарыце спробу.";
"status.error.message" = "Адбылася памылка ў кантэксце гэтай публікацыі, паспрабуйце яшчэ раз.";

View file

@ -449,6 +449,7 @@
"status.editor.text.placeholder" = "Què us passa pel cap?";
"status.editor.visibility" = "Visibilitat de la publicació";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "S'ha produït un error en carregar les publicacions, torneu-ho a provar.";
"status.error.message" = "S'ha produït un error en el context d'aquesta publicació, torneu-ho a provar.";

View file

@ -444,6 +444,7 @@
"status.editor.text.placeholder" = "Woran denkst du?";
"status.editor.visibility" = "Sichtbarkeit";
"status.editor.photo-library" = "Fotoalbum";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Dateien durchsuchen";
"status.error.loading.message" = "Beim Laden der Beiträge ist ein Fehler aufgetreten. Bitte versuche es erneut.";
"status.error.message" = "Es ist ein Fehler aufgetreten. Bitte versuche es erneut.";

View file

@ -450,6 +450,7 @@
"status.editor.text.placeholder" = "What's on your mind?";
"status.editor.visibility" = "Post visibility";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "An error occurred while loading posts, please try again.";
"status.error.message" = "An error occurred in the context of this post, please try again.";

View file

@ -451,6 +451,7 @@
"status.editor.text.placeholder" = "What's on your mind?";
"status.editor.visibility" = "Post visibility";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "An error occurred while loading posts, please try again.";
"status.error.message" = "An error occurred in the context of this post, please try again.";

View file

@ -451,6 +451,7 @@
"status.editor.text.placeholder" = "¿En qué estás pensando?";
"status.editor.visibility" = "Visibilidad de la publicación";
"status.editor.photo-library" = "Fototeca";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Archivos";
"status.error.loading.message" = "Ha ocurrido un error al cargar las publicaciones, por favor, vuelve a intentarlo.";
"status.error.message" = "Ha ocurrido un error al cargar el contexto de esta publicación, por favor, vuelve a intentarlo.";

View file

@ -444,6 +444,7 @@
"status.editor.text.placeholder" = "Zer duzu buruan?";
"status.editor.visibility" = "Bidalketaren irismena";
"status.editor.photo-library" = "Argazki-liburutegia";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Arakatu fitxategiak";
"status.error.loading.message" = "Errorea bidalketak kargatzean; saiatu berriro.";
"status.error.message" = "Errorea bidalketa honen testuinguruan; saiatu berriro.";

View file

@ -446,6 +446,7 @@
"status.editor.text.placeholder" = "Qu'est-ce qui vous passe par la tête ?";
"status.editor.visibility" = "Visibilité de la publication";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "Une erreur s'est produite lors du chargement des publications, veuillez réessayer.";
"status.error.message" = "Une erreur s'est produite dans le contexte de cette publication, veuillez réessayer.";

View file

@ -450,6 +450,7 @@
"status.editor.text.placeholder" = "A cosa stai pensando?";
"status.editor.visibility" = "Visibilità del post";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "Si è verificato un errore durante il caricamento dei post, per favore riprova.";
"status.error.message" = "Si è verificato un errore durante il caricamento del post, per favore riprova.";

View file

@ -450,6 +450,7 @@
"status.editor.text.placeholder" = "いま、何を考えているの?";
"status.editor.visibility" = "投稿の公開範囲";
"status.editor.photo-library" = "写真ライブラリ";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "ファイルの参照";
"status.error.loading.message" = "投稿の読み込み中にエラーが発生しました、もう一度試してください";
"status.error.message" = "この投稿のコンテキストでエラーが発生しました、もう一度試してください";

View file

@ -452,6 +452,7 @@
"status.editor.text.placeholder" = "무슨 생각을 하고 계신가요?";
"status.editor.visibility" = "글 공개 범위";
"status.editor.photo-library" = "사진 보관함";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "파일 앱";
"status.error.loading.message" = "글을 불러오지 못했습니다. 다시 시도해주세요.";
"status.error.message" = "글의 상세 정보를 불러오지 못했습니다. 다시 시도해주세요.";

View file

@ -450,6 +450,7 @@
"status.editor.text.placeholder" = "Hva tenker du på?";
"status.editor.visibility" = "Innleggssynlighet";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "Det oppsto en feil under innlasting av innlegg, prøv igjen.";
"status.error.message" = "Det oppsto en feil i forbindelse med dette innlegget, prøv igjen.";

View file

@ -444,6 +444,7 @@
"status.editor.text.placeholder" = "Waar denk je aan?";
"status.editor.visibility" = "Zichtbaarheid";
"status.editor.photo-library" = "Fotobibliotheek";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Bestanden";
"status.error.loading.message" = "Er heeft zich een fout voorgedaan tijdens het laden van je posts. Probeer het nogmaals.";
"status.error.message" = "Er heeft zich een fout voorgedaan. Probeer het nogmaals.";

View file

@ -446,6 +446,7 @@
"status.editor.text.placeholder" = "Co ci chodzi po głowie?";
"status.editor.visibility" = "Widoczność postu";
"status.editor.photo-library" = "Biblioteka zdjęć";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Przeglądaj pliki";
"status.error.loading.message" = "Wystąpił błąd podczas ładowania postów, spróbuj ponownie.";
"status.error.message" = "Wystąpił błąd dotyczący tego postu, proszę spróbuj ponownie.";

View file

@ -450,6 +450,7 @@
"status.editor.text.placeholder" = "O que você está pensando?";
"status.editor.visibility" = "Visibilidade da postagem";
"status.editor.photo-library" = "Biblioteca de Fotos";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Procurar Arquivos";
"status.error.loading.message" = "Ocorreu um erro enquanto as postagens eram carregadas, por favor, tente novamente.";
"status.error.message" = "Ocorreu um erro com esta postagem, por favor, tente novamente.";

View file

@ -446,6 +446,7 @@
"status.editor.text.placeholder" = "Aklında ne var?";
"status.editor.visibility" = "Görüntü görünürlüğü";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "Gönderi yüklenirken bir hata oluştu, lütfen tekrar deneyin.";
"status.error.message" = "Bu gönderi bağlamında bir hata oluştu, lütfen tekrar deneyin.";

View file

@ -451,6 +451,7 @@
"status.editor.text.placeholder" = "Що у вас на думці?";
"status.editor.visibility" = "Видимість допису";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "An error occurred while loading posts, please try again.";
"status.error.message" = "An error occurred in the context of this post, please try again.";

View file

@ -449,6 +449,7 @@
"status.editor.text.placeholder" = "在想些什么呢?";
"status.editor.visibility" = "嘟文可见性";
"status.editor.photo-library" = "Photos Library";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "Browse Files";
"status.error.loading.message" = "加载嘟文时发生错误,请重试。";
"status.error.message" = "嘟文的上下文出现了错误,请重试。";

View file

@ -451,6 +451,7 @@
"status.editor.text.placeholder" = "您在想些什麼呢?";
"status.editor.visibility" = "嘟文能見度";
"status.editor.photo-library" = "相片圖庫";
"status.editor.camera-picker" = "Take Photo";
"status.editor.browse-file" = "瀏覽檔案";
"status.error.loading.message" = "下載嘟文時發生錯誤,請再試一次。";
"status.error.message" = "嘟文上下文發生錯誤,請再試一次。";

View file

@ -21,6 +21,7 @@ struct StatusEditorAccessoryView: View {
@State private var isLoadingAIRequest: Bool = false
@State private var isPhotosPickerPresented: Bool = false
@State private var isFileImporterPresented: Bool = false
@State private var isCameraPickerPresented: Bool = false
var body: some View {
VStack(spacing: 0) {
@ -34,6 +35,11 @@ struct StatusEditorAccessoryView: View {
} label: {
Label("status.editor.photo-library", systemImage: "photo")
}
Button {
isCameraPickerPresented = true
} label: {
Label("status.editor.camera-picker", systemImage: "camera")
}
Button {
isFileImporterPresented = true
} label: {
@ -48,6 +54,7 @@ struct StatusEditorAccessoryView: View {
}
.photosPicker(isPresented: $isPhotosPickerPresented,
selection: $viewModel.selectedMedias,
maxSelectionCount: 4,
matching: .any(of: [.images, .videos]))
.fileImporter(isPresented: $isFileImporterPresented,
allowedContentTypes: [.image, .video],
@ -57,6 +64,16 @@ struct StatusEditorAccessoryView: View {
viewModel.processURLs(urls: urls)
}
}
.fullScreenCover(isPresented: $isCameraPickerPresented, content: {
StatusEditorCameraPickerView(selectedImage: .init(get: {
nil
}, set: { image in
if let image {
viewModel.processCameraPhoto(image: image)
}
}))
.background(.black)
})
.accessibilityLabel("accessibility.editor.button.attach-photo")
.disabled(viewModel.showPoll)

View file

@ -0,0 +1,35 @@
import UIKit
import SwiftUI
struct StatusEditorCameraPickerView: UIViewControllerRepresentable {
@Binding var selectedImage: UIImage?
@Environment(\.presentationMode) var isPresented
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
let picker: StatusEditorCameraPickerView
init(picker: StatusEditorCameraPickerView) {
self.picker = picker
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let selectedImage = info[.originalImage] as? UIImage else { return }
self.picker.selectedImage = selectedImage
self.picker.isPresented.wrappedValue.dismiss()
}
}
func makeUIViewController(context: Context) -> UIImagePickerController {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .camera
return imagePicker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {
}
func makeCoordinator() -> Coordinator {
Coordinator(picker: self)
}
}

View file

@ -372,6 +372,14 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
processItemsProvider(items: items)
}
func processCameraPhoto(image: UIImage) {
mediasImages.append(.init(image: image,
movieTransferable: nil,
gifTransferable: nil,
mediaAttachment: nil,
error: nil))
}
private func processItemsProvider(items: [NSItemProvider]) {
Task {
var initialText: String = ""