Skip to content

Commit 896dc2c

Browse files
Saadnajmiclaude
andcommitted
fix: address PR feedback - remove effectiveProps, simplify compat layer
- Remove verbose comments after [macOS diff tags - Replace effectiveProps pattern with spread destructuring - Use legacyKeyOverrides with direct prop fallbacks in handlers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7e68079 commit 896dc2c

2 files changed

Lines changed: 39 additions & 51 deletions

File tree

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -392,22 +392,10 @@ function useTextInputStateSynchronization({
392392
*
393393
*/
394394
function InternalTextInput(props: TextInputProps): React.Node {
395-
// [macOS Legacy keyboard event compat — to remove, delete this block and its import
396-
const usingLegacyKeyboardProps = hasLegacyKeyProps(props);
397-
// $FlowFixMe[unclear-type]
398-
const effectiveProps: any = usingLegacyKeyboardProps ? ({...props}: any) : props;
399-
if (usingLegacyKeyboardProps) {
400-
stripLegacyKeyProps(effectiveProps);
401-
const legacy = processLegacyKeyProps(props);
402-
effectiveProps.keyDownEvents = legacy.keyDownEvents;
403-
effectiveProps.keyUpEvents = legacy.keyUpEvents;
404-
if (legacy.onKeyDown != null) {
405-
effectiveProps.onKeyDown = legacy.onKeyDown;
406-
}
407-
if (legacy.onKeyUp != null) {
408-
effectiveProps.onKeyUp = legacy.onKeyUp;
409-
}
410-
}
395+
// [macOS
396+
const legacyKeyOverrides = hasLegacyKeyProps(props)
397+
? processLegacyKeyProps(props)
398+
: null;
411399
// macOS]
412400
const {
413401
'aria-busy': ariaBusy,
@@ -423,7 +411,9 @@ function InternalTextInput(props: TextInputProps): React.Node {
423411
selectionHandleColor,
424412
cursorColor,
425413
...otherProps
426-
} = effectiveProps;
414+
// $FlowFixMe[unclear-type]
415+
} = ({...props, ...legacyKeyOverrides}: any); // [macOS]
416+
stripLegacyKeyProps(otherProps); // [macOS]
427417

428418
const inputRef = useRef<null | TextInputInstance>(null);
429419

@@ -604,10 +594,14 @@ function InternalTextInput(props: TextInputProps): React.Node {
604594
};
605595

606596
// [macOS
597+
const _keyDownEvents = legacyKeyOverrides?.keyDownEvents ?? props.keyDownEvents;
598+
const _keyUpEvents = legacyKeyOverrides?.keyUpEvents ?? props.keyUpEvents;
599+
const _origOnKeyDown = legacyKeyOverrides?.onKeyDown ?? props.onKeyDown;
600+
const _origOnKeyUp = legacyKeyOverrides?.onKeyUp ?? props.onKeyUp;
601+
607602
const _onKeyDown = (event: KeyEvent) => {
608-
const keyDownEvents = effectiveProps.keyDownEvents;
609-
if (keyDownEvents != null && !event.isPropagationStopped()) {
610-
const isHandled = keyDownEvents.some(
603+
if (_keyDownEvents != null && !event.isPropagationStopped()) {
604+
const isHandled = _keyDownEvents.some(
611605
({key, metaKey, ctrlKey, altKey, shiftKey}: HandledKeyEvent) => {
612606
return (
613607
event.nativeEvent.key === key &&
@@ -622,13 +616,12 @@ function InternalTextInput(props: TextInputProps): React.Node {
622616
event.stopPropagation();
623617
}
624618
}
625-
effectiveProps.onKeyDown?.(event);
619+
_origOnKeyDown?.(event);
626620
};
627621

628622
const _onKeyUp = (event: KeyEvent) => {
629-
const keyUpEvents = effectiveProps.keyUpEvents;
630-
if (keyUpEvents != null && !event.isPropagationStopped()) {
631-
const isHandled = keyUpEvents.some(
623+
if (_keyUpEvents != null && !event.isPropagationStopped()) {
624+
const isHandled = _keyUpEvents.some(
632625
({key, metaKey, ctrlKey, altKey, shiftKey}: HandledKeyEvent) => {
633626
return (
634627
event.nativeEvent.key === key &&
@@ -643,7 +636,7 @@ function InternalTextInput(props: TextInputProps): React.Node {
643636
event.stopPropagation();
644637
}
645638
}
646-
effectiveProps.onKeyUp?.(event);
639+
_origOnKeyUp?.(event);
647640
};
648641
// macOS]
649642

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

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,23 @@ export default component View(
3636
) {
3737
const hasTextAncestor = use(TextAncestorContext);
3838

39-
// [macOS Legacy keyboard event compat — to remove, delete this block and its import
40-
const usingLegacyKeyboardProps = hasLegacyKeyProps(props);
41-
// $FlowFixMe[unclear-type]
42-
const effectiveProps: any = usingLegacyKeyboardProps ? ({...props}: any) : props;
43-
if (usingLegacyKeyboardProps) {
44-
stripLegacyKeyProps(effectiveProps);
45-
const legacy = processLegacyKeyProps(props);
46-
effectiveProps.keyDownEvents = legacy.keyDownEvents;
47-
effectiveProps.keyUpEvents = legacy.keyUpEvents;
48-
if (legacy.onKeyDown != null) {
49-
effectiveProps.onKeyDown = legacy.onKeyDown;
50-
}
51-
if (legacy.onKeyUp != null) {
52-
effectiveProps.onKeyUp = legacy.onKeyUp;
53-
}
54-
}
39+
// [macOS
40+
const legacyKeyOverrides = hasLegacyKeyProps(props)
41+
? processLegacyKeyProps(props)
42+
: null;
5543
// macOS]
5644

5745
let actualView;
5846

5947
// [macOS
48+
const _keyDownEvents = legacyKeyOverrides?.keyDownEvents ?? props.keyDownEvents;
49+
const _keyUpEvents = legacyKeyOverrides?.keyUpEvents ?? props.keyUpEvents;
50+
const _origOnKeyDown = legacyKeyOverrides?.onKeyDown ?? props.onKeyDown;
51+
const _origOnKeyUp = legacyKeyOverrides?.onKeyUp ?? props.onKeyUp;
52+
6053
const _onKeyDown = (event: KeyEvent) => {
61-
const keyDownEvents = effectiveProps.keyDownEvents;
62-
if (keyDownEvents != null && !event.isPropagationStopped()) {
63-
const isHandled = keyDownEvents.some(
54+
if (_keyDownEvents != null && !event.isPropagationStopped()) {
55+
const isHandled = _keyDownEvents.some(
6456
({key, metaKey, ctrlKey, altKey, shiftKey}: HandledKeyEvent) => {
6557
return (
6658
event.nativeEvent.key === key &&
@@ -75,13 +67,12 @@ export default component View(
7567
event.stopPropagation();
7668
}
7769
}
78-
effectiveProps.onKeyDown?.(event);
70+
_origOnKeyDown?.(event);
7971
};
8072

8173
const _onKeyUp = (event: KeyEvent) => {
82-
const keyUpEvents = effectiveProps.keyUpEvents;
83-
if (keyUpEvents != null && !event.isPropagationStopped()) {
84-
const isHandled = keyUpEvents.some(
74+
if (_keyUpEvents != null && !event.isPropagationStopped()) {
75+
const isHandled = _keyUpEvents.some(
8576
({key, metaKey, ctrlKey, altKey, shiftKey}: HandledKeyEvent) => {
8677
return (
8778
event.nativeEvent.key === key &&
@@ -96,7 +87,7 @@ export default component View(
9687
event.stopPropagation();
9788
}
9889
}
99-
effectiveProps.onKeyUp?.(event);
90+
_origOnKeyUp?.(event);
10091
};
10192
// macOS]
10293

@@ -120,10 +111,12 @@ export default component View(
120111
id,
121112
tabIndex,
122113
...otherProps
123-
} = effectiveProps;
114+
// $FlowFixMe[unclear-type]
115+
} = ({...props, ...legacyKeyOverrides}: any); // [macOS]
124116

125117
// Since we destructured props, we can now treat it as mutable
126118
const processedProps = otherProps as {...ViewProps};
119+
stripLegacyKeyProps(processedProps); // [macOS]
127120

128121
const parsedAriaLabelledBy = ariaLabelledBy?.split(/\s*,\s*/g);
129122
if (parsedAriaLabelledBy !== undefined) {
@@ -219,7 +212,9 @@ export default component View(
219212
nativeID,
220213
tabIndex,
221214
...otherProps
222-
} = effectiveProps;
215+
// $FlowFixMe[unclear-type]
216+
} = ({...props, ...legacyKeyOverrides}: any); // [macOS]
217+
stripLegacyKeyProps(otherProps); // [macOS]
223218
const _accessibilityLabelledBy =
224219
ariaLabelledBy?.split(/\s*,\s*/g) ?? accessibilityLabelledBy;
225220

0 commit comments

Comments
 (0)