Closed MatteCarra closed 3 years ago
I have also tried including the list and input field in a scrollview with scrolling disabled.
The keyboard has the expect behaviour, but the list+input field jumps down and up.
Video: https://drive.google.com/file/d/185ykiPBEtKBXy7dncRAPnZN2KBDqSrtF/view?usp=sharing
The jump usually also happens when the keyboard pops up.
Note: scrollView.shouldIgnoreScrollingAdjustment = true
had no effect.
import SwiftUI
import IQKeyboardManagerSwift
import Introspect
import Combine
@main
struct UiTestsApp: App {
@State var message = ""
@State var TEST = [ "STRING1", "STRING2", "STRING3", "STRING4", "STRING5", "STRING6", "STRING7", "STRING8","STRING9", "STRING10", "STRING11", "STRING12", "STRING13", "STRING14", "STRING15", "STRING16", "STRING17", "STRING18" ]
init() {
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = false
IQKeyboardManager.shared.shouldShowToolbarPlaceholder = false
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
IQKeyboardManager.shared.previousNextDisplayMode = .alwaysHide
}
func sendMessage() {
TEST.append(message)
message = ""
}
var body: some Scene {
WindowGroup {
ScrollView([], showsIndicators: false) {
VStack {
List {
ForEach(TEST, id: \.self) { str in
Text(str)
}
}
HStack(spacing: 15) {
TextField("Message...", text: $message)
.padding(.all, 7)
.background(Color.tertiarySystemFill)
.cornerRadius(5)
Button(action: sendMessage) {
Image(systemName: "paperplane.fill")
.resizable()
.aspectRatio(1, contentMode: .fit)
.padding(.all, 3)
}
}
.frame(height: 24)
.padding(.horizontal, 8)
.padding(.top, 8)
}
}
.introspectScrollView {
$0.shouldIgnoreScrollingAdjustment = true
}
}
}
}
How to do fix the gap between keyboard and textfield?
I think that since Xcode 14.0 beta 3 swiftui automatically avoids the keyboard, and this change is conflicting with IQKeyboard. Removing IQKeyboard solved the issue
Lmao, I'm using IQKeyboard just to push the view up whenever clicked on the text field, though. However, I'm working on UIKit, and it takes time to code all those things since the project that I'm working on is not very crucial, and just a learning project. 🤣 Removing IQKeyboard just to solve that case isn't an ideal solution. xD But, thanks for your response anyway, brother.
ran into the same issue :/
If you are using x code 12 and swiftui you need to remove iqkeyboard
Describe the bug 1) Open a swiftui app with a view that has a ScrollView/List and and input field. 2) Click on the input field 3) The view will keep its size and it will be pushed up, with no way to scroll to elements that are not on the current screen.
To Reproduce
Expected behavior The view should be resized. This way the scrollview will take all the space remaining without expanding off-screen and the user can scroll to the elements that don't fit.
Screenshots
Versions
Xcode: 12.0 beta 3 Mac OS: 10.10.5 Simulator/Device: iOS 14 Simulator/Device Name: iPhone 11 Pro Max Library Version: 6.5.5
Additional context I have tested the same behaviour with the stable xcode.