Files
simplex-chat/apps/ios/Shared/Views/LocalAuth/PasscodeView.swift
Stanislav Dmitrenko 99a9fb2e1f ios: self destruct improvements (#3640)
* ios: self destruct improvements

* test

* adapted to stopped chat

* wait until ctrl initialization finishes

* Revert "test"

This reverts commit 7c199293cc.

* refactor

* simplify,fix

* refactor2

* refactor3

* comment

* fix

* fix

* comment

Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>

* flip and rename flag

---------

Co-authored-by: Avently <avently@local>
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
2024-01-09 21:01:41 +00:00

96 lines
2.6 KiB
Swift

//
// PasscodeView.swift
// SimpleX (iOS)
//
// Created by Evgeny on 11/04/2023.
// Copyright © 2023 SimpleX Chat. All rights reserved.
//
import SwiftUI
struct PasscodeView: View {
@Binding var passcode: String
var title: LocalizedStringKey
var reason: String? = nil
var submitLabel: LocalizedStringKey
var submitEnabled: ((String) -> Bool)?
@Binding var buttonsEnabled: Bool
var submit: () -> Void
var cancel: () -> Void
var body: some View {
GeometryReader { g in
if g.size.width < g.size.height * 2 / 3 {
verticalPasscodeView(g)
} else {
horizontalPasscodeView(g)
}
}
.padding(.horizontal, 40)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(uiColor: .systemBackground))
}
private func verticalPasscodeView(_ g: GeometryProxy) -> some View {
VStack(spacing: 8) {
passcodeEntry(g)
Spacer()
HStack(spacing: 48) {
buttonsView()
}
}
.padding(.vertical, 32)
}
private func horizontalPasscodeView(_ g: GeometryProxy) -> some View {
HStack(alignment: .bottom, spacing: 48) {
VStack(spacing: 8) {
passcodeEntry(g)
}
VStack(spacing: 48) {
buttonsView()
}
.frame(maxHeight: g.size.height / 5 * 3 * 0.97)
}
.frame(maxWidth: .infinity)
.padding(.vertical)
}
@ViewBuilder private func passcodeEntry(_ g: GeometryProxy) -> some View {
Text(title)
.font(.title)
.bold()
.padding(.top, 8)
if let reason = reason {
Text(reason).padding(.top, 4)
}
Spacer()
PasscodeEntry(width: g.size.width, height: g.size.height, password: $passcode)
}
@ViewBuilder private func buttonsView() -> some View {
Button(action: cancel) {
Label("Cancel", systemImage: "multiply")
}.disabled(!buttonsEnabled)
Button(action: submit) {
Label(submitLabel, systemImage: "checkmark")
}
.disabled(submitEnabled?(passcode) == false || passcode.count < 4 || !buttonsEnabled)
}
}
struct PasscodeViewView_Previews: PreviewProvider {
static var previews: some View {
PasscodeView(
passcode: Binding.constant(""),
title: "Enter Passcode",
reason: "Unlock app",
submitLabel: "Submit",
buttonsEnabled: Binding.constant(true),
submit: {},
cancel: {}
)
}
}