-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add onPaste to TextInput #804
base: main
Are you sure you want to change the base?
Conversation
On web, the analog of this event shape is Notably, the events expose With current proposal, the way we could try to maybe infer content from the underlying mutation, but this can be tricky. We also cannot rely on the global clipboard, since it is async, and could point to something different by the time we ask for its content in response to paste event. So, we really want a reference to the underlying data when the paste happens. Partially modeling something like |
proposals/0000-textinput-onpaste.md
Outdated
|
||
## Unresolved questions | ||
|
||
- onPaste event does not expose any clipboard data. How can we add such data? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickGerleman Can we handle this as a follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. The event without data would require accessing clipboard afterward, and since that happens asynchronously, the data may have changed or be incorrect. A concrete example of this, is if you paste a password, a password manager might immediately clear it from the clipboard.
I.e. the current approach without the data is impossible to make reliable, and would encourage users to add code which falls into the anti-pattern.
I don't know how much time @cipolleschi has dedicated to this change, but did want to share the context I had on this, and some of the baselines of what these events should look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data can be as follow:
{
target: viewTag,
items: [
{
type: "image/jpeg", // MIME type
data: "data:image/jpeg;base64,..." // data: plaintext for text/plain and base64 encoded data for the rest
}
],
}
items is an array that holds different items present in the clipboard, but for the current implementation only the first item is added.
Android implementation facebook/react-native@af06d9e
Screen.Recording.2024-07-24.at.3.22.50.AM-2.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding pasting files, using base64 string is not looking very performant (dealing with long strings can be slow). I'm looking into passing the URI instead, for Android we can directly use clipData.getItemAt(0).getUri()
(still investigating the same for iOS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On iOS the clipboard items do not expose any URI. When a file is pasted, we copy its data into a temporarily file and provide that file's URI instead. Proposal updated.
Proposal on adding
onPaste
prop toTextInput
component to detect paste event. View rendered proposal