From 996da20e4ff5d7dc20a357361244691bdd3262c6 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 22 Jul 2025 17:35:55 -0700 Subject: [PATCH 1/2] fix: TextInputFocus state not in sync with View focus (#2553) ## Summary: This is fixed upstream with https://github.com/facebook/react-native/pull/52472/ . Let's commit (and backport) a smaller fix for now. ## Test Plan: Minimal repro of bug is this code below. Basically, you can't focus on "Pressable Child 2" twice by clicking on the container ``` {myRef.current.focus();}}> Pressable Container Pressable Child 1 Pressable Child 2 Pressable Child 3 ``` --- .../Libraries/Components/TextInput/TextInputState.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Components/TextInput/TextInputState.js b/packages/react-native/Libraries/Components/TextInput/TextInputState.js index 1fe8a152b57f5c..3e04582d6b9a0d 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInputState.js +++ b/packages/react-native/Libraries/Components/TextInput/TextInputState.js @@ -105,7 +105,11 @@ function focusTextInput(textField: ?ComponentRef) { if (textField != null) { const fieldCanBeFocused = - currentlyFocusedInputRef !== textField && + // [macOS currentlyFocusedInputRef does not account for the fact that any arbritrary view can + // recieve focus on desktop. https://github.com/facebook/react-native/pull/52472/ fixes this, + // disable the check for now + // currentlyFocusedInputRef !== textField && + // macOS] // $FlowFixMe - `currentProps` is missing in `NativeMethods` textField.currentProps?.editable !== false; From 6343a553eab314b6845c7d4da50e6aeb0b18fe28 Mon Sep 17 00:00:00 2001 From: Colin Heffernan Date: Tue, 22 Jul 2025 19:32:59 -0500 Subject: [PATCH 2/2] fix: Support Function Key Handling in macOS Views (#2554) ## Summary: Function keys on macOS currently get dispatched with the value from the underlying NS*FunctionKey code point. For instance, a `F12` event gets dispatched as `\uf70f` for [NS12FunctionKey](https://developer.apple.com/documentation/appkit/nsf12functionkey?language=objc). To clean this up, we should dispatch the same strings we use on other platforms (i.e. `'F12'` for the F12 key). ## Test Plan: I used a pressable component with a `onKeyDown` handler in `RNTester-macOS` to test keyboard events. With this change, the function keys come in as `F12`, `F11` etc... instead of the underlying NS*FunctionKey code points. --------- Co-authored-by: Colin Heffernan --- .../React/Views/RCTViewKeyboardEvent.m | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/react-native/React/Views/RCTViewKeyboardEvent.m b/packages/react-native/React/Views/RCTViewKeyboardEvent.m index 125586ee047b74..466939ce360886 100644 --- a/packages/react-native/React/Views/RCTViewKeyboardEvent.m +++ b/packages/react-native/React/Views/RCTViewKeyboardEvent.m @@ -63,6 +63,30 @@ + (NSString *)keyFromEvent:(NSEvent *)event return @"PageUp"; } else if (code == NSPageDownFunctionKey) { return @"PageDown"; + } else if (code == NSF1FunctionKey) { + return @"F1"; + } else if (code == NSF2FunctionKey) { + return @"F2"; + } else if (code == NSF3FunctionKey) { + return @"F3"; + } else if (code == NSF4FunctionKey) { + return @"F4"; + } else if (code == NSF5FunctionKey) { + return @"F5"; + } else if (code == NSF6FunctionKey) { + return @"F6"; + } else if (code == NSF7FunctionKey) { + return @"F7"; + } else if (code == NSF8FunctionKey) { + return @"F8"; + } else if (code == NSF9FunctionKey) { + return @"F9"; + } else if (code == NSF10FunctionKey) { + return @"F10"; + } else if (code == NSF11FunctionKey) { + return @"F11"; + } else if (code == NSF12FunctionKey) { + return @"F12"; } return key;