-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
SwiftUIViewFactory.swift
93 lines (75 loc) · 4.1 KB
/
SwiftUIViewFactory.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// SwiftUIViewFactory.swift
// Strongbox
//
// Created by Strongbox on 05/07/2023.
// Copyright © 2023 Mark McGuill. All rights reserved.
//
import Foundation
import SwiftUI
class SwiftUIViewFactory: NSObject {
@objc static func makeImportResultViewController(messages: [ImportMessage] = [],
dismissHandler: @escaping ((_ cancel: Bool) -> Void)) -> UIViewController
{
let hostingController = UIHostingController(rootView: ImportResultView(dismiss: dismissHandler, messages: messages))
return hostingController
}
@objc static func makeSaleOfferViewController(sale: Sale,
existingSubscriber: Bool,
redeemHandler: @escaping (() -> Void),
onLifetimeHandler: @escaping (() -> Void),
dismissHandler: @escaping (() -> Void)) -> UIViewController
{
let hostingController = UIHostingController(rootView: SaleOfferView(dismiss: dismissHandler, onLifetime: onLifetimeHandler, redeem: redeemHandler, sale: sale, existingSubscriber: existingSubscriber))
return hostingController
}
@objc static func makeWiFiSyncPasscodeViewController(_ server: WiFiSyncServerConfig, onDone: @escaping ((_ server: WiFiSyncServerConfig, _ pinCode: String?) -> Void)) -> UIViewController {
let hostingController = UIHostingController(rootView: PasscodeEntryView(server: server, onDone: onDone))
return hostingController
}
@objc static func showKeyFileGeneratorScreen(keyFile: KeyFile,
onPrint: @escaping (() -> Void),
onSave: @escaping (() -> Bool),
onDismiss: @escaping (() -> Void)) -> UIViewController
{
let view = GenerateKeyFileScreen(keyFile: keyFile, onPrint: onPrint, onSave: onSave) {
onDismiss()
}
let hostingController = UIHostingController(rootView: view)
return hostingController
}
@objc static func showKeyFileRecoveryScreen(onRecover: @escaping ((_ keyFile: KeyFile) -> Void),
onDismiss: @escaping (() -> Void)) -> UIViewController
{
let view = RecoverKeyFileScreen(verifyHash: { codes, hash in
guard let keyFile = KeyFile.fromHexCodes(codes) else {
return false
}
return keyFile.hashString == hash
},
validateCodes: { codes in
KeyFile.fromHexCodes(codes) != nil
},
onRecover: { codes in
guard let keyFile = KeyFile.fromHexCodes(codes) else {
NSLog("🔴 ERROR: Invalid Hex Codes for Key File, should never happen!")
return
}
onRecover(keyFile)
onDismiss()
}) {
onDismiss()
}
let hostingController = UIHostingController(rootView: view)
return hostingController
}
@objc static func getLargeTextDisplayView(text: String, font: UIFont, colorMapper: @escaping ((_ character: String) -> UIColor), onTapped: @escaping (() -> Void)) -> UIViewController {
let view = LargeTextDisplayView(text: text, font: Font(font), colorMapper: { char in
Color(colorMapper(char))
}) {
onTapped()
}
let hostingController = UIHostingController(rootView: view.ignoresSafeArea())
return hostingController
}
}