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

Add MultilineTextInput paste support #1350

Merged
merged 1 commit into from
Sep 8, 2022

Conversation

christophpurrer
Copy link

@christophpurrer christophpurrer commented Aug 10, 2022

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

This adds an onPaste event for MultilineTextInput that is fired when a pasting into the input, and includes the same dataTransfer info as the onDrop callback which is discussed here #842
This also fixes a typo in the API name
This also adds logic to extract image size info from pasted images

Noteworthy:

  • onPaste exists atm only for macOS, but we have the corresponding change to also add it rnw if that is desired
  • Should we also add a property pasteTypes similar to drag&drag drag(ged)Types?

Changelog

[macOS] [Added] - Add MultilineTextInput paste support

Test Plan

Using this example with a paste handler. CMD+C, CMD+V

        <TextInput
          autoFocus={true}
          multiline={true}
          onPaste={e => console.log(e.nativeEvent.dataTransfer)}
          style={styles.default}
          accessibilityLabel="I am the accessibility label for text input"
        />
Screen.Recording.2022-08-10.at.4.05.26.PM.mov

Using that example w/o a paste handler. CMD+C, CMD+V and CMD+V again and again. And contextMenu paste

        <TextInput
          autoFocus={true}
          multiline={true}
          style={styles.default}
          accessibilityLabel="I am the accessibility label for text input"
        />
Screen.Recording.2022-08-10.at.4.06.00.PM.mov

@christophpurrer christophpurrer marked this pull request as ready for review August 10, 2022 23:18
@christophpurrer christophpurrer requested a review from a team as a code owner August 10, 2022 23:18
@christophpurrer christophpurrer changed the title [RFC] Add TextInput paste support [RFC] Add MultilineTextInput paste support Aug 10, 2022
Copy link
Collaborator

@Saadnajmi Saadnajmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another dumb question: how much of this do you think might just work on iOS / iPadOS? Mostly curious =)

@christophpurrer christophpurrer changed the title [RFC] Add MultilineTextInput paste support Add MultilineTextInput paste support Aug 24, 2022
@Saadnajmi
Copy link
Collaborator

Can you resolve the conflicts in this one too? :)

@christophpurrer
Copy link
Author

Can you resolve the conflicts in this one too? :)

Done ;-)

@Saadnajmi
Copy link
Collaborator

Saadnajmi commented Sep 8, 2022

Would it be possible to add an example test in RN-Tester? Perhaps extend the one for Drag/Drop?

I extended the Drag/Drop by just having onPaste add a log statement. I verified that onPaste is definitely called when I have an image in the clipboard... but not much more than the simple log statement. Would be nice if there was more info / it was more obvious this what you can do with the pasted info in the test.

Screen.Recording.2022-09-08.at.10.37.41.AM.mov

@christophpurrer
Copy link
Author

Would it be possible to add an example test in RN-Tester? Perhaps extend the one for Drag/Drop?

I extended the Drag/Drop by just having onPaste add a log statement. I verified that onPaste is definitely called when I have an image in the clipboard... but not much more than the simple log statement. Would be nice if there was more info / it was more obvious this what you can do with the pasted info in the test.

Screen.Recording.2022-09-08.at.10.37.41.AM.mov

I can add or extend an example. No big deal ;-)
When pasting an image you should get it's base64 representation.
So you can take 'it' and show it as an image

@christophpurrer
Copy link
Author

@Saadnajmi here is a video from the sample added.
Adding images via Finder or from the clipboard

Screen.Recording.2022-09-08.at.12.12.42.PM.mov

This adds an `onPaste` event for `MultilineTextInput` that is fired when a pasting into the input, and includes the same `dataTransfer` info as the `onDrop` callback which is discussed here microsoft#842
This also fixes a typo in the API name

```onPaste``` exists atm only for macOS, but we have the corresponding change to also add it rnw if that is desired
Should we also add a property ```pasteTypes``` similar to drag&drag drag(ged)Types?
Copy link
Collaborator

@Saadnajmi Saadnajmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with the new test page example and it worked great! Thanks for the PR :)

@Saadnajmi Saadnajmi enabled auto-merge (squash) September 8, 2022 20:37
@Saadnajmi Saadnajmi merged commit b0aff93 into microsoft:main Sep 8, 2022
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 8, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 8, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 9, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 12, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 13, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 21, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 21, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 21, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
christophpurrer added a commit to christophpurrer/react-native-macos that referenced this pull request Sep 21, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
Saadnajmi pushed a commit that referenced this pull request Sep 21, 2022
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to #1350
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Feb 13, 2023
This adds an `onPaste` event for `MultilineTextInput` that is fired when a pasting into the input, and includes the same `dataTransfer` info as the `onDrop` callback which is discussed here microsoft#842
This also fixes a typo in the API name

```onPaste``` exists atm only for macOS, but we have the corresponding change to also add it rnw if that is desired
Should we also add a property ```pasteTypes``` similar to drag&drag drag(ged)Types?

Co-authored-by: Scott Kyle <skyle@fb.com>
# Conflicts:
#	Libraries/Components/TextInput/TextInput.js
#	Libraries/Text/TextInput/Multiline/RCTUITextView.m
#	packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js

# Conflicts:
#	Libraries/Text/TextInput/Multiline/RCTUITextView.m
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Feb 13, 2023
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
# Conflicts:
#	Libraries/Components/TextInput/TextInput.js
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Feb 13, 2023
This adds an `onPaste` event for `MultilineTextInput` that is fired when a pasting into the input, and includes the same `dataTransfer` info as the `onDrop` callback which is discussed here microsoft#842
This also fixes a typo in the API name

```onPaste``` exists atm only for macOS, but we have the corresponding change to also add it rnw if that is desired
Should we also add a property ```pasteTypes``` similar to drag&drag drag(ged)Types?

Co-authored-by: Scott Kyle <skyle@fb.com>
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Feb 13, 2023
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Mar 10, 2023
This adds an `onPaste` event for `MultilineTextInput` that is fired when a pasting into the input, and includes the same `dataTransfer` info as the `onDrop` callback which is discussed here microsoft#842
This also fixes a typo in the API name

```onPaste``` exists atm only for macOS, but we have the corresponding change to also add it rnw if that is desired
Should we also add a property ```pasteTypes``` similar to drag&drag drag(ged)Types?

Co-authored-by: Scott Kyle <skyle@fb.com>
# Conflicts:
#	Libraries/Components/TextInput/TextInput.js
#	Libraries/Text/TextInput/Multiline/RCTUITextView.m
#	packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js

# Conflicts:
#	Libraries/Text/TextInput/Multiline/RCTUITextView.m
shwanton pushed a commit to shwanton/react-native-macos that referenced this pull request Mar 10, 2023
There are use cases in which we want to ignore the base class [NSTextView readablePasteboardTypes] return values, which mostly, include RTF and formatted URL types
We want to ignore them in favor of plain text (NSPasteboardTypeString).

This change allows to opt into a custom list of supported paste types.

This is a follow-up to microsoft#1350
# Conflicts:
#	Libraries/Components/TextInput/TextInput.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants