Skip to content

Commit c12aa75

Browse files
committed
feedback #2
1 parent 7123515 commit c12aa75

File tree

6 files changed

+25
-14
lines changed

6 files changed

+25
-14
lines changed

Libraries/Components/Pressable/Pressable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ type Props = $ReadOnly<{|
195195
passthroughAllKeyEvents?: ?boolean,
196196

197197
/**
198-
* Array of keys to receive key down events for. These events are always removed from the system event queue.
198+
* Array of keys to receive key down events for. These events have their default native behavior prevented.
199199
*
200200
* @platform macos
201201
*/
202202
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
203203

204204
/**
205-
* Array of keys to receive key up events for. These events are always removed from the system event queue.
205+
* Array of keys to receive key up events for. These events have their default native behavior prevented.
206206
*
207207
* @platform macos
208208
*/

Libraries/Components/View/ViewPropTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ export type KeyboardEventProps = $ReadOnly<{|
140140
passthroughAllKeyEvents?: ?boolean,
141141

142142
/**
143-
* Array of keys to receive key down events for. These events are always removed from the system event queue.
143+
* Array of keys to receive key down events for. These events have their default native behavior prevented.
144144
*
145145
* @platform macos
146146
*/
147147
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
148148

149149
/**
150-
* Array of keys to receive key up events for. These events are always removed from the system event queue.
150+
* Array of keys to receive key up events for. These events have their default native behavior prevented.
151151
*
152152
* @platform macos
153153
*/

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import <React/RCTTextSelection.h>
2222
#import <React/RCTUITextView.h> // [macOS]
2323
#import "../RCTTextUIKit.h" // [macOS]
24-
#import "RCTHandledKey.h" // [macOS]
24+
#import <React/RCTHandledKey.h> // [macOS]
2525

2626
@implementation RCTBaseTextInputView {
2727
__weak RCTBridge *_bridge;

React/Views/RCTHandledKey.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#if TARGET_OS_OSX // [macOS
8+
// [macOS]
9+
10+
#if TARGET_OS_OSX
911
#import <React/RCTConvert.h>
1012

13+
// This class is used for specifying key filtering e.g. for -[RCTView validKeysDown] and -[RCTView validKeysUp]
14+
// Also see RCTViewKeyboardEvent, which is a React representation of an actual NSEvent that is dispatched to JS.
1115
@interface RCTHandledKey : NSObject
1216

1317
+ (BOOL)event:(NSEvent *)event matchesFilter:(NSArray<RCTHandledKey *> *)filter;
@@ -17,10 +21,13 @@
1721
- (BOOL)matchesEvent:(NSEvent *)event;
1822

1923
@property (nonatomic, copy) NSString *key;
20-
@property (nonatomic, assign) NSNumber *altKey; // boolean; nil == don't care
21-
@property (nonatomic, assign) NSNumber *ctrlKey; // boolean; nil == don't care
22-
@property (nonatomic, assign) NSNumber *metaKey; // boolean; nil == don't care
23-
@property (nonatomic, assign) NSNumber *shiftKey; // boolean; nil == don't care
24+
25+
// For the following modifiers, nil means we don't care about the presence of the modifier when filtering the key
26+
// They are still expected to be only boolean when not nil.
27+
@property (nonatomic, assign) NSNumber *altKey;
28+
@property (nonatomic, assign) NSNumber *ctrlKey;
29+
@property (nonatomic, assign) NSNumber *metaKey;
30+
@property (nonatomic, assign) NSNumber *shiftKey;
2431

2532
@end
2633

@@ -30,4 +37,4 @@
3037

3138
@end
3239

33-
#endif // macOS]
40+
#endif

React/Views/RCTHandledKey.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
// [macOS]
9+
810
#import "objc/runtime.h"
911
#import <React/RCTAssert.h>
1012
#import <React/RCTUtils.h>
1113
#import <RCTConvert.h>
1214
#import <RCTHandledKey.h>
1315
#import <RCTViewKeyboardEvent.h>
1416

15-
#if TARGET_OS_OSX // [macOS
17+
#if TARGET_OS_OSX
1618

1719
@implementation RCTHandledKey
1820

@@ -101,10 +103,12 @@ @implementation RCTConvert (RCTHandledKey)
101103

102104
+ (RCTHandledKey *)RCTHandledKey:(id)json
103105
{
106+
// legacy way of specifying validKeysDown and validKeysUp -- here we ignore the modifiers when comparing to the NSEvent
104107
if ([json isKindOfClass:[NSString class]]) {
105108
return [[RCTHandledKey alloc] initWithKey:(NSString *)json];
106109
}
107110

111+
// modern way of specifying validKeys and validKeysUp -- here we assume missing modifiers to mean false\NO
108112
if ([json isKindOfClass:[NSDictionary class]]) {
109113
NSDictionary *dict = (NSDictionary *)json;
110114
NSString *key = dict[@"key"];
@@ -138,4 +142,4 @@ + (RCTHandledKey *)RCTHandledKey:(id)json
138142

139143
@end
140144

141-
#endif // macOS]
145+
#endif

React/Views/RCTView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event shouldBlock:(BOOL *)shoul
17231723
];
17241724
}
17251725

1726-
// If a view specifies a key, it will always be removed from the system event queue (i.e. "handled")
1726+
// If a view specifies a key, it will always be removed from the responder chain (i.e. "handled")
17271727
*shouldBlock = [RCTHandledKey event:event matchesFilter:validKeys];
17281728

17291729
// If an event isn't being removed from the queue, but was requested to "passthrough" by a view,

0 commit comments

Comments
 (0)