Skip to content

Commit a3f5c10

Browse files
authored
chore: remove props validKeysDown, validKeysUp, and passThroughAllKeyEvents (#1615)
* Remove `validKeysDown`, `validKeysUp`, `passThroughAllKeyEvents`
1 parent c80cf78 commit a3f5c10

File tree

23 files changed

+106
-457
lines changed

23 files changed

+106
-457
lines changed

packages/react-native/Libraries/Components/Button.js

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212

1313
import type {TextStyleProp, ViewStyleProp} from '../StyleSheet/StyleSheet';
1414
import type {PressEvent} from '../Types/CoreEventTypes';
15-
import type {
16-
BlurEvent,
17-
FocusEvent,
18-
HandledKeyEvent,
19-
KeyEvent,
20-
} from '../Types/CoreEventTypes'; // [macOS]
15+
import type {BlurEvent, FocusEvent} from '../Types/CoreEventTypes'; // [macOS]
2116
import type {
2217
AccessibilityActionEvent,
2318
AccessibilityActionInfo,
@@ -171,56 +166,6 @@ type ButtonProps = $ReadOnly<{|
171166
*/
172167
onFocus?: ?(e: FocusEvent) => void,
173168

174-
/**
175-
* Handler to be called when a key down press is detected
176-
*/
177-
onKeyDown?: ?(e: KeyEvent) => void,
178-
179-
/**
180-
* Handler to be called when a key up press is detected
181-
*/
182-
onKeyUp?: ?(e: KeyEvent) => void,
183-
184-
/*
185-
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
186-
* Array of keys to receive key down events for
187-
* For arrow keys, add "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
188-
*/
189-
validKeysDown?: ?Array<string>,
190-
191-
/*
192-
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
193-
* Array of keys to receive key up events for
194-
* For arrow keys, add "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
195-
*/
196-
validKeysUp?: ?Array<string>,
197-
198-
/**
199-
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
200-
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
201-
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
202-
* are still removed from the event queue, but the others are not.
203-
*
204-
* @platform macos
205-
*/
206-
passthroughAllKeyEvents?: ?boolean,
207-
208-
/**
209-
* Array of keys to receive key down events for. These events have their default native behavior prevented.
210-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
211-
*
212-
* @platform macos
213-
*/
214-
keyDownEvents?: ?Array<HandledKeyEvent>,
215-
216-
/**
217-
* Array of keys to receive key up events for. These events have their default native behavior prevented.
218-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
219-
*
220-
* @platform macos
221-
*/
222-
keyUpEvents?: ?Array<HandledKeyEvent>,
223-
224169
/*
225170
* Specifies the Tooltip for the view
226171
*/
@@ -402,8 +347,6 @@ const Button: React.AbstractComponent<
402347
// [macOS
403348
onFocus,
404349
onBlur,
405-
onKeyDown,
406-
onKeyUp,
407350
tooltip,
408351
// macOS]
409352
} = props;

packages/react-native/Libraries/Components/Pressable/Pressable.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -191,36 +191,10 @@ type Props = $ReadOnly<{|
191191
*
192192
* @platform macos
193193
*/
194-
validKeysDown?: ?Array<string | HandledKeyEvent>,
195-
196-
/**
197-
* Array of keys to receive key up events for. These events have their default native behavior prevented.
198-
*
199-
* @platform macos
200-
*/
201-
validKeysUp?: ?Array<string | HandledKeyEvent>,
202-
203-
/**
204-
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
205-
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
206-
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
207-
* are still removed from the event queue, but the others are not.
208-
*
209-
* @platform macos
210-
*/
211-
passthroughAllKeyEvents?: ?boolean,
212-
213-
/**
214-
* Array of keys to receive key down events for. These events have their default native behavior prevented.
215-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
216-
*
217-
* @platform macos
218-
*/
219194
keyDownEvents?: ?Array<HandledKeyEvent>,
220195

221196
/**
222197
* Array of keys to receive key up events for. These events have their default native behavior prevented.
223-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
224198
*
225199
* @platform macos
226200
*/
@@ -377,7 +351,6 @@ function Pressable(
377351
onBlur,
378352
onKeyDown,
379353
onKeyUp,
380-
passthroughAllKeyEvents,
381354
keyDownEvents,
382355
keyUpEvents,
383356
acceptsFirstMouse,

packages/react-native/Libraries/Components/View/ReactNativeViewAttributes.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ const UIView = {
5151
onDrop: true,
5252
onKeyDown: true,
5353
onKeyUp: true,
54-
validKeysDown: true,
55-
validKeysUp: true,
56-
passthroughAllKeyEvents: true,
5754
keyDownEvents: true,
5855
keyUpEvents: true,
5956
draggedTypes: true,

packages/react-native/Libraries/Components/View/View.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ const View: React.AbstractComponent<
5454
nativeID,
5555
tabIndex,
5656
// [macOS
57-
passthroughAllKeyEvents,
58-
validKeysDown,
59-
validKeysUp,
6057
keyDownEvents,
6158
keyUpEvents,
6259
// macOS]
@@ -101,19 +98,6 @@ const View: React.AbstractComponent<
10198
};
10299
}
103100

104-
// [macOS
105-
let _passthroughAllKeyEvents = passthroughAllKeyEvents;
106-
let _validKeysDown = validKeysDown;
107-
let _validKeysUp = validKeysUp;
108-
if (keyDownEvents || keyUpEvents) {
109-
_passthroughAllKeyEvents = true;
110-
// $FlowFixMe[incompatible-type]
111-
_validKeysDown = keyDownEvents;
112-
// $FlowFixMe[incompatible-type]
113-
_validKeysUp = keyUpEvents;
114-
}
115-
// macOS]
116-
117101
const actualView = (
118102
<ViewNativeComponent
119103
{...otherProps}
@@ -132,11 +116,6 @@ const View: React.AbstractComponent<
132116
: importantForAccessibility
133117
}
134118
nativeID={id ?? nativeID}
135-
// [macOS
136-
passthroughAllKeyEvents={_passthroughAllKeyEvents}
137-
validKeysDown={_validKeysDown}
138-
validKeysUp={_validKeysUp}
139-
// macOS]
140119
ref={forwardedRef}
141120
/>
142121
);

packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,8 @@ export interface ViewPropsMacOS {
137137
onDrop?: ((event: MouseEvent) => void) | undefined;
138138
onKeyDown?: ((event: KeyEvent) => void) | undefined;
139139
onKeyUp?: ((event: KeyEvent) => void) | undefined;
140-
validKeysDown?: Array<HandledKeyEvent | string> | undefined;
141-
validKeysUp?: Array<HandledKeyEvent | string> | undefined;
142-
passthroughAllKeyEvents?: boolean | undefined;
143-
keyDownEvents?: Array<HandledKeyEvent> | undefined;
144-
keyUpEvents?: Array<HandledKeyEvent> | undefined;
140+
keyDownEvents?: HandledKeyEvent[] | undefined;
141+
keyUpEvents?: HandledKeyEvent[] | undefined;
145142
draggedTypes?: DraggedTypesType | undefined;
146143
}
147144

packages/react-native/Libraries/Components/View/ViewPropTypes.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,10 @@ export type KeyboardEventProps = $ReadOnly<{|
116116
*
117117
* @platform macos
118118
*/
119-
validKeysDown?: ?Array<string | HandledKeyEvent>,
120-
121-
/**
122-
* Array of keys to receive key up events for. These events have their default native behavior prevented.
123-
*
124-
* @platform macos
125-
*/
126-
validKeysUp?: ?Array<string | HandledKeyEvent>,
127-
128-
/**
129-
* @deprecated use `keyDownEvents` or `keyUpEvents` instead
130-
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
131-
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
132-
* are still removed from the event queue, but the others are not.
133-
*
134-
* @platform macos
135-
*/
136-
passthroughAllKeyEvents?: ?boolean,
137-
138-
/**
139-
* Array of keys to receive key down events for. These events have their default native behavior prevented.
140-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
141-
*
142-
* @platform macos
143-
*/
144119
keyDownEvents?: ?Array<HandledKeyEvent>,
145120

146121
/**
147122
* Array of keys to receive key up events for. These events have their default native behavior prevented.
148-
* Overrides the props `validKeysDown`, `validKeysUp` and `passthroughAllKeyEvents`
149123
*
150124
* @platform macos
151125
*/

packages/react-native/Libraries/NativeComponent/BaseViewConfig.macos.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ const validAttributesForNonEventProps = {
5353
draggedTypes: true,
5454
enableFocusRing: true,
5555
tooltip: true,
56-
validKeysDown: true,
57-
validKeysUp: true,
58-
passthroughAllKeyEvents: true,
5956
keyDownEvents: true,
6057
keyUpEvents: true,
6158
mouseDownCanMoveWindow: true,

packages/react-native/Libraries/Pressability/Pressability.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ export type PressabilityConfig = $ReadOnly<{|
101101
// [macOS
102102
/*
103103
* Called after a key down event is detected.
104+
*
105+
* @platform macos
104106
*/
105107
onKeyDown?: ?(event: KeyEvent) => void,
106108

107109
/*
108110
* Called after a key up event is detected.
111+
*
112+
* @platform macos
109113
*/
110114
onKeyUp?: ?(event: KeyEvent) => void,
111115
// macOS]

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4848
#if TARGET_OS_OSX // [macOS
4949
- (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
5050
- (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
51-
- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
51+
- (BOOL)hasKeyDownEventOrKeyUpEvent:(NSString *)key;
5252
- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
5353
- (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
5454
- (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doComman
228228
//escape
229229
} else if (commandSelector == @selector(cancelOperation:)) {
230230
[textInputDelegate textInputDidCancel];
231-
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
231+
if (![textInputDelegate hasKeyDownEventOrKeyUpEvent:@"Escape"]) {
232232
[[_backedTextInputView window] makeFirstResponder:nil];
233233
}
234234
commandHandled = YES;
@@ -457,7 +457,7 @@ - (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
457457
//escape
458458
} else if (commandSelector == @selector(cancelOperation:)) {
459459
[textInputDelegate textInputDidCancel];
460-
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
460+
if (![textInputDelegate hasKeyDownEventOrKeyUpEvent:@"Escape"]) {
461461
[[_backedTextInputView window] makeFirstResponder:nil];
462462
}
463463
commandHandled = YES;

0 commit comments

Comments
 (0)