-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor SecuritySettings module to SwiftUI
- Loading branch information
Showing
7 changed files
with
199 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
UnstoppableWallet/UnstoppableWallet/Modules/Settings/Security/SecuritySettingsModule.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import UIKit | ||
import SwiftUI | ||
|
||
struct SecuritySettingsModule { | ||
static func view() -> some View { | ||
let viewModel = SecuritySettingsViewModel(pinKit: App.shared.pinKit) | ||
|
||
static func viewController() -> UIViewController { | ||
let service = SecuritySettingsService(pinKit: App.shared.pinKit) | ||
let viewModel = SecuritySettingsViewModel(service: service) | ||
return SecuritySettingsViewController(viewModel: viewModel) | ||
return SecuritySettingsView(viewModel: viewModel) | ||
} | ||
|
||
} |
61 changes: 0 additions & 61 deletions
61
UnstoppableWallet/UnstoppableWallet/Modules/Settings/Security/SecuritySettingsService.swift
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
UnstoppableWallet/UnstoppableWallet/Modules/Settings/Security/SecuritySettingsView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import PinKit | ||
import SwiftUI | ||
|
||
struct SecuritySettingsView: View { | ||
@ObservedObject var viewModel: SecuritySettingsViewModel | ||
@State var editPasscodePresented: Bool = false | ||
|
||
var body: some View { | ||
ScrollableThemeView { | ||
VStack(spacing: .margin32) { | ||
ListSection { | ||
ListRow { | ||
Image("dialpad_alt_2_24") | ||
Text("settings_security.passcode".localized).themeBody() | ||
Spacer() | ||
|
||
if !viewModel.passcodeEnabled { | ||
Image("warning_2_20") | ||
.renderingMode(.template) | ||
.foregroundColor(.themeLucian) | ||
} | ||
|
||
Toggle(isOn: $viewModel.passcodeSwitchOn) {} | ||
.labelsHidden() | ||
} | ||
.sheet(isPresented: $viewModel.setPasscodePresented, onDismiss: { viewModel.cancelSetPasscode() }) { | ||
SetPinView( | ||
cancelAction: { viewModel.cancelSetPasscode() } | ||
).edgesIgnoringSafeArea(.all) | ||
} | ||
.sheet(isPresented: $viewModel.unlockPasscodePresented, onDismiss: { viewModel.cancelUnlock() }) { | ||
UnlockPinView( | ||
unlockAction: { viewModel.onUnlock() }, | ||
cancelAction: { viewModel.cancelUnlock() } | ||
).edgesIgnoringSafeArea(.all) | ||
} | ||
|
||
if viewModel.passcodeEnabled { | ||
ClickableRow(action: { editPasscodePresented = true }) { | ||
Text("settings_security.change_pin".localized).themeBody() | ||
Image.disclosureIcon | ||
} | ||
.sheet(isPresented: $editPasscodePresented) { | ||
EditPinView().edgesIgnoringSafeArea(.all) | ||
} | ||
} | ||
} | ||
|
||
if viewModel.passcodeEnabled && viewModel.biometryAvailable { | ||
ListSection { | ||
ListRow { | ||
Image(viewModel.biometryIconName) | ||
Toggle(isOn: $viewModel.biometryEnabled) { | ||
Text(viewModel.biometryTitle).themeBody() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.padding(EdgeInsets(top: .margin12, leading: .margin16, bottom: .margin32, trailing: .margin16)) | ||
} | ||
} | ||
} | ||
|
||
struct SetPinView: UIViewControllerRepresentable, ISetPinDelegate { | ||
typealias UIViewControllerType = UIViewController | ||
|
||
let cancelAction: () -> () | ||
|
||
func makeUIViewController(context: Context) -> UIViewController { | ||
App.shared.pinKit.setPinModule(delegate: self) | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} | ||
|
||
func didCancelSetPin() { | ||
cancelAction() | ||
} | ||
} | ||
|
||
struct EditPinView: UIViewControllerRepresentable { | ||
typealias UIViewControllerType = UIViewController | ||
|
||
func makeUIViewController(context: Context) -> UIViewController { | ||
return App.shared.pinKit.editPinModule | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} | ||
} | ||
|
||
struct UnlockPinView: UIViewControllerRepresentable { | ||
typealias UIViewControllerType = UIViewController | ||
|
||
let unlockAction: () -> () | ||
let cancelAction: () -> () | ||
|
||
func makeUIViewController(context: Context) -> UIViewController { | ||
return App.shared.pinKit.unlockPinModule( | ||
biometryUnlockMode: .disabled, | ||
insets: .zero, | ||
cancellable: true, | ||
autoDismiss: true, | ||
onUnlock: unlockAction, | ||
onCancelUnlock: cancelAction | ||
) | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} | ||
} |
Oops, something went wrong.