I am making a chat app in SwiftUI. Here is the effect that I want to have: open any chat in Telegram or Whatsapp, tap on the input box. The content of the chat slides up when the keyboard slides up. So if you were looking at say the bottom message, you can still see it.
I am unable to get this effect in SwiftUI. Keyboard sliding up does not slide the content of the chat:
import SwiftUI
struct SlidingKeyboardTest: View {
@State var inputText = "Placeholder"
var body: some View {
VStack {
ScrollView {
LazyVStack {
ForEach(1...100, id: \.self) { id in
HStack {
Spacer()
Text("message \(id)")
Spacer()
}
}
}
}
TextEditor(text: $inputText)
.frame(height: 50)
}
.background(LinearGradient(gradient: Gradient(colors: [.white, .blue, .white]), startPoint: .top, endPoint: .bottom))
.onTapGesture { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) }
}
}
struct SlidingKeyboardTest_Previews: PreviewProvider {
static var previews: some View {
SlidingKeyboardTest()
}
}
Any ideas how to get this effect?