File tree Expand file tree Collapse file tree
SnapSafe/Screens/PinVerification Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import SwiftUI
99
1010struct PINVerificationView : View {
1111 @StateObject private var viewModel = PINVerificationViewModel ( )
12+ @FocusState private var isPINFieldFocused : Bool
13+ @Environment ( \. scenePhase) private var scenePhase
1214
1315 var body : some View {
1416 VStack ( spacing: 30 ) {
@@ -31,6 +33,7 @@ struct PINVerificationView: View {
3133 . padding ( )
3234 . background ( RoundedRectangle ( cornerRadius: 8 ) . stroke ( Color . gray, lineWidth: 1 ) )
3335 . padding ( . horizontal, 50 )
36+ . focused ( $isPINFieldFocused)
3437 . onChange ( of: viewModel. pin) { _, newValue in
3538 viewModel. updatePIN ( newValue)
3639 }
@@ -60,6 +63,12 @@ struct PINVerificationView: View {
6063 . onAppear {
6164 viewModel. onAppear ( )
6265 }
66+ . onChange ( of: scenePhase) { _, newPhase in
67+ // Dismiss keyboard when app goes to background or inactive
68+ if newPhase == . background || newPhase == . inactive {
69+ isPINFieldFocused = false
70+ }
71+ }
6372 . obscuredWhenInactive ( )
6473 . screenCaptureProtected ( )
6574 }
You can’t perform that action at this time.
0 commit comments