Reportage/Views/Settings/AppLockView.swift (2498B)
1import SwiftUI
2
3
4struct AppLockView: View {
5 @Environment(AppLock.self) private var lock
6
7 var body: some View {
8 List {
9 Section {
10 Toggle(isOn: isEnabled) {
11 Text("Lock with \(Text(lock.methodName))", comment: "Turns the app lock on; the method is Face ID, Touch ID or Passcode")
12 }
13 .disabled(!lock.isAvailable)
14 .settingsRow()
15 .listRowSeparator(.hidden, edges: .top)
16 if lock.settings.isEnabled {
17 Picker("Require", selection: delay) {
18 ForEach(AppLockSettings.Delay.allCases, id: \.self) { delay in
19 DelayText(delay: delay).tag(delay)
20 }
21 }
22 .settingsRow()
23 }
24 SettingsNote {
25 if lock.isAvailable {
26 Text(
27 "Reportage asks for \(Text(lock.methodName)) when it's opened, and hides its contents in the app switcher. Notification actions, Instant Reports and Shortcuts still work while it's locked."
28 )
29 } else {
30 Text("Set a passcode for this iPhone to lock Reportage.")
31 }
32 }
33 }
34 }
35 .listStyle(.plain)
36 .scrollContentBackground(.hidden)
37 .tabBarClearance()
38 .background(Theme.paper)
39 .foregroundStyle(Theme.ink)
40 .navigationTitle("App Lock")
41 .navigationBarTitleDisplayMode(.inline)
42 .toolbar(.visible, for: .navigationBar)
43 }
44
45
46 private var isEnabled: Binding<Bool> {
47 Binding(
48 get: { lock.settings.isEnabled },
49 set: { isOn in Task { await lock.setEnabled(isOn) } })
50 }
51
52 private var delay: Binding<AppLockSettings.Delay> {
53 Binding(
54 get: { lock.settings.delay },
55 set: { lock.setDelay($0) })
56 }
57}
58
59private struct DelayText: View {
60 let delay: AppLockSettings.Delay
61
62 var body: some View {
63 switch delay {
64 case .immediately: Text("Immediately")
65 case .oneMinute: Text("After 1 Minute")
66 case .fiveMinutes: Text("After 5 Minutes")
67 case .fifteenMinutes: Text("After 15 Minutes")
68 }
69 }
70}