wip
This commit is contained in:
parent
8aa1ed6b75
commit
c2fb21f932
|
@ -65,4 +65,5 @@
|
|||
"Attachment.Tab.files" = "Files";
|
||||
"Attachment.Tab.location" = "Location";
|
||||
"Attachment.Tab.contacts" = "Contacts";
|
||||
"Attachment.Send.media" = "Send media";
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import Photos
|
|||
import SwiftUI
|
||||
|
||||
struct SelectedMedia {
|
||||
let path: String
|
||||
let id: String
|
||||
}
|
||||
|
||||
struct AttachmentMediaPickerView: View {
|
||||
|
@ -18,6 +18,8 @@ struct AttachmentMediaPickerView: View {
|
|||
var body: some View {
|
||||
let columns = Array(repeating: GridItem(.flexible(), spacing: 0), count: 3)
|
||||
|
||||
VStack(spacing: 0) {
|
||||
// List of media
|
||||
ScrollView(showsIndicators: false) {
|
||||
LazyVGrid(columns: columns, spacing: 0) {
|
||||
// For camera
|
||||
|
@ -58,7 +60,7 @@ struct AttachmentMediaPickerView: View {
|
|||
}
|
||||
}
|
||||
|
||||
// For pictures
|
||||
// For gallery
|
||||
if isGalleryAccessGranted {
|
||||
ForEach(thumbnails) { photo in
|
||||
photo
|
||||
|
@ -86,6 +88,29 @@ struct AttachmentMediaPickerView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send panel
|
||||
Rectangle()
|
||||
.foregroundColor(.Material.Shape.black)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: self.selectedMedia.isEmpty ? 0 : 50)
|
||||
.overlay {
|
||||
HStack {
|
||||
Text(L10n.Attachment.Send.media)
|
||||
.foregroundColor(.Material.Text.white)
|
||||
.font(.body1)
|
||||
Image(systemName: "arrow.up.circle")
|
||||
.foregroundColor(.Material.Text.white)
|
||||
.font(.body1)
|
||||
.padding(.leading, 8)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.clipped()
|
||||
.onTapGesture {
|
||||
print("Send media files")
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 0.2) {
|
||||
checkCameraAccess()
|
||||
|
@ -160,7 +185,7 @@ struct AttachmentMediaPickerView: View {
|
|||
image?.scaleAndCropImage(toExampleSize: CGSize(width: gridSize, height: gridSize), completion: { image in
|
||||
if let image {
|
||||
DispatchQueue.main.async {
|
||||
self.thumbnails.append(ThumbnailView(image: image, gridSize: gridSize, selected: $selectedMedia))
|
||||
self.thumbnails.append(ThumbnailView(id: asset.localIdentifier, image: image, gridSize: gridSize, selected: $selectedMedia))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -177,7 +202,7 @@ struct AttachmentMediaPickerView: View {
|
|||
thumbnail.scaleAndCropImage(toExampleSize: CGSize(width: gridSize, height: gridSize), completion: { image in
|
||||
if let image {
|
||||
DispatchQueue.main.async {
|
||||
self.thumbnails.append(ThumbnailView(image: image, gridSize: gridSize, selected: $selectedMedia, duration: asset.duration.minAndSec))
|
||||
self.thumbnails.append(ThumbnailView(id: asset.localIdentifier, image: image, gridSize: gridSize, selected: $selectedMedia, duration: asset.duration.minAndSec))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -201,7 +226,7 @@ struct AttachmentMediaPickerView: View {
|
|||
}
|
||||
|
||||
private struct ThumbnailView: Identifiable, View {
|
||||
let id = UUID()
|
||||
let id: String
|
||||
let gridSize: CGFloat
|
||||
let duration: String?
|
||||
|
||||
|
@ -210,7 +235,8 @@ private struct ThumbnailView: Identifiable, View {
|
|||
@State private var selected = false
|
||||
@Binding var selectedMedia: [SelectedMedia]
|
||||
|
||||
init(image: UIImage, gridSize: CGFloat, selected: Binding<[SelectedMedia]>, duration: String? = nil) {
|
||||
init(id: String, image: UIImage, gridSize: CGFloat, selected: Binding<[SelectedMedia]>, duration: String? = nil) {
|
||||
self.id = id
|
||||
self.image = image
|
||||
self.gridSize = gridSize
|
||||
_selectedMedia = selected
|
||||
|
@ -246,10 +272,6 @@ private struct ThumbnailView: Identifiable, View {
|
|||
.frame(width: 30, height: 30)
|
||||
.shadow(color: .black, radius: 2)
|
||||
.foregroundColor(.Material.Shape.white)
|
||||
// Circle()
|
||||
// .fill(Color.Material.Shape.white)
|
||||
// .frame(width: 30, height: 30)
|
||||
// .shadow(color: .black, radius: 2)
|
||||
.overlay {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.Material.Elements.active)
|
||||
|
@ -265,9 +287,9 @@ private struct ThumbnailView: Identifiable, View {
|
|||
withAnimation {
|
||||
selected.toggle()
|
||||
if selected {
|
||||
selectedMedia.append(SelectedMedia(path: id.uuidString))
|
||||
selectedMedia.append(SelectedMedia(id: id))
|
||||
} else {
|
||||
selectedMedia.removeAll { $0.path == id.uuidString }
|
||||
selectedMedia.removeAll { $0.id == id }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue