Created
May 4, 2020 17:06
-
-
Save michzio/07d7ee668cafb028b8bf58b1ea2f23df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct KeyboardAvoiding<Content>: View where Content: View{ | |
@ObservedObject private var avoider : KeyboardAvoider | |
let content: () -> Content | |
let offset: CGFloat | |
init(with avoider: KeyboardAvoider, offset: CGFloat = 0, @ViewBuilder content: @escaping () -> Content) { | |
self.content = content | |
self.avoider = avoider | |
self.offset = offset | |
} | |
var body: some View { | |
let isKeyboard = avoider.slideSize.height != 0 | |
return self.content() | |
.offset(y: isKeyboard ? avoider.slideSize.height + offset : 0) | |
.animation( avoider.isInitialized ? .easeInOut(duration: 1.0) : .none) | |
.registerKeyboardAvoider(avoider) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment