-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Problem:
When user type CMD+V, Flutter app shows paste warning, but native app does not show the warning. (related: #103163)
Why flutter apps trigger this warning?
The path is quite complex with multiple steps:
- User press CMD+V
- iOS calls
FlutterTextInputView's key press event handlers - The keyboard event is eventually relayed to FlutterKeyboardManager, which sends to the framework
- Framework handles the keyboard event and request access to clipboard from the engine
- FlutterPlatformPlugin programmatically access the pasteboard, triggering the paste warning
Why native apps are ok?
As explained in the design doc, iOS has access to private APIs, which contains the secret logic that unlocks the pasteboard content. That logic is probably invoked by the default keyboard handler (which we override).
Solution?
To find out where this logic is, I removed the custom handlers from both FlutterTextInputView and FlutterViewController. By doing so, iOS will just follows the responder chain and eventually use default handlers, which unlocks the pasteboard contents. Then I was able to successfully paste in content using keyboard, without triggering the paste warning.
So problem solved? Not quite!
Removing these custom handlers will probably break framework's KeyboardListener widget. I am not familiar with how keyboard works, so this will need more investigation to properly solve it (if it's solvable). I don't think it's high priority, as it only impact iPad hardware keyboard.