IQKeyboardManager
IQKeyboardManager copied to clipboard
SwiftUI Support
I wonder how we can use the IQKeyboardManager in SwiftUI.
Is there is a way to use it with toolbarPreviousNextAllowedClasses ?
Sorry, I current do not know how we can use library functions in SwiftUI. However all default functions works with SwiftUI projects. Please also let me know if you know something about it.
So far I got some things working, but the IQPreviousNext isn't one of them
@PedroCavaleiro Can you please share your experience with swiftUI and IQKeyboardManager?
@hackiftekhar So far good, haven’t found any bugs on the features that I use (dismiss when tapped outside the TextField, changed the name of the toolbar button Done button and forced the next/previous keys to show up) Only the previous/next isn’t working for me, neither on the toolbar or the keyboard (return/next/done) key The next/previous buttons, if forced, they appear if installed using podfile
@PedroCavaleiro can you share the way that you've done it please ?
Sorry for the delayed response @MaxenceMax but I was extremely sick and did not used my computer until now.
On the AppDelegate.swift
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "Terminar"
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
IQKeyboardManager.shared.previousNextDisplayMode = .alwaysShow
I did a little bit testing with SwiftUI, the next/previous arrows do not appear because the SwiftUI creates a different hierarchy of views than usual. I was trying to implement some kind of IQPreviousNextViewSwiftUI
which we can use as a container to enable previous/next buttons, but not able to fully support it.
are there going to be work to make next/previous arrow work for swiftUI? would love that.
It would be easier to make some workaround by peoples who already know how to do it with SwiftUI. Unfortunately I'm not one of them till now, haven't got chance to learn SwiftUI.
Hi all, I discovered that pressing the "Done" button in SwiftUi doesn't trigger the "on commit:" in the SwiftUi TextField. Any Idea how to change this behaviour? Especially, I am using the keyboardTye(.decimalPad) option where the IQKeyboardManager-Done button would come in super handy committing the keyboard and finishing the entry in the SwiftUI TextField as well. Pressing return on a the default keyboard works just fine. Thanks
In Xcode 12 there is no any AppDelegate and we now views will allow only struct, class,enum. If anyone has implemented IQKeyboard for swiftui then please share few tips.
You can still implement it, go to the file where the @main is located, in the example below it's called your_projectApp.swift
// MARK: Add from here
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
IQKeyboardManager.shared.enable = true
return true
}
}
// MARK: To Here
@main
struct your_projectApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate // add this line in the struct
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
You can still implement it, go to the file where the @main is located, in the example below it's called
your_projectApp.swift
// MARK: Add from here class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { IQKeyboardManager.shared.enable = true return true } } // MARK: To Here @main struct your_projectApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate // add this line in the struct var body: some Scene { WindowGroup { ContentView() } } }
It will display only Done button and Next, Previous is not working
You can still implement it, go to the file where the @main is located, in the example below it's called
your_projectApp.swift
// MARK: Add from here class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { IQKeyboardManager.shared.enable = true return true } } // MARK: To Here @main struct your_projectApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate // add this line in the struct var body: some Scene { WindowGroup { ContentView() } } }
It will display only Done button and Next, Previous is not working
That's a problem that I've yet to solve.
any update on " Next, Previous is not working"? I checked today and it's the same result.
I haven't learned the SwiftUI yet. So I need help from peoples who already learn the swift UI to write something same like IQPreviousNextView class implemented for the Swift/ObjC.
For me it will crash on search when i click on textfield.
I learned the SwiftUI now and I found that it's not easy to use this library directly in SwiftUI because SwiftUI has it's own mechanism to handle keyboard input and show the textField at correct position by moving it's UI. However we may have something for previous/next and done. But in those cases onCommit doesn't fire probably.
Due to these things, I think it's not a good idea at the moment to support it for SwiftUI as the general purpose use of the library is already handled by SwiftUI.
@PedroCavaleiro Can you please share your experience with swiftUI and IQKeyboardManager?
it is not showing tool bar in swiftui
Since I started targeting iOS 15 I no longer use IQKeyboardManager
I felt that the OS was doing its thing and you could add the toolbar items on SwiftUI. I no longer know how this lib is behaving.
But as @hackiftekhar said
I learned the SwiftUI now and I found that it's not easy to use this library directly in SwiftUI because SwiftUI has it's own mechanism to handle keyboard input and show the textField at correct position by moving it's UI. However we may have something for previous/next and done. But in those cases onCommit doesn't fire probably.
Due to these things, I think it's not a good idea at the moment to support it for SwiftUI as the general purpose use of the library is already handled by SwiftUI.
So this lib is really not suitable to use with SwiftUI specially in the latest versions of iOS