mastodon-app-ufficiale-ipho.../ShareActionExtension/Scene/View/StatusAttachmentView.swift

66 lines
1.7 KiB
Swift
Raw Normal View History

2021-07-19 11:12:45 +02:00
//
// StatusAttachmentView.swift
//
//
// Created by MainasuK Cirno on 2021-7-19.
//
import SwiftUI
struct StatusAttachmentView: View {
let image: UIImage?
let removeButtonAction: () -> Void
var body: some View {
let image = image ?? UIImage.placeholder(color: .systemFill)
Color.clear
.aspectRatio(CGSize(width: 16, height: 9), contentMode: .fill)
.overlay(
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fill)
)
.background(Color.gray)
.cornerRadius(4)
.badgeView(
Button(action: {
removeButtonAction()
}, label: {
Image(systemName: "minus.circle.fill")
.renderingMode(.original)
.font(.system(size: 22, weight: .bold, design: .default))
})
.buttonStyle(BorderlessButtonStyle())
)
}
}
extension View {
func badgeView<Content>(_ content: Content) -> some View where Content: View {
overlay(
ZStack {
content
}
.alignmentGuide(.top) { $0.height / 2 }
.alignmentGuide(.trailing) { $0.width / 2 }
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topTrailing)
)
}
}
struct StatusAttachmentView_Previews: PreviewProvider {
static var previews: some View {
ScrollView {
StatusAttachmentView(
image: UIImage(systemName: "photo"),
removeButtonAction: {
// do nothing
}
)
.padding(20)
}
}
}