Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created October 4, 2020 14:56
Show Gist options
  • Save prafullakumar/6223a24769ef24b9fe00bff5655396cb to your computer and use it in GitHub Desktop.
Save prafullakumar/6223a24769ef24b9fe00bff5655396cb to your computer and use it in GitHub Desktop.
struct KeyboardView<Content, ToolBar> : View where Content : View, ToolBar: View {
@StateObject private var keyboard: KeyboardResponder = KeyboardResponder()
let toolbarFrame: CGSize = CGSize(width: UIScreen.main.bounds.width, height: 40.0)
var content: () -> Content
var toolBar: () -> ToolBar
var body: some View {
ZStack {
content()
.padding(.bottom, (keyboard.currentHeight == 0) ? 0 : toolbarFrame.height)
VStack {
Spacer()
toolBar()
.frame(width: toolbarFrame.width, height: toolbarFrame.height)
.background(Color.secondary)
}.opacity((keyboard.currentHeight == 0) ? 0 : 1)
.animation(.easeOut)
}
.padding(.bottom, keyboard.currentHeight)
.edgesIgnoringSafeArea(.bottom)
.animation(.easeOut)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment