Skip to content

Commit

Permalink
Remove validKeysDown, validKeysUp, passThroughAllKeyEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Aug 22, 2024
1 parent 0854351 commit 21ab8f8
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 470 deletions.
59 changes: 1 addition & 58 deletions packages/react-native/Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@

import type {TextStyleProp, ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {PressEvent} from '../Types/CoreEventTypes';
import type {
BlurEvent,
FocusEvent,
HandledKeyEvent,
KeyEvent,
} from '../Types/CoreEventTypes'; // [macOS]
import type {BlurEvent, FocusEvent} from '../Types/CoreEventTypes'; // [macOS]
import type {
AccessibilityActionEvent,
AccessibilityActionInfo,
Expand Down Expand Up @@ -171,56 +166,6 @@ type ButtonProps = $ReadOnly<{|
*/
onFocus?: ?(e: FocusEvent) => void,

/**
* Handler to be called when a key down press is detected
*/
onKeyDown?: ?(e: KeyEvent) => void,

/**
* Handler to be called when a key up press is detected
*/
onKeyUp?: ?(e: KeyEvent) => void,

/*
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
* Array of keys to receive key down events for
* For arrow keys, add "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
*/
validKeysDown?: ?Array<string>,

/*
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
* Array of keys to receive key up events for
* For arrow keys, add "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
*/
validKeysUp?: ?Array<string>,

/**
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
* are still removed from the event queue, but the others are not.
*
* @platform macos
*/
passthroughAllKeyEvents?: ?boolean,

/**
* Array of keys to receive key down events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
keyDownEvents?: ?Array<HandledKeyEvent>,

/**
* Array of keys to receive key up events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
keyUpEvents?: ?Array<HandledKeyEvent>,

/*
* Specifies the Tooltip for the view
*/
Expand Down Expand Up @@ -396,8 +341,6 @@ const Button: React.AbstractComponent<ButtonProps> = (props: ButtonProps) => {
// [macOS
onFocus,
onBlur,
onKeyDown,
onKeyUp,
tooltip,
// macOS]
} = props;
Expand Down
27 changes: 0 additions & 27 deletions packages/react-native/Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,10 @@ type Props = $ReadOnly<{|
*
* @platform macos
*/
validKeysDown?: ?Array<string | HandledKeyEvent>,

/**
* Array of keys to receive key up events for. These events have their default native behavior prevented.
*
* @platform macos
*/
validKeysUp?: ?Array<string | HandledKeyEvent>,

/**
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
* are still removed from the event queue, but the others are not.
*
* @platform macos
*/
passthroughAllKeyEvents?: ?boolean,

/**
* Array of keys to receive key down events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
keyDownEvents?: ?Array<HandledKeyEvent>,

/**
* Array of keys to receive key up events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
Expand Down Expand Up @@ -374,7 +348,6 @@ function Pressable(props: Props, forwardedRef): React.Node {
onBlur,
onKeyDown,
onKeyUp,
passthroughAllKeyEvents,
keyDownEvents,
keyUpEvents,
acceptsFirstMouse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {EdgeInsetsOrSizeProp} from '../../StyleSheet/EdgeInsetsPropType';
import type {
BlurEvent,
FocusEvent,
KeyEvent,
LayoutEvent,
MouseEvent,
PressEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const UIView = {
onDrop: true,
onKeyDown: true,
onKeyUp: true,
validKeysDown: true,
validKeysUp: true,
passthroughAllKeyEvents: true,
keyDownEvents: true,
keyUpEvents: true,
draggedTypes: true,
Expand Down
25 changes: 0 additions & 25 deletions packages/react-native/Libraries/Components/View/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ const View: React.AbstractComponent<
nativeID,
pointerEvents,
tabIndex,
// [macOS
passthroughAllKeyEvents,
validKeysDown,
validKeysUp,
keyDownEvents,
keyUpEvents,
// macOS]
...otherProps
}: ViewProps,
forwardedRef,
Expand Down Expand Up @@ -109,19 +102,6 @@ const View: React.AbstractComponent<
// $FlowFixMe[sketchy-null-mixed]
const newPointerEvents = style?.pointerEvents || pointerEvents;

// [macOS
let _passthroughAllKeyEvents = passthroughAllKeyEvents;
let _validKeysDown = validKeysDown;
let _validKeysUp = validKeysUp;
if (keyDownEvents || keyUpEvents) {
_passthroughAllKeyEvents = true;
// $FlowFixMe[incompatible-type]
_validKeysDown = keyDownEvents;
// $FlowFixMe[incompatible-type]
_validKeysUp = keyUpEvents;
}
// macOS]

const actualView = (
<ViewNativeComponent
{...otherProps}
Expand All @@ -143,11 +123,6 @@ const View: React.AbstractComponent<
style={style}
// $FlowFixMe[incompatible-type]
pointerEvents={newPointerEvents}
// [macOS
passthroughAllKeyEvents={_passthroughAllKeyEvents}
validKeysDown={_validKeysDown}
validKeysUp={_validKeysUp}
// macOS]
ref={forwardedRef}
/>
);
Expand Down
15 changes: 10 additions & 5 deletions packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ export interface ViewPropsAndroid {
export type DraggedType = 'fileUrl';
export type DraggedTypesType = DraggedType | DraggedType[];

export type HandledKeyEvent = {
altKey?: boolean | undefined;
ctrlKey?: boolean | undefined;
metaKey?: boolean | undefined;
shiftKey?: boolean | undefined;
key: string;
};

export interface ViewPropsMacOS {
acceptsFirstMouse?: boolean | undefined;
allowsVibrancy?: boolean | undefined;
Expand All @@ -179,11 +187,8 @@ export interface ViewPropsMacOS {
onDrop?: ((event: MouseEvent) => void) | undefined;
onKeyDown?: ((event: KeyEvent) => void) | undefined;
onKeyUp?: ((event: KeyEvent) => void) | undefined;
validKeysDown?: Array<HandledKeyEvent | string> | undefined;
validKeysUp?: Array<HandledKeyEvent | string> | undefined;
passthroughAllKeyEvents?: boolean | undefined;
keyDownEvents?: Array<HandledKeyEvent> | undefined;
keyUpEvents?: Array<HandledKeyEvent> | undefined;
keyDownEvents?: HandledKeyEvent[] | undefined;
keyUpEvents?: HandledKeyEvent[] | undefined;
draggedTypes?: DraggedTypesType | undefined;
}

Expand Down
26 changes: 0 additions & 26 deletions packages/react-native/Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,36 +116,10 @@ export type KeyboardEventProps = $ReadOnly<{|
*
* @platform macos
*/
validKeysDown?: ?Array<string | HandledKeyEvent>,

/**
* Array of keys to receive key up events for. These events have their default native behavior prevented.
*
* @platform macos
*/
validKeysUp?: ?Array<string | HandledKeyEvent>,

/**
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
* are still removed from the event queue, but the others are not.
*
* @platform macos
*/
passthroughAllKeyEvents?: ?boolean,

/**
* Array of keys to receive key down events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
keyDownEvents?: ?Array<HandledKeyEvent>,

/**
* Array of keys to receive key up events for. These events have their default native behavior prevented.
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
*
* @platform macos
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ const validAttributesForNonEventProps = {
draggedTypes: true,
enableFocusRing: true,
tooltip: true,
validKeysDown: true,
validKeysUp: true,
passthroughAllKeyEvents: true,
keyDownEvents: true,
keyUpEvents: true,
mouseDownCanMoveWindow: true,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,15 @@ export type PressabilityConfig = $ReadOnly<{|
// [macOS
/*
* Called after a key down event is detected.
*
* @platform macos
*/
onKeyDown?: ?(event: KeyEvent) => void,

/*
* Called after a key up event is detected.
*
* @platform macos
*/
onKeyUp?: ?(event: KeyEvent) => void,
// macOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
#if TARGET_OS_OSX // [macOS
- (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
- (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
- (BOOL)hasKeyDownEventOrKeyUpEvent:(NSString *)key;
- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
- (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
- (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doComman
//escape
} else if (commandSelector == @selector(cancelOperation:)) {
[textInputDelegate textInputDidCancel];
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
if (![textInputDelegate hasKeyDownEventOrKeyUpEvent:@"Escape"]) {
[[_backedTextInputView window] makeFirstResponder:nil];
}
commandHandled = YES;
Expand Down Expand Up @@ -450,7 +450,7 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
//escape
} else if (commandSelector == @selector(cancelOperation:)) {
[textInputDelegate textInputDidCancel];
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
if (![textInputDelegate hasKeyDownEventOrKeyUpEvent:@"Escape"]) {
[[_backedTextInputView window] makeFirstResponder:nil];
}
commandHandled = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ - (BOOL)textInputShouldHandleDeleteForward:(__unused id)sender {
return YES;
}

- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key {
return [RCTHandledKey key:key matchesFilter:self.validKeysDown]
|| [RCTHandledKey key:key matchesFilter:self.validKeysUp];
- (BOOL)hasKeyDownEventOrKeyUpEvent:(NSString *)key {
return [RCTHandledKey key:key matchesFilter:self.keyDownEvents]
|| [RCTHandledKey key:key matchesFilter:self.keyUpEvents];
}

- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1706,13 +1706,6 @@ exports[`public API should not change unintentionally Libraries/Components/Butto
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
onBlur?: ?(e: BlurEvent) => void,
onFocus?: ?(e: FocusEvent) => void,
onKeyDown?: ?(e: KeyEvent) => void,
onKeyUp?: ?(e: KeyEvent) => void,
validKeysDown?: ?Array<string>,
validKeysUp?: ?Array<string>,
passthroughAllKeyEvents?: ?boolean,
keyDownEvents?: ?Array<HandledKeyboardEvent>,
keyUpEvents?: ?Array<HandledKeyboardEvent>,
tooltip?: string,
accessible?: ?boolean,
accessibilityActions?: ?$ReadOnlyArray<AccessibilityActionInfo>,
Expand Down Expand Up @@ -1904,11 +1897,8 @@ type Props = $ReadOnly<{|
onBlur?: ?(event: BlurEvent) => void,
onKeyDown?: ?(event: KeyEvent) => void,
onKeyUp?: ?(event: KeyEvent) => void,
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
validKeysUp?: ?Array<string | HandledKeyboardEvent>,
passthroughAllKeyEvents?: ?boolean,
keyDownEvents?: ?Array<HandledKeyboardEvent>,
keyUpEvents?: ?Array<HandledKeyboardEvent>,
keyDownEvents?: ?Array<HandledKeyEvent>,
keyUpEvents?: ?Array<HandledKeyEvent>,
acceptsFirstMouse?: ?boolean,
mouseDownCanMoveWindow?: ?boolean,
enableFocusRing?: ?boolean,
Expand Down Expand Up @@ -3639,9 +3629,6 @@ exports[`public API should not change unintentionally Libraries/Components/View/
onDrop: true,
onKeyDown: true,
onKeyUp: true,
validKeysDown: true,
validKeysUp: true,
passthroughAllKeyEvents: true,
keyDownEvents: true,
keyUpEvents: true,
draggedTypes: true,
Expand Down Expand Up @@ -3828,21 +3815,11 @@ type DirectEventProps = $ReadOnly<{|
onMagicTap?: ?() => mixed,
onAccessibilityEscape?: ?() => mixed,
|}>;
export type HandledKeyboardEvent = $ReadOnly<{|
altKey?: ?boolean,
ctrlKey?: ?boolean,
metaKey?: ?boolean,
shiftKey?: ?boolean,
key: string,
|}>;
export type KeyboardEventProps = $ReadOnly<{|
onKeyDown?: ?(event: KeyEvent) => void,
onKeyUp?: ?(event: KeyEvent) => void,
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
validKeysUp?: ?Array<string | HandledKeyboardEvent>,
passthroughAllKeyEvents?: ?boolean,
keyDownEvents?: ?Array<HandledKeyboardEvent>,
keyUpEvents?: ?Array<HandledKeyboardEvent>,
keyDownEvents?: ?Array<HandledKeyEvent>,
keyUpEvents?: ?Array<HandledKeyEvent>,
|}>;
type MouseEventProps = $ReadOnly<{|
onMouseEnter?: ?(event: MouseEvent) => void,
Expand Down Expand Up @@ -8539,6 +8516,13 @@ export type KeyEvent = SyntheticEvent<
key: string,
|}>,
>;
export type HandledKeyEvent = $ReadOnly<{|
altKey?: ?boolean,
ctrlKey?: ?boolean,
metaKey?: ?boolean,
shiftKey?: ?boolean,
key: string,
|}>;
export type MouseEvent = SyntheticEvent<
$ReadOnly<{|
clientX: number,
Expand Down
Loading

0 comments on commit 21ab8f8

Please sign in to comment.