File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Sources/KeyboardObserving/viewmodifier Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,8 @@ struct KeyboardObserving: ViewModifier {
1717
1818 func body( content: Content ) -> some View {
1919 content
20- . padding ( [ . bottom ] , keyboardHeight)
20+ . offset ( x : 0 , y : - keyboardHeight)
2121 . edgesIgnoringSafeArea ( ( keyboardHeight > 0 ) ? [ . bottom] : [ ] )
22- . animation ( . easeOut( duration: keyboardAnimationDuration) )
2322 . onReceive (
2423 NotificationCenter . default. publisher ( for: UIResponder . keyboardWillChangeFrameNotification)
2524 . receive ( on: RunLoop . main) ,
@@ -35,12 +34,15 @@ struct KeyboardObserving: ViewModifier {
3534
3635 guard let keyboardFrame = info [ UIResponder . keyboardFrameEndUserInfoKey] as? CGRect
3736 else { return }
38- // If the top of the frame is at the bottom of the screen, set the height to 0.
39- if keyboardFrame. origin. y == UIScreen . main. bounds. height {
40- keyboardHeight = 0
41- } else {
42- // IMPORTANT: This height will _include_ the SafeAreaInset height.
43- keyboardHeight = keyboardFrame. height + offset
37+
38+ withAnimation ( . easeInOut( duration: keyboardAnimationDuration) ) {
39+ // If the top of the frame is at the bottom of the screen, set the height to 0.
40+ if keyboardFrame. origin. y == UIScreen . main. bounds. height {
41+ keyboardHeight = 0
42+ } else {
43+ // IMPORTANT: This height will _include_ the SafeAreaInset height.
44+ keyboardHeight = keyboardFrame. height + offset
45+ }
4446 }
4547 }
4648}
You can’t perform that action at this time.
0 commit comments