Skip to content

Commit cdc1415

Browse files
committed
Dismiss keyboard in pin verification view
The keyboard wasn't dismissed when we move the app to the background so this fixes that issue.
1 parent cbfe190 commit cdc1415

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

SnapSafe/Screens/PinVerification/PINVerificationView.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import SwiftUI
99

1010
struct 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
}

0 commit comments

Comments
 (0)