How to show web content as QR code in SwiftUI in watchOS

Issue #449

WatchKit does not have Web component, despite the fact that we can view web content

A workaround is to show url as QR code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import SwiftUI

struct QRCodeView: View {
let title: String
let url: URL

var body: some View {
GeometryReader { geometry in
VStack {
self.makeImage(size: geometry.size)
.padding(.top, 10)
Text("Scan to open")
.font(.system(.footnote))
}.navigationBarTitle(self.title)
}
}

private func makeImage(size: CGSize) -> some View {
let value = size.height - 30
return RemoteImage(url: self.url)
.frame(width: value, height: value, alignment: .center)
}
}

Comments