Allow pasting and attaching images in question Other fields on iPhone
This commit is contained in:
@@ -267,12 +267,12 @@ extension View {
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
private struct ComposerMenu: View {
|
||||
struct ComposerMenu: View {
|
||||
let key: String
|
||||
let photos: Bool
|
||||
let models: [String]
|
||||
let selected: String
|
||||
let choose: @MainActor @Sendable (String) -> Void
|
||||
var models: [String] = []
|
||||
var selected = ""
|
||||
var choose: @MainActor @Sendable (String) -> Void = { _ in }
|
||||
@Environment(Store.self) private var store
|
||||
@Environment(Overlays.self) private var overlays
|
||||
@ViewState private var picking = false
|
||||
@@ -286,6 +286,11 @@ private struct ComposerMenu: View {
|
||||
} label: {
|
||||
Label("Attach photos", systemImage: "photo")
|
||||
}
|
||||
Button {
|
||||
paste()
|
||||
} label: {
|
||||
Label("Paste image", systemImage: "doc.on.clipboard")
|
||||
}
|
||||
}
|
||||
if !models.isEmpty {
|
||||
Picker("Model for the next turn", selection: Binding(get: { selected }, set: choose)) {
|
||||
@@ -316,6 +321,19 @@ private struct ComposerMenu: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func paste() {
|
||||
let images = UIPasteboard.general.images ?? []
|
||||
if images.isEmpty {
|
||||
overlays.showAlert("The clipboard has no image.")
|
||||
return
|
||||
}
|
||||
for image in images {
|
||||
if let data = image.jpegData(compressionQuality: 0.85) {
|
||||
store.images.add(key, data, name: nil, overlays)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user