react-native-macos 0.71.19 → 0.71.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Libraries/Components/Pressable/Pressable.js +18 -6
- package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
- package/Libraries/Components/View/ViewPropTypes.js +41 -5
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/NativeComponent/BaseViewConfig.macos.js +1 -0
- package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +8 -0
- package/Libraries/Text/TextInput/RCTBaseTextInputView.m +3 -1
- package/React/Base/RCTConvert.h +4 -0
- package/React/Base/RCTConvert.m +4 -0
- package/React/Base/RCTVersion.m +1 -1
- package/React/Views/RCTHandledKey.h +40 -0
- package/React/Views/RCTHandledKey.m +145 -0
- package/React/Views/RCTView.h +8 -2
- package/React/Views/RCTView.m +47 -9
- package/React/Views/RCTViewKeyboardEvent.m +10 -9
- package/React/Views/RCTViewManager.m +3 -2
- package/React/Views/ScrollView/RCTScrollView.m +3 -3
- package/ReactAndroid/gradle.properties +1 -1
- package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
- package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
- package/package.json +1 -1
- package/template/package.json +1 -1
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
AccessibilityState,
|
|
27
27
|
AccessibilityValue,
|
|
28
28
|
} from '../View/ViewAccessibility';
|
|
29
|
+
import type {HandledKeyboardEvent} from '../View/ViewPropTypes'; // [macOS]
|
|
29
30
|
|
|
30
31
|
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
|
|
31
32
|
import usePressability from '../../Pressability/usePressability';
|
|
@@ -185,16 +186,27 @@ type Props = $ReadOnly<{|
|
|
|
185
186
|
onKeyUp?: ?(event: KeyEvent) => void,
|
|
186
187
|
|
|
187
188
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
189
|
+
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
|
|
190
|
+
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
|
|
191
|
+
* still have their native default behavior prevented, but the others do not.
|
|
192
|
+
*
|
|
193
|
+
* @platform macos
|
|
190
194
|
*/
|
|
191
|
-
|
|
195
|
+
passthroughAllKeyEvents?: ?boolean,
|
|
192
196
|
|
|
193
197
|
/**
|
|
194
|
-
* Array of keys to receive key
|
|
195
|
-
*
|
|
198
|
+
* Array of keys to receive key down events for. These events have their default native behavior prevented.
|
|
199
|
+
*
|
|
200
|
+
* @platform macos
|
|
201
|
+
*/
|
|
202
|
+
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Array of keys to receive key up events for. These events have their default native behavior prevented.
|
|
206
|
+
*
|
|
207
|
+
* @platform macos
|
|
196
208
|
*/
|
|
197
|
-
validKeysUp?: ?Array<string>,
|
|
209
|
+
validKeysUp?: ?Array<string | HandledKeyboardEvent>,
|
|
198
210
|
|
|
199
211
|
/**
|
|
200
212
|
* Specifies whether the view should receive the mouse down event when the
|
|
@@ -100,22 +100,58 @@ type DirectEventProps = $ReadOnly<{|
|
|
|
100
100
|
|}>;
|
|
101
101
|
|
|
102
102
|
// [macOS
|
|
103
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Represents a key that could be passed to `validKeysDown` and `validKeysUp`.
|
|
105
|
+
*
|
|
106
|
+
* `key` is the actual key, such as "a", or one of the special values:
|
|
107
|
+
* "Tab", "Escape", "Enter", "ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown",
|
|
108
|
+
* "Backspace", "Delete", "Home", "End", "PageUp", "PageDown".
|
|
109
|
+
*
|
|
110
|
+
* The rest are modifiers that when absent mean false.
|
|
111
|
+
*
|
|
112
|
+
* @platform macos
|
|
113
|
+
*/
|
|
114
|
+
export type HandledKeyboardEvent = $ReadOnly<{|
|
|
115
|
+
altKey?: ?boolean,
|
|
116
|
+
ctrlKey?: ?boolean,
|
|
117
|
+
metaKey?: ?boolean,
|
|
118
|
+
shiftKey?: ?boolean,
|
|
119
|
+
key: string,
|
|
120
|
+
|}>;
|
|
121
|
+
|
|
122
|
+
export type KeyboardEventProps = $ReadOnly<{|
|
|
123
|
+
/**
|
|
124
|
+
* Called after a key down event is detected.
|
|
125
|
+
*/
|
|
104
126
|
onKeyDown?: ?(event: KeyEvent) => void,
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Called after a key up event is detected.
|
|
130
|
+
*/
|
|
105
131
|
onKeyUp?: ?(event: KeyEvent) => void,
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* When `true`, allows `onKeyDown` and `onKeyUp` to receive events not specified in
|
|
135
|
+
* `validKeysDown` and `validKeysUp`, respectively. Events matching `validKeysDown` and `validKeysUp`
|
|
136
|
+
* are still removed from the event queue, but the others are not.
|
|
137
|
+
*
|
|
138
|
+
* @platform macos
|
|
139
|
+
*/
|
|
140
|
+
passthroughAllKeyEvents?: ?boolean,
|
|
141
|
+
|
|
106
142
|
/**
|
|
107
|
-
* Array of keys to receive key down events for
|
|
143
|
+
* Array of keys to receive key down events for. These events have their default native behavior prevented.
|
|
108
144
|
*
|
|
109
145
|
* @platform macos
|
|
110
146
|
*/
|
|
111
|
-
validKeysDown?: ?Array<string>,
|
|
147
|
+
validKeysDown?: ?Array<string | HandledKeyboardEvent>,
|
|
112
148
|
|
|
113
149
|
/**
|
|
114
|
-
* Array of keys to receive key up events for
|
|
150
|
+
* Array of keys to receive key up events for. These events have their default native behavior prevented.
|
|
115
151
|
*
|
|
116
152
|
* @platform macos
|
|
117
153
|
*/
|
|
118
|
-
validKeysUp?: ?Array<string>,
|
|
154
|
+
validKeysUp?: ?Array<string | HandledKeyboardEvent>,
|
|
119
155
|
|}>;
|
|
120
156
|
// macOS]
|
|
121
157
|
|
|
@@ -550,6 +550,14 @@ static RCTUIColor *defaultPlaceholderColor() // [macOS]
|
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
552
|
#else // [macOS
|
|
553
|
+
- (BOOL)performKeyEquivalent:(NSEvent *)event {
|
|
554
|
+
if (!self.hasMarkedText && ![self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
|
|
555
|
+
return YES;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return [super performKeyEquivalent:event];
|
|
559
|
+
}
|
|
560
|
+
|
|
553
561
|
- (void)keyDown:(NSEvent *)event {
|
|
554
562
|
// If has marked text, handle by native and return
|
|
555
563
|
// Do this check before textInputShouldHandleKeyEvent as that one attempts to send the event to JS
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#import <React/RCTTextSelection.h>
|
|
22
22
|
#import <React/RCTUITextView.h> // [macOS]
|
|
23
23
|
#import "../RCTTextUIKit.h" // [macOS]
|
|
24
|
+
#import <React/RCTHandledKey.h> // [macOS]
|
|
24
25
|
|
|
25
26
|
@implementation RCTBaseTextInputView {
|
|
26
27
|
__weak RCTBridge *_bridge;
|
|
@@ -662,7 +663,8 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)decoder)
|
|
|
662
663
|
}
|
|
663
664
|
|
|
664
665
|
- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key {
|
|
665
|
-
return [
|
|
666
|
+
return [RCTHandledKey key:key matchesFilter:self.validKeysDown]
|
|
667
|
+
|| [RCTHandledKey key:key matchesFilter:self.validKeysUp];
|
|
666
668
|
}
|
|
667
669
|
|
|
668
670
|
- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo
|
package/React/Base/RCTConvert.h
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
#import <WebKit/WebKit.h>
|
|
21
21
|
#endif
|
|
22
22
|
|
|
23
|
+
@class RCTHandledKey; // [macOS]
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* This class provides a collection of conversion functions for mapping
|
|
25
27
|
* JSON objects to native types and classes. These are useful when writing
|
|
@@ -147,6 +149,8 @@ typedef BOOL css_backface_visibility_t;
|
|
|
147
149
|
|
|
148
150
|
#if TARGET_OS_OSX // [macOS
|
|
149
151
|
+ (NSString *)accessibilityRoleFromTraits:(id)json;
|
|
152
|
+
|
|
153
|
+
+ (NSArray<RCTHandledKey *> *)RCTHandledKeyArray:(id)json;
|
|
150
154
|
#endif // macOS]
|
|
151
155
|
@end
|
|
152
156
|
|
package/React/Base/RCTConvert.m
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#import <CoreText/CoreText.h>
|
|
13
13
|
|
|
14
14
|
#import "RCTDefines.h"
|
|
15
|
+
#import "RCTHandledKey.h" // [macOS]
|
|
15
16
|
#import "RCTImageSource.h"
|
|
16
17
|
#import "RCTParserUtils.h"
|
|
17
18
|
#import "RCTUtils.h"
|
|
@@ -1500,6 +1501,9 @@ RCT_ENUM_CONVERTER(
|
|
|
1500
1501
|
}
|
|
1501
1502
|
return NSAccessibilityUnknownRole;
|
|
1502
1503
|
}
|
|
1504
|
+
|
|
1505
|
+
RCT_JSON_ARRAY_CONVERTER(RCTHandledKey);
|
|
1506
|
+
|
|
1503
1507
|
#endif // macOS]
|
|
1504
1508
|
|
|
1505
1509
|
@end
|
package/React/Base/RCTVersion.m
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// [macOS]
|
|
9
|
+
|
|
10
|
+
#if TARGET_OS_OSX
|
|
11
|
+
#import <React/RCTConvert.h>
|
|
12
|
+
|
|
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.
|
|
15
|
+
@interface RCTHandledKey : NSObject
|
|
16
|
+
|
|
17
|
+
+ (BOOL)event:(NSEvent *)event matchesFilter:(NSArray<RCTHandledKey *> *)filter;
|
|
18
|
+
+ (BOOL)key:(NSString *)key matchesFilter:(NSArray<RCTHandledKey *> *)filter;
|
|
19
|
+
|
|
20
|
+
- (instancetype)initWithKey:(NSString *)key;
|
|
21
|
+
- (BOOL)matchesEvent:(NSEvent *)event;
|
|
22
|
+
|
|
23
|
+
@property (nonatomic, copy) NSString *key;
|
|
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;
|
|
31
|
+
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
@interface RCTConvert (RCTHandledKey)
|
|
35
|
+
|
|
36
|
+
+ (RCTHandledKey *)RCTHandledKey:(id)json;
|
|
37
|
+
|
|
38
|
+
@end
|
|
39
|
+
|
|
40
|
+
#endif
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// [macOS]
|
|
9
|
+
|
|
10
|
+
#import "objc/runtime.h"
|
|
11
|
+
#import <React/RCTAssert.h>
|
|
12
|
+
#import <React/RCTUtils.h>
|
|
13
|
+
#import <RCTConvert.h>
|
|
14
|
+
#import <RCTHandledKey.h>
|
|
15
|
+
#import <RCTViewKeyboardEvent.h>
|
|
16
|
+
|
|
17
|
+
#if TARGET_OS_OSX
|
|
18
|
+
|
|
19
|
+
@implementation RCTHandledKey
|
|
20
|
+
|
|
21
|
+
+ (NSArray<NSString *> *)validModifiers {
|
|
22
|
+
// keep in sync with actual properties and RCTViewKeyboardEvent
|
|
23
|
+
return @[@"altKey", @"ctrlKey", @"metaKey", @"shiftKey"];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
+ (BOOL)event:(NSEvent *)event matchesFilter:(NSArray<RCTHandledKey *> *)filter {
|
|
27
|
+
for (RCTHandledKey *key in filter) {
|
|
28
|
+
if ([key matchesEvent:event]) {
|
|
29
|
+
return YES;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return NO;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
+ (BOOL)key:(NSString *)key matchesFilter:(NSArray<RCTHandledKey *> *)filter {
|
|
37
|
+
for (RCTHandledKey *aKey in filter) {
|
|
38
|
+
if ([[aKey key] isEqualToString:key]) {
|
|
39
|
+
return YES;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return NO;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (instancetype)initWithKey:(NSString *)key {
|
|
47
|
+
if ((self = [super init])) {
|
|
48
|
+
self.key = key;
|
|
49
|
+
}
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (BOOL)matchesEvent:(NSEvent *)event
|
|
54
|
+
{
|
|
55
|
+
NSEventType type = [event type];
|
|
56
|
+
if (type != NSEventTypeKeyDown && type != NSEventTypeKeyUp) {
|
|
57
|
+
RCTFatal(RCTErrorWithMessage([NSString stringWithFormat:@"Wrong event type (%d) sent to -[RCTHandledKey matchesEvent:]", (int)type]));
|
|
58
|
+
return NO;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
NSDictionary *body = [RCTViewKeyboardEvent bodyFromEvent:event];
|
|
62
|
+
NSString *key = body[@"key"];
|
|
63
|
+
if (key == nil) {
|
|
64
|
+
RCTFatal(RCTErrorWithMessage(@"Event body has missing value for 'key'"));
|
|
65
|
+
return NO;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (![key isEqualToString:self.key]) {
|
|
69
|
+
return NO;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
NSArray<NSString *> *modifiers = [RCTHandledKey validModifiers];
|
|
73
|
+
for (NSString *modifier in modifiers) {
|
|
74
|
+
NSNumber *myValue = [self valueForKey:modifier];
|
|
75
|
+
|
|
76
|
+
if (myValue == nil) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
NSNumber *eventValue = (NSNumber *)body[modifier];
|
|
81
|
+
if (eventValue == nil) {
|
|
82
|
+
RCTFatal(RCTErrorWithMessage([NSString stringWithFormat:@"Event body has missing value for '%@'", modifier]));
|
|
83
|
+
return NO;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (![eventValue isKindOfClass:[NSNumber class]]) {
|
|
87
|
+
RCTFatal(RCTErrorWithMessage([NSString stringWithFormat:@"Event body has unexpected value of class '%@' for '%@'",
|
|
88
|
+
NSStringFromClass(object_getClass(eventValue)), modifier]));
|
|
89
|
+
return NO;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (![myValue isEqualToNumber:body[modifier]]) {
|
|
93
|
+
return NO;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return YES; // keys matched; all present modifiers matched
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@end
|
|
101
|
+
|
|
102
|
+
@implementation RCTConvert (RCTHandledKey)
|
|
103
|
+
|
|
104
|
+
+ (RCTHandledKey *)RCTHandledKey:(id)json
|
|
105
|
+
{
|
|
106
|
+
// legacy way of specifying validKeysDown and validKeysUp -- here we ignore the modifiers when comparing to the NSEvent
|
|
107
|
+
if ([json isKindOfClass:[NSString class]]) {
|
|
108
|
+
return [[RCTHandledKey alloc] initWithKey:(NSString *)json];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// modern way of specifying validKeys and validKeysUp -- here we assume missing modifiers to mean false\NO
|
|
112
|
+
if ([json isKindOfClass:[NSDictionary class]]) {
|
|
113
|
+
NSDictionary *dict = (NSDictionary *)json;
|
|
114
|
+
NSString *key = dict[@"key"];
|
|
115
|
+
if (key == nil) {
|
|
116
|
+
RCTLogConvertError(dict, @"a RCTHandledKey -- must include \"key\"");
|
|
117
|
+
return nil;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
RCTHandledKey *handledKey = [[RCTHandledKey alloc] initWithKey:key];
|
|
121
|
+
NSArray<NSString *> *modifiers = RCTHandledKey.validModifiers;
|
|
122
|
+
for (NSString *key in modifiers) {
|
|
123
|
+
id value = dict[key];
|
|
124
|
+
if (value == nil) {
|
|
125
|
+
value = @NO; // assume NO -- instead of nil i.e. "don't care" unlike the string case above.
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (![value isKindOfClass:[NSNumber class]]) {
|
|
129
|
+
RCTLogConvertError(value, @"a boolean");
|
|
130
|
+
return nil;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
[handledKey setValue:@([(NSNumber *)value boolValue]) forKey:key];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return handledKey;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
RCTLogConvertError(json, @"a RCTHandledKey -- allowed types are string and object");
|
|
140
|
+
return nil;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@end
|
|
144
|
+
|
|
145
|
+
#endif
|
package/React/Views/RCTView.h
CHANGED
|
@@ -23,6 +23,8 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
|
|
|
23
23
|
|
|
24
24
|
@protocol RCTAutoInsetsProtocol;
|
|
25
25
|
|
|
26
|
+
@class RCTHandledKey; // [macOS]
|
|
27
|
+
|
|
26
28
|
@interface RCTView : RCTUIView // [macOS]
|
|
27
29
|
|
|
28
30
|
// [macOS
|
|
@@ -157,10 +159,14 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
|
|
|
157
159
|
@property (nonatomic, copy) RCTDirectEventBlock onDrop;
|
|
158
160
|
|
|
159
161
|
// Keyboarding events
|
|
162
|
+
// NOTE does not properly work with single line text inputs (most key downs). This is because those are
|
|
163
|
+
// presumably handled by the window's field editor. To make it work, we'd need to look into providing
|
|
164
|
+
// a custom field editor for NSTextField controls.
|
|
165
|
+
@property (nonatomic, assign) BOOL passthroughAllKeyEvents;
|
|
160
166
|
@property (nonatomic, copy) RCTDirectEventBlock onKeyDown;
|
|
161
167
|
@property (nonatomic, copy) RCTDirectEventBlock onKeyUp;
|
|
162
|
-
@property (nonatomic, copy) NSArray<
|
|
163
|
-
@property (nonatomic, copy) NSArray<
|
|
168
|
+
@property (nonatomic, copy) NSArray<RCTHandledKey*> *validKeysDown;
|
|
169
|
+
@property (nonatomic, copy) NSArray<RCTHandledKey*> *validKeysUp;
|
|
164
170
|
|
|
165
171
|
// Shadow Properties
|
|
166
172
|
@property (nonatomic, strong) NSColor *shadowColor;
|
package/React/Views/RCTView.m
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
// [macOS
|
|
9
|
+
#import "objc/runtime.h"
|
|
10
|
+
#import "RCTHandledKey.h"
|
|
11
|
+
// macOS]
|
|
8
12
|
#import "RCTView.h"
|
|
9
13
|
|
|
10
14
|
#import <QuartzCore/QuartzCore.h>
|
|
@@ -1681,19 +1685,52 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
|
|
|
1681
1685
|
|
|
1682
1686
|
#pragma mark - Keyboard Events
|
|
1683
1687
|
|
|
1684
|
-
|
|
1688
|
+
// This dictionary is attached to the NSEvent being handled so we can ensure we only dispatch it
|
|
1689
|
+
// once per RCTView\nativeTag. The reason we need to track this state is that certain React native
|
|
1690
|
+
// views such as RCTUITextView inherit from views (such as NSTextView) which may or may not
|
|
1691
|
+
// decide to bubble the event to the next responder, and we don't want to dispatch the same
|
|
1692
|
+
// event more than once (e.g. first from RCTUITextView, and then from it's parent RCTView).
|
|
1693
|
+
NSMutableDictionary<NSNumber *, NSNumber *> *GetEventDispatchStateDictionary(NSEvent *event) {
|
|
1694
|
+
static const char *key = "RCTEventDispatchStateDictionary";
|
|
1695
|
+
NSMutableDictionary<NSNumber *, NSNumber *> *dict = objc_getAssociatedObject(event, key);
|
|
1696
|
+
if (dict == nil) {
|
|
1697
|
+
dict = [NSMutableDictionary new];
|
|
1698
|
+
objc_setAssociatedObject(event, key, dict, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
1699
|
+
}
|
|
1700
|
+
return dict;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
- (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event shouldBlock:(BOOL *)shouldBlock {
|
|
1685
1704
|
BOOL keyDown = event.type == NSEventTypeKeyDown;
|
|
1686
|
-
NSArray<
|
|
1687
|
-
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
|
|
1705
|
+
NSArray<RCTHandledKey *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
|
|
1688
1706
|
|
|
1689
|
-
// If the view is focusable and the component didn't explicity set the validKeysDown or
|
|
1707
|
+
// If the view is focusable and the component didn't explicity set the validKeysDown or validKeysUp,
|
|
1690
1708
|
// allow enter/return and spacebar key events to mimic the behavior of native controls.
|
|
1691
1709
|
if (self.focusable && validKeys == nil) {
|
|
1692
|
-
validKeys = @[
|
|
1710
|
+
validKeys = @[
|
|
1711
|
+
[[RCTHandledKey alloc] initWithKey:@"Enter"],
|
|
1712
|
+
[[RCTHandledKey alloc] initWithKey:@" "]
|
|
1713
|
+
];
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
// If a view specifies a key, it will always be removed from the responder chain (i.e. "handled")
|
|
1717
|
+
*shouldBlock = [RCTHandledKey event:event matchesFilter:validKeys];
|
|
1718
|
+
|
|
1719
|
+
// If an event isn't being removed from the queue, but was requested to "passthrough" by a view,
|
|
1720
|
+
// we want to be sure we dispatch it only once for that view. See note for GetEventDispatchStateDictionary.
|
|
1721
|
+
if ([self passthroughAllKeyEvents] && !*shouldBlock) {
|
|
1722
|
+
NSNumber *tag = [self reactTag];
|
|
1723
|
+
NSMutableDictionary<NSNumber *, NSNumber *> *dict = GetEventDispatchStateDictionary(event);
|
|
1724
|
+
|
|
1725
|
+
if ([dict[tag] boolValue]) {
|
|
1726
|
+
return nil;
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
dict[tag] = @YES;
|
|
1693
1730
|
}
|
|
1694
1731
|
|
|
1695
|
-
//
|
|
1696
|
-
if (![
|
|
1732
|
+
// Don't pass events we don't care about
|
|
1733
|
+
if (![self passthroughAllKeyEvents] && !*shouldBlock) {
|
|
1697
1734
|
return nil;
|
|
1698
1735
|
}
|
|
1699
1736
|
|
|
@@ -1702,10 +1739,11 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
|
|
|
1702
1739
|
|
|
1703
1740
|
- (BOOL)handleKeyboardEvent:(NSEvent *)event {
|
|
1704
1741
|
if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
|
|
1705
|
-
|
|
1742
|
+
BOOL shouldBlock = YES;
|
|
1743
|
+
RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event shouldBlock:&shouldBlock];
|
|
1706
1744
|
if (keyboardEvent) {
|
|
1707
1745
|
[_eventDispatcher sendEvent:keyboardEvent];
|
|
1708
|
-
return
|
|
1746
|
+
return shouldBlock;
|
|
1709
1747
|
}
|
|
1710
1748
|
}
|
|
1711
1749
|
return NO;
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
NSString *key = [self keyFromEvent:event];
|
|
19
19
|
NSEventModifierFlags modifierFlags = event.modifierFlags;
|
|
20
20
|
|
|
21
|
+
// when making changes here, also consider what should happen to RCTHandledKey. [macOS]
|
|
21
22
|
return @{
|
|
22
23
|
@"key" : key,
|
|
23
24
|
@"capsLockKey" : (modifierFlags & NSEventModifierFlagCapsLock) ? @YES : @NO,
|
|
@@ -54,15 +55,15 @@
|
|
|
54
55
|
return @"Backspace";
|
|
55
56
|
} else if (code == NSDeleteFunctionKey) {
|
|
56
57
|
return @"Delete";
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
} else if (code == NSHomeFunctionKey) {
|
|
59
|
+
return @"Home";
|
|
60
|
+
} else if (code == NSEndFunctionKey) {
|
|
61
|
+
return @"End";
|
|
62
|
+
} else if (code == NSPageUpFunctionKey) {
|
|
63
|
+
return @"PageUp";
|
|
64
|
+
} else if (code == NSPageDownFunctionKey) {
|
|
65
|
+
return @"PageDown";
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
return key;
|
|
68
69
|
}
|
|
@@ -511,10 +511,11 @@ RCT_EXPORT_VIEW_PROPERTY(onMouseLeave, RCTDirectEventBlock)
|
|
|
511
511
|
RCT_EXPORT_VIEW_PROPERTY(onDragEnter, RCTDirectEventBlock)
|
|
512
512
|
RCT_EXPORT_VIEW_PROPERTY(onDragLeave, RCTDirectEventBlock)
|
|
513
513
|
RCT_EXPORT_VIEW_PROPERTY(onDrop, RCTDirectEventBlock)
|
|
514
|
+
RCT_EXPORT_VIEW_PROPERTY(passthroughAllKeyEvents, BOOL)
|
|
514
515
|
RCT_EXPORT_VIEW_PROPERTY(onKeyDown, RCTDirectEventBlock) // macOS keyboard events
|
|
515
516
|
RCT_EXPORT_VIEW_PROPERTY(onKeyUp, RCTDirectEventBlock) // macOS keyboard events
|
|
516
|
-
RCT_EXPORT_VIEW_PROPERTY(validKeysDown, NSArray<
|
|
517
|
-
RCT_EXPORT_VIEW_PROPERTY(validKeysUp, NSArray<
|
|
517
|
+
RCT_EXPORT_VIEW_PROPERTY(validKeysDown, NSArray<RCTHandledKey *>)
|
|
518
|
+
RCT_EXPORT_VIEW_PROPERTY(validKeysUp, NSArray<RCTHandledKey *>)
|
|
518
519
|
|
|
519
520
|
#endif // macOS]
|
|
520
521
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#import <React/RCTUIKit.h> // [macOS]
|
|
11
11
|
|
|
12
12
|
#import "RCTConvert.h"
|
|
13
|
+
#import "RCTHandledKey.h" // [macOS]
|
|
13
14
|
#import "RCTLog.h"
|
|
14
15
|
#import "RCTScrollEvent.h"
|
|
15
16
|
#import "RCTUIManager.h"
|
|
@@ -1269,11 +1270,10 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
|
|
|
1269
1270
|
#if TARGET_OS_OSX
|
|
1270
1271
|
- (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
|
|
1271
1272
|
BOOL keyDown = event.type == NSEventTypeKeyDown;
|
|
1272
|
-
NSArray<
|
|
1273
|
-
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
|
|
1273
|
+
NSArray<RCTHandledKey *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
|
|
1274
1274
|
|
|
1275
1275
|
// Only post events for keys we care about
|
|
1276
|
-
if (![
|
|
1276
|
+
if (![RCTHandledKey event:event matchesFilter:validKeys]) {
|
|
1277
1277
|
return nil;
|
|
1278
1278
|
}
|
|
1279
1279
|
|
package/package.json
CHANGED