Add prop to filter drag and drop pasting on Android (#49446)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49446

On Android, by default, every EditText accepts `DragEvent` and will automatically focus themselves to accept these data. In some rare cases, it might not be desirable to allow data from arbitrary drag and drop events to be pasted into a text input.

This change adds a new prop `acceptDragAndDropTypes`  to do exactly that: reject drag and drop events by telling the system to ignore certain types of drag data and, by proxy, disabling behavior that automatically focuses the text input.

The prop accepts a subset of MIME types supported by Android as documented [here](https://developer.android.com/reference/android/content/ClipDescription#MIMETYPE_TEXT_HTML).

It's important to note that this is an experimental prop, as is evident by the `experimental_` prefix on the JS side. Its signature could change before the prop has fully matured, use at your own risk

Changelog: [Android][Added] - Add new prop for filtering drag and drop targeting to text inputs

Reviewed By: javache

Differential Revision: D69674225

fbshipit-source-id: 4dbbdd81bb0f394b6206da5a377c75ea71671626
This commit is contained in:
Peter Abbondanzo
2025-04-23 13:13:17 -07:00
committed by Facebook GitHub Bot
parent 3b17cdb643
commit d10dd7130c
8 changed files with 70 additions and 0 deletions
@@ -448,6 +448,27 @@ const examples: Array<RNTesterModuleExample> = [
return <ToggleDefaultPaddingExample />;
},
},
{
title: 'Drag and drop',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
experimental_acceptDragAndDropTypes={[]}
placeholder="Does not accept drag drops"
/>
<ExampleTextInput
experimental_acceptDragAndDropTypes={['text/plain']}
placeholder="Only accepts plaintext drag drops"
/>
<ExampleTextInput
experimental_acceptDragAndDropTypes={null}
placeholder="Accepts all drag drops"
/>
</View>
);
},
},
];
module.exports = ({