react-native-macos 0.0.0-b9fb2dd1a → 0.0.0-bb8a035db
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/ScrollView/ScrollView.js +11 -45
- package/Libraries/Components/TextInput/TextInput.js +72 -1
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +1 -0
- package/Libraries/Components/View/ReactNativeViewViewConfig.js +1 -0
- package/Libraries/Components/View/ReactNativeViewViewConfigMacOS.js +3 -3
- package/Libraries/Components/View/ViewPropTypes.js +10 -6
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/LinkingIOS/RCTLinkingManager.h +1 -0
- package/Libraries/LinkingIOS/macos/RCTLinkingManager.mm +12 -5
- package/Libraries/Lists/FlatList.js +25 -1
- package/Libraries/Lists/VirtualizedList.js +106 -113
- package/Libraries/Lists/VirtualizedSectionList.js +9 -5
- package/Libraries/StyleSheet/StyleSheetTypes.js +25 -0
- package/Libraries/Text/RCTTextAttributes.m +5 -5
- package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.h +3 -0
- package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.m +6 -1
- package/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputViewManager.m +11 -0
- package/Libraries/Text/TextInput/Multiline/RCTUITextView.h +1 -0
- package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +69 -2
- package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +7 -1
- package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
- package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
- package/Libraries/Text/TextInput/RCTBaseTextInputView.h +4 -1
- package/Libraries/Text/TextInput/RCTBaseTextInputView.m +97 -2
- package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +6 -0
- package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +40 -0
- package/Libraries/Types/CoreEventTypes.js +0 -1
- package/React/Base/RCTConvert.m +9 -5
- package/React/Base/RCTTouchHandler.m +4 -0
- package/React/Base/RCTUtils.m +6 -3
- package/React/Base/RCTVersion.m +1 -1
- package/React/Base/macOS/RCTUIKit.m +7 -0
- package/React/CoreModules/RCTPerfMonitor.mm +1 -1
- package/React/Modules/RCTUIManager.m +2 -1
- package/React/Views/RCTActivityIndicatorView.m +2 -1
- package/React/Views/RCTCursor.h +39 -0
- package/React/Views/RCTCursor.m +105 -0
- package/React/Views/RCTView.h +12 -0
- package/React/Views/RCTView.m +110 -42
- package/React/Views/RCTViewKeyboardEvent.m +9 -1
- package/React/Views/RCTViewManager.m +17 -12
- package/React/Views/ScrollView/RCTScrollContentView.h +4 -0
- package/React/Views/ScrollView/RCTScrollContentView.m +18 -0
- package/React/Views/ScrollView/RCTScrollContentViewManager.m +2 -0
- package/React/Views/ScrollView/RCTScrollView.h +2 -1
- package/React/Views/ScrollView/RCTScrollView.m +69 -62
- package/React/Views/ScrollView/RCTScrollViewManager.m +1 -1
- package/React/Views/UIView+React.h +2 -0
- package/React/Views/UIView+React.m +22 -13
- 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/scripts/generate-artifacts.js +21 -17
- package/scripts/react_native_pods.rb +0 -3
- package/template/Gemfile.lock +5 -5
- package/template/package.json +1 -1
- package/third-party-podspecs/boost-for-react-native.podspec +0 -20
|
@@ -12,7 +12,7 @@ const Platform = require('../Utilities/Platform'); // TODO(macOS GH#774)
|
|
|
12
12
|
import invariant from 'invariant';
|
|
13
13
|
import type {ViewToken} from './ViewabilityHelper';
|
|
14
14
|
import type {SelectedRowIndexPathType} from './VirtualizedList'; // TODO(macOS GH#774)
|
|
15
|
-
import type {
|
|
15
|
+
import type {KeyEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
|
|
16
16
|
import {keyExtractor as defaultKeyExtractor} from './VirtualizeUtils';
|
|
17
17
|
import {View, VirtualizedList} from 'react-native';
|
|
18
18
|
import * as React from 'react';
|
|
@@ -311,8 +311,12 @@ class VirtualizedSectionList<
|
|
|
311
311
|
}
|
|
312
312
|
};
|
|
313
313
|
|
|
314
|
-
_handleKeyDown = (e:
|
|
314
|
+
_handleKeyDown = (e: KeyEvent) => {
|
|
315
315
|
if (Platform.OS === 'macos') {
|
|
316
|
+
if (e.defaultPrevented) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
316
320
|
const event = e.nativeEvent;
|
|
317
321
|
const key = event.key;
|
|
318
322
|
let prevIndexPath = this.state.selectedRowIndexPath;
|
|
@@ -320,7 +324,7 @@ class VirtualizedSectionList<
|
|
|
320
324
|
const sectionIndex = this.state.selectedRowIndexPath.sectionIndex;
|
|
321
325
|
const rowIndex = this.state.selectedRowIndexPath.rowIndex;
|
|
322
326
|
|
|
323
|
-
if (key === '
|
|
327
|
+
if (key === 'ArrowDown') {
|
|
324
328
|
nextIndexPath = this._selectRowBelowIndexPath(prevIndexPath);
|
|
325
329
|
this._ensureItemAtIndexPathIsVisible(nextIndexPath);
|
|
326
330
|
|
|
@@ -332,7 +336,7 @@ class VirtualizedSectionList<
|
|
|
332
336
|
item: item,
|
|
333
337
|
});
|
|
334
338
|
}
|
|
335
|
-
} else if (key === '
|
|
339
|
+
} else if (key === 'ArrowUp') {
|
|
336
340
|
nextIndexPath = this._selectRowAboveIndexPath(prevIndexPath);
|
|
337
341
|
this._ensureItemAtIndexPathIsVisible(nextIndexPath);
|
|
338
342
|
|
|
@@ -344,7 +348,7 @@ class VirtualizedSectionList<
|
|
|
344
348
|
item: item,
|
|
345
349
|
});
|
|
346
350
|
}
|
|
347
|
-
} else if (key === '
|
|
351
|
+
} else if (key === 'Enter') {
|
|
348
352
|
if (this.props.onSelectionEntered) {
|
|
349
353
|
const item = this.props.sections[sectionIndex].data[rowIndex];
|
|
350
354
|
this.props.onSelectionEntered(item);
|
|
@@ -16,6 +16,29 @@ import type {NativeColorValue} from './PlatformColorValueTypes';
|
|
|
16
16
|
|
|
17
17
|
export type ____ColorValue_Internal = null | string | NativeColorValue;
|
|
18
18
|
|
|
19
|
+
export type CursorValue = ?(
|
|
20
|
+
| 'alias'
|
|
21
|
+
| 'auto'
|
|
22
|
+
| 'col-resize'
|
|
23
|
+
| 'context-menu'
|
|
24
|
+
| 'copy'
|
|
25
|
+
| 'crosshair'
|
|
26
|
+
| 'default'
|
|
27
|
+
| 'disappearing-item'
|
|
28
|
+
| 'e-resize'
|
|
29
|
+
| 'grab'
|
|
30
|
+
| 'grabbing'
|
|
31
|
+
| 'n-resize'
|
|
32
|
+
| 'no-drop'
|
|
33
|
+
| 'not-allowed'
|
|
34
|
+
| 'pointer'
|
|
35
|
+
| 'row-resize'
|
|
36
|
+
| 's-resize'
|
|
37
|
+
| 'text'
|
|
38
|
+
| 'vertical-text'
|
|
39
|
+
| 'w-resize'
|
|
40
|
+
);
|
|
41
|
+
|
|
19
42
|
export type ColorArrayValue = null | $ReadOnlyArray<____ColorValue_Internal>;
|
|
20
43
|
export type PointValue = {|
|
|
21
44
|
x: number,
|
|
@@ -584,6 +607,7 @@ export type ____ViewStyle_Internal = $ReadOnly<{|
|
|
|
584
607
|
borderTopWidth?: number | AnimatedNode,
|
|
585
608
|
opacity?: number | AnimatedNode,
|
|
586
609
|
elevation?: number,
|
|
610
|
+
cursor?: CursorValue,
|
|
587
611
|
|}>;
|
|
588
612
|
|
|
589
613
|
export type ____FontWeight_Internal =
|
|
@@ -638,6 +662,7 @@ export type ____TextStyle_Internal = $ReadOnly<{|
|
|
|
638
662
|
textDecorationColor?: ____ColorValue_Internal,
|
|
639
663
|
textTransform?: 'none' | 'capitalize' | 'uppercase' | 'lowercase',
|
|
640
664
|
writingDirection?: 'auto' | 'ltr' | 'rtl',
|
|
665
|
+
cursor?: CursorValue,
|
|
641
666
|
|}>;
|
|
642
667
|
|
|
643
668
|
export type ____ImageStyle_Internal = $ReadOnly<{|
|
|
@@ -109,27 +109,27 @@ NSString *const RCTTextAttributesTagAttributeName = @"RCTTextAttributesTagAttrib
|
|
|
109
109
|
alignment = NSTextAlignmentRight;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
paragraphStyle.alignment = alignment;
|
|
114
114
|
isParagraphStyleUsed = YES;
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
if (_baseWritingDirection != NSWritingDirectionNatural) {
|
|
118
118
|
paragraphStyle.baseWritingDirection = _baseWritingDirection;
|
|
119
119
|
isParagraphStyleUsed = YES;
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
|
|
122
122
|
if (!isnan(_lineHeight)) {
|
|
123
123
|
CGFloat lineHeight = _lineHeight * self.effectiveFontSizeMultiplier;
|
|
124
124
|
paragraphStyle.minimumLineHeight = lineHeight;
|
|
125
125
|
paragraphStyle.maximumLineHeight = lineHeight;
|
|
126
126
|
isParagraphStyleUsed = YES;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
|
|
129
129
|
if (isParagraphStyleUsed) {
|
|
130
130
|
return [paragraphStyle copy];
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
return nil;
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -11,6 +11,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
11
11
|
|
|
12
12
|
@interface RCTMultilineTextInputView : RCTBaseTextInputView
|
|
13
13
|
|
|
14
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
15
|
+
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
|
|
16
|
+
#endif // ]TODO(macOS GH#774)
|
|
14
17
|
@end
|
|
15
18
|
|
|
16
19
|
NS_ASSUME_NONNULL_END
|
|
@@ -99,6 +99,9 @@
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes {
|
|
103
|
+
[_backedTextInputView setReadablePasteBoardTypes:readablePasteboardTypes];
|
|
104
|
+
}
|
|
102
105
|
#endif // ]TODO(macOS GH#774)
|
|
103
106
|
|
|
104
107
|
#pragma mark - UIScrollViewDelegate
|
|
@@ -106,7 +109,9 @@
|
|
|
106
109
|
- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // TODO(macOS ISS#3536887)
|
|
107
110
|
{
|
|
108
111
|
RCTDirectEventBlock onScroll = self.onScroll;
|
|
109
|
-
|
|
112
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
113
|
+
[_scrollView setHasVerticalScroller:YES];
|
|
114
|
+
#endif // ]TODO(macOS GH#774)
|
|
110
115
|
if (onScroll) {
|
|
111
116
|
CGPoint contentOffset = scrollView.contentOffset;
|
|
112
117
|
CGSize contentSize = scrollView.contentSize;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
#import <React/RCTMultilineTextInputViewManager.h>
|
|
9
9
|
#import <React/RCTMultilineTextInputView.h>
|
|
10
|
+
#import <React/RCTUITextView.h> // TODO(macOS GH#774)
|
|
10
11
|
|
|
11
12
|
@implementation RCTMultilineTextInputViewManager
|
|
12
13
|
|
|
@@ -22,4 +23,14 @@ RCT_EXPORT_MODULE()
|
|
|
22
23
|
RCT_REMAP_NOT_OSX_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.dataDetectorTypes, UIDataDetectorTypes) // TODO(macOS GH#774)
|
|
23
24
|
RCT_REMAP_OSX_VIEW_PROPERTY(dataDetectorTypes, backedTextInputView.enabledTextCheckingTypes, NSTextCheckingTypes) // TODO(macOS GH#774)
|
|
24
25
|
|
|
26
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
27
|
+
RCT_CUSTOM_VIEW_PROPERTY(pastedTypes, NSArray<NSPasteboardType>*, RCTUITextView)
|
|
28
|
+
{
|
|
29
|
+
NSArray<NSPasteboardType> *types = json ? [RCTConvert NSPasteboardTypeArray:json] : nil;
|
|
30
|
+
if ([view respondsToSelector:@selector(setReadablePasteBoardTypes:)]) {
|
|
31
|
+
[view setReadablePasteBoardTypes: types];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
#endif // ]TODO(macOS GH#774)
|
|
35
|
+
|
|
25
36
|
@end
|
|
@@ -53,6 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
53
53
|
@property (nonatomic, assign) NSTextAlignment textAlignment;
|
|
54
54
|
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
|
|
55
55
|
- (NSSize)sizeThatFits:(NSSize)size;
|
|
56
|
+
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
|
|
56
57
|
#endif // ]TODO(macOS GH#774)
|
|
57
58
|
|
|
58
59
|
@end
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
#endif // TODO(macOS GH#774)
|
|
22
22
|
RCTBackedTextViewDelegateAdapter *_textInputDelegateAdapter;
|
|
23
23
|
NSDictionary<NSAttributedStringKey, id> *_defaultTextAttributes;
|
|
24
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
25
|
+
NSArray<NSPasteboardType> *_readablePasteboardTypes;
|
|
26
|
+
#endif // TODO(macOS GH#774)
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
static UIFont *defaultPlaceholderFont()
|
|
@@ -177,6 +180,11 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|
|
177
180
|
self.string = text;
|
|
178
181
|
}
|
|
179
182
|
|
|
183
|
+
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes
|
|
184
|
+
{
|
|
185
|
+
_readablePasteboardTypes = readablePasteboardTypes;
|
|
186
|
+
}
|
|
187
|
+
|
|
180
188
|
- (void)setTypingAttributes:(__unused NSDictionary *)typingAttributes
|
|
181
189
|
{
|
|
182
190
|
// Prevent NSTextView from changing its own typing attributes out from under us.
|
|
@@ -320,12 +328,45 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|
|
320
328
|
{
|
|
321
329
|
return [super selectedRange];
|
|
322
330
|
}
|
|
331
|
+
|
|
332
|
+
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)draggingInfo
|
|
333
|
+
{
|
|
334
|
+
NSDragOperation dragOperation = [self.textInputDelegate textInputDraggingEntered:draggingInfo];
|
|
335
|
+
NSDragOperation superOperation = [super draggingEntered:draggingInfo];
|
|
336
|
+
// The delegate's operation should take precedence.
|
|
337
|
+
return dragOperation != NSDragOperationNone ? dragOperation : superOperation;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
- (void)draggingExited:(id<NSDraggingInfo>)draggingInfo
|
|
341
|
+
{
|
|
342
|
+
[self.textInputDelegate textInputDraggingExited:draggingInfo];
|
|
343
|
+
[super draggingExited:draggingInfo];
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
- (BOOL)performDragOperation:(id<NSDraggingInfo>)draggingInfo
|
|
347
|
+
{
|
|
348
|
+
if ([self.textInputDelegate textInputShouldHandleDragOperation:draggingInfo]) {
|
|
349
|
+
return [super performDragOperation:draggingInfo];
|
|
350
|
+
}
|
|
351
|
+
return YES;
|
|
352
|
+
}
|
|
353
|
+
- (NSArray *)readablePasteboardTypes
|
|
354
|
+
{
|
|
355
|
+
return _readablePasteboardTypes ? _readablePasteboardTypes : [super readablePasteboardTypes];
|
|
356
|
+
}
|
|
357
|
+
|
|
323
358
|
#endif // ]TODO(macOS GH#774)
|
|
324
359
|
|
|
325
360
|
- (void)paste:(id)sender
|
|
326
361
|
{
|
|
327
|
-
|
|
328
|
-
|
|
362
|
+
#if TARGET_OS_OSX // TODO(macOS GH#774)
|
|
363
|
+
if ([self.textInputDelegate textInputShouldHandlePaste:self]) {
|
|
364
|
+
#endif
|
|
365
|
+
[super paste:sender];
|
|
366
|
+
_textWasPasted = YES;
|
|
367
|
+
#if TARGET_OS_OSX // TODO(macOS GH#774)
|
|
368
|
+
}
|
|
369
|
+
#endif
|
|
329
370
|
}
|
|
330
371
|
|
|
331
372
|
// Turn off scroll animation to fix flaky scrolling.
|
|
@@ -383,6 +424,10 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|
|
383
424
|
// UI/NSTextField do NOT have textContainerInset properties
|
|
384
425
|
_textContainerInsets = textContainerInsets;
|
|
385
426
|
super.textContainerInset = NSMakeSize(MIN(textContainerInsets.left, textContainerInsets.right), MIN(textContainerInsets.top, textContainerInsets.bottom));
|
|
427
|
+
|
|
428
|
+
if (self.shouldDrawInsertionPoint) {
|
|
429
|
+
[self updateInsertionPointStateAndRestartTimer:NO];
|
|
430
|
+
}
|
|
386
431
|
}
|
|
387
432
|
|
|
388
433
|
#endif // ]TODO(macOS GH#774)
|
|
@@ -514,6 +559,28 @@ static RCTUIColor *defaultPlaceholderColor() // TODO(OSS Candidate ISS#2710739)
|
|
|
514
559
|
[super deleteBackward];
|
|
515
560
|
}
|
|
516
561
|
}
|
|
562
|
+
#else
|
|
563
|
+
- (void)keyDown:(NSEvent *)event {
|
|
564
|
+
// If has marked text, handle by native and return
|
|
565
|
+
// Do this check before textInputShouldHandleKeyEvent as that one attempts to send the event to JS
|
|
566
|
+
if (self.hasMarkedText) {
|
|
567
|
+
[super keyDown:event];
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// textInputShouldHandleKeyEvent represents if native should handle the event instead of JS.
|
|
572
|
+
// textInputShouldHandleKeyEvent also sends keyDown event to JS internally, so we only call this once
|
|
573
|
+
if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
|
|
574
|
+
[super keyDown:event];
|
|
575
|
+
[self.textInputDelegate submitOnKeyDownIfNeeded:event];
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
- (void)keyUp:(NSEvent *)event {
|
|
580
|
+
if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
|
|
581
|
+
[super keyUp:event];
|
|
582
|
+
}
|
|
583
|
+
}
|
|
517
584
|
#endif // ]TODO(OSS Candidate ISS#2710739)
|
|
518
585
|
|
|
519
586
|
- (void)_updatePlaceholder
|
|
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
26
26
|
- (void)automaticSpellingCorrectionDidChange:(BOOL)enabled;
|
|
27
27
|
- (void)continuousSpellCheckingDidChange:(BOOL)enabled;
|
|
28
28
|
- (void)grammarCheckingDidChange:(BOOL)enabled;
|
|
29
|
+
- (void)submitOnKeyDownIfNeeded:(NSEvent *)event;
|
|
29
30
|
#endif // ]TODO(macOS GH#774)
|
|
30
31
|
|
|
31
32
|
/*
|
|
@@ -42,8 +43,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
42
43
|
- (BOOL)textInputShouldHandleDeleteBackward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteBackward event handled normally. Return `NO` to disallow it and handle it yourself. TODO(OSS Candidate ISS#2710739)
|
|
43
44
|
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
44
45
|
- (BOOL)textInputShouldHandleDeleteForward:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the deleteForward event handled normally. Return `NO` to disallow it and handle it yourself.
|
|
45
|
-
|
|
46
|
+
- (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event; // Return `YES` to have the key event handled normally. Return `NO` to disallow it and handle it yourself.
|
|
47
|
+
- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key;
|
|
48
|
+
- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo;
|
|
49
|
+
- (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo;
|
|
50
|
+
- (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo;
|
|
46
51
|
- (void)textInputDidCancel; // Handle `Escape` key press.
|
|
52
|
+
- (BOOL)textInputShouldHandlePaste:(id<RCTBackedTextInputViewProtocol>)sender; // Return `YES` to have the paste event handled normally. Return `NO` to disallow it and handle it yourself.
|
|
47
53
|
#endif // ]TODO(macOS GH#774)
|
|
48
54
|
|
|
49
55
|
@optional
|
|
@@ -213,11 +213,18 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
|
|
|
213
213
|
}
|
|
214
214
|
//paste
|
|
215
215
|
} else if (commandSelector == @selector(paste:)) {
|
|
216
|
-
|
|
216
|
+
id<RCTBackedTextInputDelegate> textInputDelegate = [_backedTextInputView textInputDelegate];
|
|
217
|
+
if (textInputDelegate != nil && ![textInputDelegate textInputShouldHandlePaste:_backedTextInputView]) {
|
|
218
|
+
commandHandled = YES;
|
|
219
|
+
} else {
|
|
220
|
+
_backedTextInputView.textWasPasted = YES;
|
|
221
|
+
}
|
|
217
222
|
//escape
|
|
218
223
|
} else if (commandSelector == @selector(cancelOperation:)) {
|
|
219
224
|
[textInputDelegate textInputDidCancel];
|
|
220
|
-
[
|
|
225
|
+
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
|
|
226
|
+
[[_backedTextInputView window] makeFirstResponder:nil];
|
|
227
|
+
}
|
|
221
228
|
commandHandled = YES;
|
|
222
229
|
}
|
|
223
230
|
|
|
@@ -421,7 +428,9 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
|
|
|
421
428
|
//escape
|
|
422
429
|
} else if (commandSelector == @selector(cancelOperation:)) {
|
|
423
430
|
[textInputDelegate textInputDidCancel];
|
|
424
|
-
[
|
|
431
|
+
if (![textInputDelegate hasValidKeyDownOrValidKeyUp:@"Escape"]) {
|
|
432
|
+
[[_backedTextInputView window] makeFirstResponder:nil];
|
|
433
|
+
}
|
|
425
434
|
commandHandled = YES;
|
|
426
435
|
|
|
427
436
|
}
|
|
@@ -39,6 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
39
39
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onContentSizeChange;
|
|
40
40
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onSelectionChange;
|
|
41
41
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onChange;
|
|
42
|
+
@property (nonatomic, copy, nullable) RCTDirectEventBlock onPaste; // TODO(OSS Candidate GH#774)
|
|
42
43
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onChangeSync;
|
|
43
44
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
|
|
44
45
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onScroll;
|
|
@@ -46,8 +47,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
46
47
|
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onAutoCorrectChange;
|
|
47
48
|
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onSpellCheckChange;
|
|
48
49
|
@property (nonatomic, copy, nullable) RCTBubblingEventBlock onGrammarCheckChange;
|
|
50
|
+
@property (nonatomic, assign) BOOL clearTextOnSubmit;
|
|
51
|
+
@property (nonatomic, copy, nullable) RCTDirectEventBlock onSubmitEditing;
|
|
52
|
+
@property (nonatomic, copy) NSArray<NSDictionary *> *submitKeyEvents;
|
|
49
53
|
#endif // TODO(macOS GH#774)
|
|
50
|
-
|
|
51
54
|
@property (nonatomic, assign) NSInteger mostRecentEventCount;
|
|
52
55
|
@property (nonatomic, assign, readonly) NSInteger nativeEventCount;
|
|
53
56
|
@property (nonatomic, assign) BOOL autoFocus;
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
#import <React/RCTUtils.h>
|
|
15
15
|
#import <React/UIView+React.h>
|
|
16
16
|
|
|
17
|
+
#import <React/RCTViewKeyboardEvent.h> // TODO(macOS GH#774)
|
|
17
18
|
#import <React/RCTInputAccessoryView.h>
|
|
18
19
|
#import <React/RCTInputAccessoryViewContent.h>
|
|
19
20
|
#import <React/RCTTextAttributes.h>
|
|
20
21
|
#import <React/RCTTextSelection.h>
|
|
22
|
+
#import <React/RCTUITextView.h> // TODO(macOS GH#774)
|
|
21
23
|
#import "../RCTTextUIKit.h" // TODO(macOS GH#774)
|
|
22
24
|
|
|
23
25
|
@implementation RCTBaseTextInputView {
|
|
@@ -32,7 +34,7 @@
|
|
|
32
34
|
{
|
|
33
35
|
RCTAssertParam(bridge);
|
|
34
36
|
|
|
35
|
-
if (self = [super
|
|
37
|
+
if (self = [super initWithEventDispatcher:bridge.eventDispatcher]) { // TODO(OSS Candidate GH#774)
|
|
36
38
|
_bridge = bridge;
|
|
37
39
|
_eventDispatcher = bridge.eventDispatcher;
|
|
38
40
|
}
|
|
@@ -42,7 +44,6 @@
|
|
|
42
44
|
|
|
43
45
|
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|
44
46
|
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
|
|
45
|
-
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
46
47
|
|
|
47
48
|
- (RCTUIView<RCTBackedTextInputViewProtocol> *)backedTextInputView // TODO(macOS ISS#3536887)
|
|
48
49
|
{
|
|
@@ -153,6 +154,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
153
154
|
range:NSMakeRange(0, attributedTextCopy.length)];
|
|
154
155
|
|
|
155
156
|
textNeedsUpdate = ([self textOf:attributedTextCopy equals:backedTextInputViewTextCopy] == NO);
|
|
157
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
158
|
+
// If we are in a language that uses conversion (e.g. Japanese), ignore updates if we have unconverted text.
|
|
159
|
+
if ([self.backedTextInputView hasMarkedText]) {
|
|
160
|
+
textNeedsUpdate = NO;
|
|
161
|
+
}
|
|
162
|
+
#endif // ]TODO(macOS GH#774)
|
|
156
163
|
|
|
157
164
|
if (eventLag == 0 && textNeedsUpdate) {
|
|
158
165
|
#if !TARGET_OS_OSX // TODO(macOS GH#774)
|
|
@@ -423,6 +430,46 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
423
430
|
_onGrammarCheckChange(@{@"enabled": [NSNumber numberWithBool:enabled]});
|
|
424
431
|
}
|
|
425
432
|
}
|
|
433
|
+
|
|
434
|
+
- (void)submitOnKeyDownIfNeeded:(NSEvent *)event
|
|
435
|
+
{
|
|
436
|
+
NSDictionary *currentKeyboardEvent = [RCTViewKeyboardEvent bodyFromEvent:event];
|
|
437
|
+
// Enter is the default clearTextOnSubmit key
|
|
438
|
+
BOOL shouldSubmit = NO;
|
|
439
|
+
if (!_submitKeyEvents) {
|
|
440
|
+
shouldSubmit = [currentKeyboardEvent[@"key"] isEqualToString:@"Enter"]
|
|
441
|
+
&& ![currentKeyboardEvent[@"altKey"] boolValue]
|
|
442
|
+
&& ![currentKeyboardEvent[@"shiftKey"] boolValue]
|
|
443
|
+
&& ![currentKeyboardEvent[@"ctrlKey"] boolValue]
|
|
444
|
+
&& ![currentKeyboardEvent[@"metaKey"] boolValue]
|
|
445
|
+
&& ![currentKeyboardEvent[@"functionKey"] boolValue]; // Default clearTextOnSubmit key
|
|
446
|
+
} else {
|
|
447
|
+
for (NSDictionary *submitKeyEvent in _submitKeyEvents) {
|
|
448
|
+
if (
|
|
449
|
+
[submitKeyEvent[@"key"] isEqualToString:currentKeyboardEvent[@"key"]] &&
|
|
450
|
+
[submitKeyEvent[@"altKey"] boolValue] == [currentKeyboardEvent[@"altKey"] boolValue] &&
|
|
451
|
+
[submitKeyEvent[@"shiftKey"] boolValue] == [currentKeyboardEvent[@"shiftKey"] boolValue] &&
|
|
452
|
+
[submitKeyEvent[@"ctrlKey"] boolValue]== [currentKeyboardEvent[@"ctrlKey"] boolValue] &&
|
|
453
|
+
[submitKeyEvent[@"metaKey"] boolValue]== [currentKeyboardEvent[@"metaKey"] boolValue] &&
|
|
454
|
+
[submitKeyEvent[@"functionKey"] boolValue]== [currentKeyboardEvent[@"functionKey"] boolValue]
|
|
455
|
+
) {
|
|
456
|
+
shouldSubmit = YES;
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (shouldSubmit) {
|
|
463
|
+
if (_onSubmitEditing) {
|
|
464
|
+
_onSubmitEditing(@{});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (_clearTextOnSubmit) {
|
|
468
|
+
self.backedTextInputView.attributedText = [NSAttributedString new];
|
|
469
|
+
[self.backedTextInputView.textInputDelegate textInputDidChange];
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
426
473
|
#endif // ]TODO(macOS GH#774)
|
|
427
474
|
|
|
428
475
|
- (BOOL)textInputShouldReturn
|
|
@@ -589,6 +636,35 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
589
636
|
return YES;
|
|
590
637
|
}
|
|
591
638
|
|
|
639
|
+
- (BOOL)hasValidKeyDownOrValidKeyUp:(NSString *)key {
|
|
640
|
+
return [self.validKeysDown containsObject:key] || [self.validKeysUp containsObject:key];
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
- (NSDragOperation)textInputDraggingEntered:(id<NSDraggingInfo>)draggingInfo
|
|
644
|
+
{
|
|
645
|
+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
|
|
646
|
+
return [self draggingEntered:draggingInfo];
|
|
647
|
+
}
|
|
648
|
+
return NSDragOperationNone;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
- (void)textInputDraggingExited:(id<NSDraggingInfo>)draggingInfo
|
|
652
|
+
{
|
|
653
|
+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
|
|
654
|
+
[self draggingExited:draggingInfo];
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
- (BOOL)textInputShouldHandleDragOperation:(id<NSDraggingInfo>)draggingInfo
|
|
659
|
+
{
|
|
660
|
+
if ([draggingInfo.draggingPasteboard availableTypeFromArray:self.registeredDraggedTypes]) {
|
|
661
|
+
[self performDragOperation:draggingInfo];
|
|
662
|
+
return NO;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return YES;
|
|
666
|
+
}
|
|
667
|
+
|
|
592
668
|
- (void)textInputDidCancel {
|
|
593
669
|
[_eventDispatcher sendTextEventWithType:RCTTextEventTypeKeyPress
|
|
594
670
|
reactTag:self.reactTag
|
|
@@ -597,6 +673,25 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
|
|
|
597
673
|
eventCount:_nativeEventCount];
|
|
598
674
|
[self textInputDidEndEditing];
|
|
599
675
|
}
|
|
676
|
+
|
|
677
|
+
- (BOOL)textInputShouldHandleKeyEvent:(NSEvent *)event {
|
|
678
|
+
return ![self handleKeyboardEvent:event];
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
- (BOOL)textInputShouldHandlePaste:(__unused id)sender
|
|
682
|
+
{
|
|
683
|
+
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
|
|
684
|
+
NSPasteboardType fileType = [pasteboard availableTypeFromArray:@[NSPasteboardTypeFileURL, NSPasteboardTypePNG, NSPasteboardTypeTIFF]];
|
|
685
|
+
NSArray<NSPasteboardType>* pastedTypes = ((RCTUITextView*) self.backedTextInputView).readablePasteboardTypes;
|
|
686
|
+
|
|
687
|
+
// If there's a fileType that is of interest, notify JS. Also blocks notifying JS if it's a text paste
|
|
688
|
+
if (_onPaste && fileType != nil && [pastedTypes containsObject:fileType]) {
|
|
689
|
+
_onPaste([self dataTransferInfoFromPasteboard:pasteboard]);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// Only allow pasting text.
|
|
693
|
+
return fileType == nil;
|
|
694
|
+
}
|
|
600
695
|
#endif // ]TODO(macOS GH#774)
|
|
601
696
|
|
|
602
697
|
- (void)updateLocalData
|
|
@@ -71,12 +71,18 @@ RCT_EXPORT_VIEW_PROPERTY(passwordRules, NSString)
|
|
|
71
71
|
RCT_EXPORT_VIEW_PROPERTY(onAutoCorrectChange, RCTBubblingEventBlock);
|
|
72
72
|
RCT_EXPORT_VIEW_PROPERTY(onSpellCheckChange, RCTBubblingEventBlock);
|
|
73
73
|
RCT_EXPORT_VIEW_PROPERTY(onGrammarCheckChange, RCTBubblingEventBlock);
|
|
74
|
+
|
|
75
|
+
// Specifically for clearing text on enter key press
|
|
76
|
+
RCT_EXPORT_VIEW_PROPERTY(clearTextOnSubmit, BOOL);
|
|
77
|
+
RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock);
|
|
78
|
+
RCT_EXPORT_VIEW_PROPERTY(submitKeyEvents, NSArray<NSDictionary *>);
|
|
74
79
|
#endif // TODO(macOS GH#774)
|
|
75
80
|
|
|
76
81
|
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
|
|
77
82
|
RCT_EXPORT_VIEW_PROPERTY(onKeyPressSync, RCTDirectEventBlock)
|
|
78
83
|
RCT_EXPORT_VIEW_PROPERTY(onChangeSync, RCTDirectEventBlock)
|
|
79
84
|
RCT_EXPORT_VIEW_PROPERTY(onSelectionChange, RCTDirectEventBlock)
|
|
85
|
+
RCT_EXPORT_VIEW_PROPERTY(onPaste, RCTDirectEventBlock)
|
|
80
86
|
RCT_EXPORT_VIEW_PROPERTY(onTextInput, RCTDirectEventBlock)
|
|
81
87
|
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
|
|
82
88
|
|
|
@@ -127,6 +127,13 @@
|
|
|
127
127
|
#endif // ]TODO(macOS GH#774)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
131
|
+
- (BOOL)hasMarkedText
|
|
132
|
+
{
|
|
133
|
+
return ((NSTextView *)self.currentEditor).hasMarkedText;
|
|
134
|
+
}
|
|
135
|
+
#endif // ]TODO(macOS GH#774)
|
|
136
|
+
|
|
130
137
|
#pragma mark - Accessibility
|
|
131
138
|
|
|
132
139
|
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
@@ -144,11 +151,27 @@
|
|
|
144
151
|
|
|
145
152
|
- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
|
|
146
153
|
{
|
|
154
|
+
if (UIEdgeInsetsEqualToEdgeInsets(textContainerInset, _textContainerInset)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
147
158
|
_textContainerInset = textContainerInset;
|
|
148
159
|
#if !TARGET_OS_OSX // TODO(macOS GH#774)
|
|
149
160
|
[self setNeedsLayout];
|
|
150
161
|
#else // [TODO(macOS GH#774)
|
|
151
162
|
((RCTUITextFieldCell*)self.cell).textContainerInset = _textContainerInset;
|
|
163
|
+
|
|
164
|
+
if (self.currentEditor) {
|
|
165
|
+
NSRange selectedRange = self.currentEditor.selectedRange;
|
|
166
|
+
|
|
167
|
+
// Relocate the NSTextView without changing the selection.
|
|
168
|
+
[self.cell selectWithFrame:self.bounds
|
|
169
|
+
inView:self
|
|
170
|
+
editor:self.currentEditor
|
|
171
|
+
delegate:self
|
|
172
|
+
start:selectedRange.location
|
|
173
|
+
length:selectedRange.length];
|
|
174
|
+
}
|
|
152
175
|
#endif // ]TODO(macOS GH#774)
|
|
153
176
|
}
|
|
154
177
|
|
|
@@ -482,6 +505,17 @@
|
|
|
482
505
|
}
|
|
483
506
|
return isFirstResponder;
|
|
484
507
|
}
|
|
508
|
+
|
|
509
|
+
- (BOOL)performKeyEquivalent:(NSEvent *)event
|
|
510
|
+
{
|
|
511
|
+
// The currentEditor is NSText for historical reasons, but documented to be NSTextView.
|
|
512
|
+
NSTextView *currentEditor = (NSTextView *)self.currentEditor;
|
|
513
|
+
// The currentEditor is non-nil when focused and hasMarkedText means an IME is open.
|
|
514
|
+
if (currentEditor && !currentEditor.hasMarkedText && ![self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
|
|
515
|
+
return YES; // Don't send currentEditor the keydown event.
|
|
516
|
+
}
|
|
517
|
+
return [super performKeyEquivalent:event];
|
|
518
|
+
}
|
|
485
519
|
#endif // ]TODO(macOS GH#774)
|
|
486
520
|
|
|
487
521
|
#if !TARGET_OS_OSX // TODO(macOS GH#774)
|
|
@@ -563,6 +597,12 @@
|
|
|
563
597
|
[super deleteBackward];
|
|
564
598
|
}
|
|
565
599
|
}
|
|
600
|
+
#else
|
|
601
|
+
- (void)keyUp:(NSEvent *)event {
|
|
602
|
+
if ([self.textInputDelegate textInputShouldHandleKeyEvent:event]) {
|
|
603
|
+
[super keyUp:event];
|
|
604
|
+
}
|
|
605
|
+
}
|
|
566
606
|
#endif // ]TODO(OSS Candidate ISS#2710739)
|
|
567
607
|
|
|
568
608
|
@end
|
package/React/Base/RCTConvert.m
CHANGED
|
@@ -1233,9 +1233,12 @@ RCT_JSON_ARRAY_CONVERTER(NSNumber)
|
|
|
1233
1233
|
}
|
|
1234
1234
|
|
|
1235
1235
|
if ([type isEqualToString:@"fileUrl"]) {
|
|
1236
|
-
return @[
|
|
1236
|
+
return @[NSPasteboardTypeFileURL];
|
|
1237
|
+
} else if ([type isEqualToString:@"image"]) {
|
|
1238
|
+
return @[NSPasteboardTypePNG, NSPasteboardTypeTIFF];
|
|
1239
|
+
} else if ([type isEqualToString:@"string"]) {
|
|
1240
|
+
return @[NSPasteboardTypeString];
|
|
1237
1241
|
}
|
|
1238
|
-
|
|
1239
1242
|
return @[];
|
|
1240
1243
|
}
|
|
1241
1244
|
|
|
@@ -1244,11 +1247,11 @@ RCT_JSON_ARRAY_CONVERTER(NSNumber)
|
|
|
1244
1247
|
if ([json isKindOfClass:[NSString class]]) {
|
|
1245
1248
|
return [RCTConvert NSPasteboardType:json];
|
|
1246
1249
|
} else if ([json isKindOfClass:[NSArray class]]) {
|
|
1247
|
-
NSMutableArray *
|
|
1250
|
+
NSMutableArray *mutablePasteboardTypes = [NSMutableArray new];
|
|
1248
1251
|
for (NSString *type in json) {
|
|
1249
|
-
[
|
|
1250
|
-
return mutablePastboardTypes.copy;
|
|
1252
|
+
[mutablePasteboardTypes addObjectsFromArray:[RCTConvert NSPasteboardType:type]];
|
|
1251
1253
|
}
|
|
1254
|
+
return mutablePasteboardTypes.copy;
|
|
1252
1255
|
}
|
|
1253
1256
|
return @[];
|
|
1254
1257
|
}
|
|
@@ -1461,6 +1464,7 @@ RCT_ENUM_CONVERTER(
|
|
|
1461
1464
|
@"list": NSAccessibilityListRole,
|
|
1462
1465
|
@"popupbutton": NSAccessibilityPopUpButtonRole,
|
|
1463
1466
|
@"menubutton": NSAccessibilityMenuButtonRole,
|
|
1467
|
+
@"table": NSAccessibilityTableRole,
|
|
1464
1468
|
};
|
|
1465
1469
|
});
|
|
1466
1470
|
|