Skip to content

Commit 02d5480

Browse files
ColinHeffernanColin Heffernan
andauthored
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 <[email protected]>
1 parent 48e6077 commit 02d5480

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/react-native/React/Views/RCTViewKeyboardEvent.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ + (NSString *)keyFromEvent:(NSEvent *)event
6363
return @"PageUp";
6464
} else if (code == NSPageDownFunctionKey) {
6565
return @"PageDown";
66+
} else if (code == NSF1FunctionKey) {
67+
return @"F1";
68+
} else if (code == NSF2FunctionKey) {
69+
return @"F2";
70+
} else if (code == NSF3FunctionKey) {
71+
return @"F3";
72+
} else if (code == NSF4FunctionKey) {
73+
return @"F4";
74+
} else if (code == NSF5FunctionKey) {
75+
return @"F5";
76+
} else if (code == NSF6FunctionKey) {
77+
return @"F6";
78+
} else if (code == NSF7FunctionKey) {
79+
return @"F7";
80+
} else if (code == NSF8FunctionKey) {
81+
return @"F8";
82+
} else if (code == NSF9FunctionKey) {
83+
return @"F9";
84+
} else if (code == NSF10FunctionKey) {
85+
return @"F10";
86+
} else if (code == NSF11FunctionKey) {
87+
return @"F11";
88+
} else if (code == NSF12FunctionKey) {
89+
return @"F12";
6690
}
6791

6892
return key;

0 commit comments

Comments
 (0)