Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI Support #1606

Closed
MahranBayed opened this issue Sep 25, 2019 · 20 comments
Closed

SwiftUI Support #1606

MahranBayed opened this issue Sep 25, 2019 · 20 comments

Comments

@MahranBayed
Copy link

I wonder how we can use the IQKeyboardManager in SwiftUI.

Is there is a way to use it with toolbarPreviousNextAllowedClasses ?

@hackiftekhar
Copy link
Owner

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.

@PedroCavaleiro
Copy link

So far I got some things working, but the IQPreviousNext isn't one of them

@hackiftekhar
Copy link
Owner

@PedroCavaleiro Can you please share your experience with swiftUI and IQKeyboardManager?

@PedroCavaleiro
Copy link

PedroCavaleiro commented Dec 5, 2019

@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

@MaxenceMax
Copy link

@PedroCavaleiro can you share the way that you've done it please ?

@PedroCavaleiro
Copy link

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

@hackiftekhar
Copy link
Owner

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.

@TakaGoto
Copy link

TakaGoto commented Jun 1, 2020

are there going to be work to make next/previous arrow work for swiftUI? would love that.

@hackiftekhar
Copy link
Owner

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.

@Heye42
Copy link

Heye42 commented Aug 15, 2020

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

@dipak-onehop
Copy link

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.

@PedroCavaleiro
Copy link

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()
        }
    }
}

@dipak-onehop
Copy link

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

@PedroCavaleiro
Copy link

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.

@skywalkerlw
Copy link

any update on " Next, Previous is not working"? I checked today and it's the same result.

@hackiftekhar
Copy link
Owner

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.

@ParagDevac
Copy link

For me it will crash on search when i click on textfield.

@hackiftekhar
Copy link
Owner

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.

@abhishekquantic
Copy link

@PedroCavaleiro Can you please share your experience with swiftUI and IQKeyboardManager?

it is not showing tool bar in swiftui

@PedroCavaleiro
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants