35 lines
1.0 KiB
Swift
35 lines
1.0 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct QRCodeView: View {
|
|
@Environment(AppState.self) private var appState
|
|
let payload: String
|
|
|
|
var body: some View {
|
|
if let image = appState.qrCodeService.qrCode(from: payload) {
|
|
Image(decorative: image, scale: 1)
|
|
.resizable()
|
|
.interpolation(.none)
|
|
.scaledToFit()
|
|
.accessibilityLabel(String.localized("QR code"))
|
|
} else {
|
|
Image(systemName: "qrcode")
|
|
.resizable()
|
|
.scaledToFit()
|
|
.foregroundStyle(Color.Text.secondary)
|
|
.padding(Design.Spacing.large)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let container = try! ModelContainer(for: BusinessCard.self, Contact.self)
|
|
let context = container.mainContext
|
|
BusinessCard.createSamples(in: context)
|
|
let cards = try! context.fetch(FetchDescriptor<BusinessCard>())
|
|
|
|
return QRCodeView(payload: cards.first?.vCardPayload ?? "")
|
|
.environment(AppState(modelContext: context))
|
|
.padding()
|
|
}
|