Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
52f025e
[fabric] Add draggedTypes prop to View
Feb 12, 2024
7a4f466
[fabric] Add drag and drop event emitters to View
Feb 12, 2024
1055d4c
[fabric] Add drag and drop support to View component
Feb 12, 2024
5aff5ca
no longer optional
Saadnajmi Oct 1, 2025
4ff4c7f
take fix from meta/pristine
Saadnajmi Oct 1, 2025
4ac7e98
Add missing header
Saadnajmi Oct 1, 2025
e1ec4de
Update PressableExample
Saadnajmi Oct 1, 2025
f8e51b4
undo event emitter
Saadnajmi Oct 1, 2025
ebc4aea
redo event emitter
Saadnajmi Oct 1, 2025
2851aac
Update HostPlatformViewProps.cpp
Saadnajmi Oct 1, 2025
9a6095c
Apply suggestions from code review
Saadnajmi Oct 2, 2025
42dc769
Add a new drag and drop example
Saadnajmi Oct 3, 2025
3f45e98
Move example to top
Saadnajmi Oct 3, 2025
a6452f8
sendDragEvent -> emitDragEvent
Saadnajmi Oct 3, 2025
e10f5ca
nil check strings
Saadnajmi Oct 3, 2025
0f79940
Use cgImage
Saadnajmi Oct 3, 2025
c3afaf0
update js example
Saadnajmi Oct 3, 2025
d8ab0f4
Update types
Saadnajmi Oct 4, 2025
174c387
update example
Saadnajmi Oct 4, 2025
0957cc8
prettier fix
Saadnajmi Oct 4, 2025
1f887b6
fixup types
Saadnajmi Oct 6, 2025
23c38b1
use UTTypes
Saadnajmi Oct 6, 2025
71e0222
Merge branch 'main' into drag-drop
Saadnajmi Oct 6, 2025
63b15c6
[fabric] Add keyboard event handling to TextInput component
Jan 30, 2024
64d756b
[fabric] Add drag and drop support to TextInput component
Feb 12, 2024
b3e83b1
[fabric] Add file paste event emitter to TextInput component
Feb 13, 2024
be8259c
[fabric] Add file paste support to TextInput component
Feb 13, 2024
35d1f10
build fixes
Saadnajmi Oct 3, 2025
f4df879
new keyboard events example
Saadnajmi Oct 6, 2025
a343a57
[fabric] TextInput should handle pasted types prop
shwanton Apr 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
BlurEvent,
// [macOS
FocusEvent,
DragEvent,
HandledKeyEvent,
KeyEvent,
GestureResponderEvent,
Expand Down Expand Up @@ -198,21 +199,21 @@ type PressableBaseProps = $ReadOnly<{
*
* @platform macos
*/
onDragEnter?: (event: MouseEvent) => void,
onDragEnter?: (event: DragEvent) => void,

/**
* Fired when a file is dragged out of the Pressable via the mouse.
*
* @platform macos
*/
onDragLeave?: (event: MouseEvent) => void,
onDragLeave?: (event: DragEvent) => void,

/**
* Fired when a file is dropped on the Pressable via the mouse.
*
* @platform macos
*/
onDrop?: (event: MouseEvent) => void,
onDrop?: (event: DragEvent) => void,

/**
* The types of dragged files that the Pressable will accept.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {
BlurEvent,
FocusEvent,
// [macOS]
MouseEvent,
MouseEvent, // [macOS]
DragEvent, // [macOS]
GestureResponderEvent,
LayoutChangeEvent,
} from '../../Types/CoreEventTypes';
Expand All @@ -36,9 +36,9 @@ export type TouchableWithoutFeedbackPropsIOS = {
tooltip?: ?string,
onMouseEnter?: (event: MouseEvent) => void,
onMouseLeave?: (event: MouseEvent) => void,
onDragEnter?: (event: MouseEvent) => void,
onDragLeave?: (event: MouseEvent) => void,
onDrop?: (event: MouseEvent) => void,
onDragEnter?: (event: DragEvent) => void,
onDragLeave?: (event: DragEvent) => void,
onDrop?: (event: DragEvent) => void,
draggedTypes?: ?DraggedTypesType,
// macOS]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

'use strict';

export type DraggedType = 'fileUrl';
export type DraggedType = 'fileUrl' | 'image' | 'string';

export type DraggedTypesType = DraggedType | $ReadOnlyArray<DraggedType>;

module.exports = {
DraggedTypes: ['fileUrl'],
DraggedTypes: ['fileUrl', 'image', 'string'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {GestureResponderHandlers} from '../../../types/public/ReactNativeRendere
import {StyleProp} from '../../StyleSheet/StyleSheet';
import {ViewStyle} from '../../StyleSheet/StyleSheetTypes';
import {
DragEvent,
HandledKeyEvent,
KeyEvent,
LayoutChangeEvent,
Expand Down Expand Up @@ -108,7 +109,7 @@ export interface ViewPropsAndroid {
tabIndex?: 0 | -1 | undefined;
}

export type DraggedType = 'fileUrl';
export type DraggedType = 'fileUrl' | 'image' | 'string';
export type DraggedTypesType = DraggedType | DraggedType[];

export interface ViewPropsMacOS {
Expand All @@ -118,9 +119,9 @@ export interface ViewPropsMacOS {
enableFocusRing?: boolean | undefined;
onMouseEnter?: ((event: MouseEvent) => void) | undefined;
onMouseLeave?: ((event: MouseEvent) => void) | undefined;
onDragEnter?: ((event: MouseEvent) => void) | undefined;
onDragLeave?: ((event: MouseEvent) => void) | undefined;
onDrop?: ((event: MouseEvent) => void) | undefined;
onDragEnter?: ((event: DragEvent) => void) | undefined;
onDragLeave?: ((event: DragEvent) => void) | undefined;
onDrop?: ((event: DragEvent) => void) | undefined;
onKeyDown?: ((event: KeyEvent) => void) | undefined;
onKeyUp?: ((event: KeyEvent) => void) | undefined;
keyDownEvents?: HandledKeyEvent[] | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
BlurEvent,
FocusEvent,
// [macOS]
DragEvent,
HandledKeyEvent,
KeyEvent,
LayoutChangeEvent,
Expand Down Expand Up @@ -410,21 +411,21 @@ type MacOSViewProps = $ReadOnly<{|
*
* @platform macos
*/
onDragEnter?: (event: MouseEvent) => void,
onDragEnter?: (event: DragEvent) => void,

/**
* Fired when a file is dragged out of the view via the mouse.
*
* @platform macos
*/
onDragLeave?: (event: MouseEvent) => void,
onDragLeave?: (event: DragEvent) => void,

/**
* Fired when an element is dropped on a valid drop target
*
* @platform macos
*/
onDrop?: (event: MouseEvent) => void,
onDrop?: (event: DragEvent) => void,

/**
* Specifies the Tooltip for the view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ NS_ASSUME_NONNULL_BEGIN
#if TARGET_OS_OSX // [macOS
// UITextInput method for OSX
- (CGSize)sizeThatFits:(CGSize)size;
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
#endif // macOS]

// This protocol disallows direct access to `text` property because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor;
@property (weak, nullable) id<RCTUITextFieldDelegate> delegate;
@property (nonatomic, assign) CGFloat pointScaleFactor;

- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
#endif // macOS]

@property (nonatomic, getter=isGhostTextChanging) BOOL ghostTextChanging; // [macOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ @implementation RCTUITextField {
#endif // [macOS]
#if TARGET_OS_OSX // [macOS
BOOL _isUpdatingPlaceholderText;
NSArray<NSPasteboardType> *_readablePasteboardTypes;
#endif // macOS]
}

Expand Down Expand Up @@ -705,5 +706,12 @@ - (void)keyUp:(NSEvent *)event {
}
}
#endif // macOS]

#if TARGET_OS_OSX // [macOS
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
{
_readablePasteboardTypes = readablePasteboardTypes;
}
#endif // macOS]

@end
22 changes: 22 additions & 0 deletions packages/react-native/Libraries/Types/CoreEventTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,26 @@ export interface NativeBlurEvent extends TargetedEvent {}
export interface FocusEvent extends NativeSyntheticEvent<NativeFocusEvent> {}

export interface BlueEvent extends NativeSyntheticEvent<NativeBlurEvent> {}

// Drag and Drop types
export interface DataTransferItem {
name: string;
kind: string;
type: string;
uri: string;
size?: number | undefined;
width?: number | undefined;
height?: number | undefined;
}

export interface DataTransfer {
files: ReadonlyArray<DataTransferItem>;
types: ReadonlyArray<string>;
}

export interface DragEvent extends MouseEvent {
nativeEvent: NativeMouseEvent & {
dataTransfer?: DataTransfer | undefined;
};
}
// macOS]
122 changes: 75 additions & 47 deletions packages/react-native/Libraries/Types/CoreEventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,10 @@ export interface NativePointerEvent extends NativeMouseEvent {
export type PointerEvent = NativeSyntheticEvent<NativePointerEvent>;

export type NativeTouchEvent = $ReadOnly<{
altKey?: ?boolean, // [macOS]
button?: ?number, // [macOS]
/**
* Array of all touch events that have changed since the last event
*/
changedTouches: $ReadOnlyArray<NativeTouchEvent>,
ctrlKey?: ?boolean, // [macOS]
/**
* 3D Touch reported force
* @platform ios
Expand All @@ -245,7 +242,7 @@ export type NativeTouchEvent = $ReadOnly<{
* The Y position of the touch, relative to the element
*/
locationY: number,
metaKey?: ?boolean, // [macOS]

/**
* The X position of the touch, relative to the screen
*/
Expand All @@ -254,7 +251,6 @@ export type NativeTouchEvent = $ReadOnly<{
* The Y position of the touch, relative to the screen
*/
pageY: number,
shiftKey?: ?boolean, // [macOS]
/**
* The node id of the element receiving the touch event
*/
Expand All @@ -267,6 +263,13 @@ export type NativeTouchEvent = $ReadOnly<{
* Array of all current touches on the screen
*/
touches: $ReadOnlyArray<NativeTouchEvent>,
// [macOS
ctrlKey?: ?boolean,
altKey?: ?boolean,
shiftKey?: ?boolean,
metaKey?: ?boolean,
button?: ?number,
// macOS]
}>;

export type GestureResponderEvent = ResponderSyntheticEvent<NativeTouchEvent>;
Expand All @@ -283,48 +286,6 @@ export type NativeScrollPoint = $ReadOnly<{
x: number,
}>;

// [macOS
export type KeyEvent = NativeSyntheticEvent<
$ReadOnly<{|
// Modifier keys
capsLockKey: boolean,
shiftKey: boolean,
ctrlKey: boolean,
altKey: boolean,
metaKey: boolean,
numericPadKey: boolean,
helpKey: boolean,
functionKey: boolean,
// Key options
ArrowLeft: boolean,
ArrowRight: boolean,
ArrowUp: boolean,
ArrowDown: boolean,
key: string,
|}>,
>;

/**
* Represents a key that could be passed to `KeyDownEvents` and `KeyUpEvents`.
*
* `key` is the actual key, such as "a", or one of the special values:
* "Tab", "Escape", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
* "Backspace", "Delete", "Home", "End", "PageUp", "PageDown".
*
* The rest are modifiers that when absent mean false.
*
* @platform macos
*/
export type HandledKeyEvent = $ReadOnly<{|
altKey?: ?boolean,
ctrlKey?: ?boolean,
metaKey?: ?boolean,
shiftKey?: ?boolean,
key: string,
|}>;

// macOS]

export type NativeScrollVelocity = $ReadOnly<{
y: number,
x: number,
Expand Down Expand Up @@ -370,3 +331,70 @@ export type MouseEvent = NativeSyntheticEvent<
timestamp: number,
}>,
>;

// [macOS
export type DataTransferItem = $ReadOnly<{
name: string,
kind: string,
type: string,
uri: string,
size?: number,
width?: number,
height?: number,
}>;

export type DataTransfer = $ReadOnly<{
files: $ReadOnlyArray<DataTransferItem>,
types: $ReadOnlyArray<string>,
}>;

export type DragEvent = NativeSyntheticEvent<
$ReadOnly<{
clientX: number,
clientY: number,
pageX: number,
pageY: number,
timestamp: number,
dataTransfer?: DataTransfer,
}>,
>;

export type KeyEvent = NativeSyntheticEvent<
$ReadOnly<{|
// Modifier keys
capsLockKey: boolean,
shiftKey: boolean,
ctrlKey: boolean,
altKey: boolean,
metaKey: boolean,
numericPadKey: boolean,
helpKey: boolean,
functionKey: boolean,
// Key options
ArrowLeft: boolean,
ArrowRight: boolean,
ArrowUp: boolean,
ArrowDown: boolean,
key: string,
|}>,
>;

/**
* Represents a key that could be passed to `KeyDownEvents` and `KeyUpEvents`.
*
* `key` is the actual key, such as "a", or one of the special values:
* "Tab", "Escape", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
* "Backspace", "Delete", "Home", "End", "PageUp", "PageDown".
*
* The rest are modifiers that when absent mean false.
*
* @platform macos
*/
export type HandledKeyEvent = $ReadOnly<{|
ctrlKey?: ?boolean,
altKey?: ?boolean,
shiftKey?: ?boolean,
metaKey?: ?boolean,
key: string,
|}>;
// macOS]
Loading