mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-08-28 00:44:27 +00:00
ios: digital password (instead of device auth) (#2169)
* ios: digital password (instead of device auth) * set, ask, change password * kind of working, sometimes * ZSTack * fix cancel * update title * fix password showing after settings dismissed * disable button when 16 digits entered * fixes * layout on larger screens * do not disable auth when switching to system if system auth failed, refactor * fix enabling auth via the initial alert * support landscape orientation
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// SetAppPaswordView.swift
|
||||
// SimpleX (iOS)
|
||||
//
|
||||
// Created by Evgeny on 10/04/2023.
|
||||
// Copyright © 2023 SimpleX Chat. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
struct SetAppPasscodeView: View {
|
||||
var submit: () -> Void
|
||||
var cancel: () -> Void
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@State private var showKeychainError = false
|
||||
@State private var passcode = ""
|
||||
@State private var enteredPassword = ""
|
||||
@State private var confirming = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if confirming {
|
||||
setPasswordView(
|
||||
title: "Confirm Passcode",
|
||||
submitLabel: "Confirm",
|
||||
submitEnabled: { pwd in pwd == enteredPassword }
|
||||
) {
|
||||
if passcode == enteredPassword {
|
||||
if kcAppPassword.set(passcode) {
|
||||
enteredPassword = ""
|
||||
passcode = ""
|
||||
dismiss()
|
||||
submit()
|
||||
} else {
|
||||
showKeychainError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setPasswordView(title: "New Passcode", submitLabel: "Save") {
|
||||
enteredPassword = passcode
|
||||
passcode = ""
|
||||
confirming = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $showKeychainError) {
|
||||
mkAlert(title: "KeyChain error", message: "Error saving passcode")
|
||||
}
|
||||
}
|
||||
|
||||
private func setPasswordView(title: LocalizedStringKey, submitLabel: LocalizedStringKey, submitEnabled: (((String) -> Bool))? = nil, submit: @escaping () -> Void) -> some View {
|
||||
PasscodeView(passcode: $passcode, title: title, submitLabel: submitLabel, submitEnabled: submitEnabled, submit: submit) {
|
||||
dismiss()
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SetAppPasscodeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SetAppPasscodeView(submit: {}, cancel: {})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user