File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import MapKit
1010import RealmSwift
1111import ARKit
1212import SwiftUI
13+ import Combine
1314
1415
1516// Extension to check if a polyline intersects with a coordinate
@@ -161,4 +162,27 @@ extension UIApplication {
161162 static func window( ) -> UIWindow ? {
162163 return UIApplication . shared. connectedScenes. flatMap { ( $0 as? UIWindowScene ) ? . windows ?? [ ] } . first { $0. isKeyWindow }
163164 }
165+
166+ var safeAreaBottomInset : CGFloat {
167+ guard let windowScene = connectedScenes. first as? UIWindowScene ,
168+ let window = windowScene. windows. first ( where: \. isKeyWindow) else {
169+ return 0
170+ }
171+ return window. safeAreaInsets. bottom
172+ }
173+ }
174+
175+ extension Publishers {
176+ static var keyboardHeight : AnyPublisher < CGFloat , Never > {
177+ let willShow = NotificationCenter . default
178+ . publisher ( for: UIResponder . keyboardWillShowNotification)
179+ . map { ( $0. userInfo ? [ UIResponder . keyboardFrameEndUserInfoKey] as? CGRect ) ? . height ?? 0 }
180+
181+ let willHide = NotificationCenter . default
182+ . publisher ( for: UIResponder . keyboardWillHideNotification)
183+ . map { _ in CGFloat ( 0 ) }
184+
185+ return MergeMany ( willShow, willHide)
186+ . eraseToAnyPublisher ( )
187+ }
164188}
Original file line number Diff line number Diff line change 77
88import SwiftUI
99import CoreLocation
10-
10+ import Combine
1111
1212struct LongForm : View , QuestForm {
1313
@@ -58,6 +58,8 @@ struct LongForm: View, QuestForm {
5858
5959 @StateObject private var noteViewModel = NotesViewModel ( )
6060
61+ @State private var keyboardHeight : CGFloat = 0
62+
6163 var body : some View {
6264 ZStack {
6365 VStack ( alignment: . leading) {
@@ -192,6 +194,13 @@ struct LongForm: View, QuestForm {
192194 Text ( " No Quests available " )
193195 }
194196 }
197+ . padding ( . bottom, keyboardHeight)
198+ . onReceive ( Publishers . keyboardHeight) { height in
199+ let safeAreaBottom = UIApplication . shared. safeAreaBottomInset
200+ withAnimation {
201+ keyboardHeight = max ( 0 , height - safeAreaBottom)
202+ }
203+ }
195204 }
196205 . hideKeyboardOnTap ( )
197206
You can’t perform that action at this time.
0 commit comments