Created
November 9, 2024 13:46
-
-
Save pd95/088dddaa0328113bb545eb396651beee to your computer and use it in GitHub Desktop.
Bottom view not moving while interactive keyboard dismissal is ongong
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
import SwiftUI | |
struct MessageInput: View { | |
@State private var text = "" | |
@FocusState private var isFocused: Bool | |
var body: some View { | |
HStack { | |
TextField("Enter your message…", text: $text) | |
.textFieldStyle(.roundedBorder) | |
.padding(.trailing) | |
.focused($isFocused) | |
} | |
.padding(.horizontal) | |
.padding(.vertical, 8) | |
} | |
} | |
struct ContentView: View { | |
var colors: [Color] = [.red, .brown, .green, .cyan, .blue, .purple] | |
var body: some View { | |
NavigationStack { | |
ScrollViewReader { scrollView in | |
VStack(spacing: 0) { | |
ScrollView { | |
VStack(spacing: 0) { | |
ForEach(colors.indices, id: \.self) { colorIndex in | |
Rectangle() | |
.fill(colors[colorIndex]) | |
.frame(height: 200) | |
.id(colorIndex) | |
} | |
} | |
} | |
.scrollDismissesKeyboard(.interactively) // allow dismissing the keyboard interactively | |
.navigationTitle("Chat") | |
.navigationBarTitleDisplayMode(.inline) | |
.onAppear() { | |
scrollView.scrollTo(colors.indices.last, anchor: .bottom) | |
} | |
MessageInput() | |
.background(Material.thin) | |
} | |
.background(.red) | |
} | |
} | |
} | |
} |
No, sorry. I've just tested it now again... it simply is not interactive enough to keep up with the keyboard dismiss gesture of the user.
According to WWDC23 video Keep up with the keyboard there is a way with UIKit using layout constraints... but they do not go into details for SwiftUI.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you find a solution?