SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.32k stars 746 forks source link

Missing copy/paste menu in UITextField/UIWebView #429

Closed canhth closed 3 years ago

canhth commented 3 years ago

Description

Screenshot

clipboard

References

https://stackoverflow.com/questions/6414540/missing-copy-paste-menu-in-uitextfield-uiwebview/7576544

Solution & PR

https://github.com/SwiftKickMobile/SwiftMessages/pull/430

Demo

wtmoose commented 3 years ago

Where is the text field?

canhth commented 3 years ago

Hi @wtmoose ,

I've updated the Description. Including demo, video, and solution. How to reproduce it (Please check out my demo fork):

- Add rootViewController programmatically (don't forget to call `window.makeKeyAndVisible`).
- Use another third party that also active another UIWindow. (_I'm using DoraemonKit for example _)
- Show SwiftMessage view with `dimMode != .none`.
- Now, there is no more clipboard options (copy/paste) for your selected text.

Please consider the PR that I made. That's just for enabling users can force disable becomeKeyWindow in SwiftMessages.Config.

Thanks

wtmoose commented 3 years ago

Thanks for clarifying. The change in the PR is fine, but it seems like more of a workaround than a solution. The case where the message’s window should become the key window, for example if the message has a text field, would still have the issue wouldn’t it?

wtmoose commented 3 years ago

Would it make sense to have SwiftMessages restore the previous key window on dismissal?

canhth commented 3 years ago

Yes, you're right. This is just a workaround. I've tried reactive my Appdelegate's window in eventListeners .didHide. But that can not fix the issue.

After spent more time debugging. I've found an issue in iOS 13, we set window?.windowScene = scene but when uninstall the window, I think we forgot to remove the windowScene reference.

The correct uninstall function should be:

func uninstall() {
        if #available(iOS 13, *) {
            window?.windowScene = nil
        }
        window?.isHidden = true
        window = nil
}

I prefer to have this fix and disable becomeKeyWindow as well. I'll update my PR, and if you agree with this, could you please help to release the new version ASAP?

I'm pretty sure this is the root cause of the missing clipboard issue. Cheers.

haitacnj commented 3 years ago

Your fix make keyWindow nil when call show popup second time

if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {    //  keyWindow nil 
   let viewController = rootViewController.sm_selectPresentationContextTopDown(config)
   return .viewController(Weak(value: viewController))
} else {
   throw SwiftMessagesError.noRootViewController
}
canhth commented 3 years ago

Hi @haitacnj,

Created the fix in this PR: https://github.com/SwiftKickMobile/SwiftMessages/pull/438 But if you want a workaround, just disable becomKeyActive in Configuration:

        var config = SwiftMessages.Config()
        config.presentationStyle = .center
        // Disable this loading toast window become KeyWindow,
        // to fix the issue clipboard (copy/paste) can not displayed.
        config.becomeKeyWindow = false

If you have a better idea of how to fix my problem without breaking anything, let's have further discussion.

wtmoose commented 3 years ago

I've lost track of the status on this one. Can this be closed now?

canhth commented 3 years ago

We can close this. I can not reproduce @haitacnj's issue with Xcode 12.