You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.3 KiB

import SwiftUI
// MARK: - QR
struct QRCodePreviewView: View {
let qrCodeImage: UIImage?
let formattedContent: String
let qrCodeType: QRCodeType
var body: some View {
VStack(spacing: 16) {
HStack {
InputTitleView.required(NSLocalizedString("preview", comment: "Preview"), icon: "eye")
.padding(.horizontal, 20)
Spacer()
}
//
VStack(spacing: 16) {
//
if let qrImage = qrCodeImage {
Image(uiImage: qrImage)
.interpolation(.none)
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
.background(Color.white)
.cornerRadius(12)
.shadow(color: .black.opacity(0.1), radius: 8, x: 0, y: 4)
} else {
//
RoundedRectangle(cornerRadius: 12)
.fill(Color(.systemGray5))
.frame(width: 200, height: 200)
.overlay(
VStack(spacing: 8) {
Image(systemName: "qrcode")
.font(.system(size: 40))
.foregroundColor(.secondary)
Text(NSLocalizedString("cannot_generate_qrcode", comment: "Cannot generate QR code"))
.font(.caption)
.foregroundColor(.secondary)
}
)
}
//
VStack(alignment: .leading, spacing: 8) {
HStack {
Text(NSLocalizedString("content", comment: "Content"))
.font(.caption)
.foregroundColor(.secondary)
Spacer()
Text(qrCodeType.displayName)
.font(.caption)
.padding(.horizontal, 6)
.padding(.vertical, 2)
.background(Color.orange.opacity(0.1))
.foregroundColor(.orange)
.cornerRadius(4)
}
Text(formattedContent)
.font(.body)
.foregroundColor(.primary)
.textSelection(.enabled)
.lineLimit(nil)
}
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
}
.padding()
.background(Color(.systemBackground))
.cornerRadius(12)
.shadow(color: .black.opacity(0.05), radius: 4, x: 0, y: 2)
}
}
}
#Preview {
QRCodePreviewView(
qrCodeImage: nil,
formattedContent: NSLocalizedString("sample_content", comment: "Sample content"),
qrCodeType: .text
)
}