-
Notifications
You must be signed in to change notification settings - Fork 22
/
ContentView.swift
55 lines (45 loc) · 1.18 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// ContentView.swift
// HCaptcha_SwiftUI_Example
//
// Copyright © 2022 HCaptcha. MIT License.
//
import SwiftUI
import HCaptcha
// Wrapper-view to provide UIView instance
struct UIViewWrapperView: UIViewRepresentable {
var uiview = UIView()
func makeUIView(context: Context) -> UIView {
uiview.backgroundColor = .gray
return uiview
}
func updateUIView(_ view: UIView, context: Context) {
// nothing to update
}
}
// Example of hCaptcha usage
struct HCaptchaView: View {
private(set) var hcaptcha: HCaptcha!
let placeholder = UIViewWrapperView()
var body: some View {
VStack{
placeholder.frame(width: 640, height: 640, alignment: .center)
Button(
"validate",
action: { showCaptcha(placeholder.uiview) }
).padding()
}
}
func showCaptcha(_ view: UIView) {
hcaptcha.validate(on: view) { result in
print(result)
}
}
init() {
hcaptcha = try? HCaptcha()
let hostView = self.placeholder.uiview
hcaptcha.configureWebView { webview in
webview.frame = hostView.bounds
}
}
}