react-native-macos 0.0.0-8c5d0eced → 0.0.0-8f5b6f691
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 +69 -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.m +3 -1
- package/Libraries/Text/TextInput/Multiline/RCTUITextView.m +68 -2
- package/Libraries/Text/TextInput/RCTBackedTextInputDelegate.h +12 -1
- package/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m +12 -3
- package/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +1 -0
- package/Libraries/Text/TextInput/RCTBaseTextInputView.h +6 -0
- package/Libraries/Text/TextInput/RCTBaseTextInputView.m +77 -2
- package/Libraries/Text/TextInput/RCTBaseTextInputViewManager.m +7 -0
- package/Libraries/Text/TextInput/Singleline/RCTUITextField.m +24 -0
- package/Libraries/Types/CoreEventTypes.js +0 -1
- package/React/Base/RCTConvert.m +3 -0
- package/React/Base/RCTRootView.m +0 -9
- package/React/Base/RCTUtils.m +27 -0
- package/React/Base/RCTVersion.m +1 -1
- package/React/Base/macOS/RCTUIKit.m +7 -0
- package/React/CoreModules/RCTAppearance.mm +21 -5
- 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 +16 -0
- package/React/Views/RCTView.m +135 -190
- package/React/Views/RCTViewKeyboardEvent.h +6 -28
- package/React/Views/RCTViewKeyboardEvent.m +66 -61
- 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/android/gradlew.bat +89 -89
- package/template/package.json +1 -1
- package/third-party-podspecs/boost-for-react-native.podspec +0 -20
|
@@ -499,6 +499,10 @@ export type Props = $ReadOnly<{|
|
|
|
499
499
|
* ScrollView. This is usually used with inverted ScrollViews.
|
|
500
500
|
*/
|
|
501
501
|
invertStickyHeaders?: ?boolean,
|
|
502
|
+
/**
|
|
503
|
+
* Reverses the direction of scroll. Uses native inversion on macOS and scale transforms of -1 elsewhere
|
|
504
|
+
*/
|
|
505
|
+
inverted?: ?boolean, // TODO(macOS GH#774)
|
|
502
506
|
/**
|
|
503
507
|
* Determines whether the keyboard gets dismissed in response to a drag.
|
|
504
508
|
*
|
|
@@ -1188,54 +1192,15 @@ class ScrollView extends React.Component<Props, State> {
|
|
|
1188
1192
|
}
|
|
1189
1193
|
|
|
1190
1194
|
// [TODO(macOS GH#774)
|
|
1191
|
-
_handleKeyDown = (event: ScrollEvent) => {
|
|
1192
|
-
if (this.props.onScrollKeyDown) {
|
|
1193
|
-
this.props.onScrollKeyDown(event);
|
|
1194
|
-
} else {
|
|
1195
|
-
if (Platform.OS === 'macos') {
|
|
1196
|
-
const nativeEvent = event.nativeEvent;
|
|
1197
|
-
const key = nativeEvent.key;
|
|
1198
|
-
const kMinScrollOffset = 10;
|
|
1199
|
-
if (key === 'PAGE_UP') {
|
|
1200
|
-
this._handleScrollByKeyDown(event, {
|
|
1201
|
-
x: nativeEvent.contentOffset.x,
|
|
1202
|
-
y:
|
|
1203
|
-
nativeEvent.contentOffset.y +
|
|
1204
|
-
-nativeEvent.layoutMeasurement.height,
|
|
1205
|
-
});
|
|
1206
|
-
} else if (key === 'PAGE_DOWN') {
|
|
1207
|
-
this._handleScrollByKeyDown(event, {
|
|
1208
|
-
x: nativeEvent.contentOffset.x,
|
|
1209
|
-
y:
|
|
1210
|
-
nativeEvent.contentOffset.y +
|
|
1211
|
-
nativeEvent.layoutMeasurement.height,
|
|
1212
|
-
});
|
|
1213
|
-
} else if (key === 'HOME') {
|
|
1214
|
-
this.scrollTo({x: 0, y: 0});
|
|
1215
|
-
} else if (key === 'END') {
|
|
1216
|
-
this.scrollToEnd({animated: true});
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
};
|
|
1221
|
-
|
|
1222
|
-
_handleScrollByKeyDown = (event: ScrollEvent, newOffset) => {
|
|
1223
|
-
const maxX =
|
|
1224
|
-
event.nativeEvent.contentSize.width -
|
|
1225
|
-
event.nativeEvent.layoutMeasurement.width;
|
|
1226
|
-
const maxY =
|
|
1227
|
-
event.nativeEvent.contentSize.height -
|
|
1228
|
-
event.nativeEvent.layoutMeasurement.height;
|
|
1229
|
-
this.scrollTo({
|
|
1230
|
-
x: Math.max(0, Math.min(maxX, newOffset.x)),
|
|
1231
|
-
y: Math.max(0, Math.min(maxY, newOffset.y)),
|
|
1232
|
-
});
|
|
1233
|
-
};
|
|
1234
|
-
|
|
1235
1195
|
_handlePreferredScrollerStyleDidChange = (event: ScrollEvent) => {
|
|
1236
1196
|
this.setState({contentKey: this.state.contentKey + 1});
|
|
1237
1197
|
}; // ]TODO(macOS GH#774)
|
|
1238
1198
|
|
|
1199
|
+
// [TODO(macOS GH#774)
|
|
1200
|
+
_handleInvertedDidChange = () => {
|
|
1201
|
+
this.setState({contentKey: this.state.contentKey + 1});
|
|
1202
|
+
}; // ]TODO(macOS GH#774)
|
|
1203
|
+
|
|
1239
1204
|
_handleScroll = (e: ScrollEvent) => {
|
|
1240
1205
|
if (__DEV__) {
|
|
1241
1206
|
if (
|
|
@@ -1760,6 +1725,7 @@ class ScrollView extends React.Component<Props, State> {
|
|
|
1760
1725
|
: this.props.removeClippedSubviews
|
|
1761
1726
|
}
|
|
1762
1727
|
key={this.state.contentKey} // TODO(macOS GH#774)
|
|
1728
|
+
inverted={this.props.inverted} // TODO(macOS GH#774)
|
|
1763
1729
|
collapsable={false}>
|
|
1764
1730
|
{children}
|
|
1765
1731
|
</NativeDirectionalScrollContentView>
|
|
@@ -1787,7 +1753,7 @@ class ScrollView extends React.Component<Props, State> {
|
|
|
1787
1753
|
// Override the onContentSizeChange from props, since this event can
|
|
1788
1754
|
// bubble up from TextInputs
|
|
1789
1755
|
onContentSizeChange: null,
|
|
1790
|
-
|
|
1756
|
+
onInvertedDidChange: this._handleInvertedDidChange, // TODO macOS GH#774
|
|
1791
1757
|
onPreferredScrollerStyleDidChange:
|
|
1792
1758
|
this._handlePreferredScrollerStyleDidChange, // TODO(macOS GH#774)
|
|
1793
1759
|
onLayout: this._handleLayout,
|
|
@@ -130,6 +130,33 @@ export type EditingEvent = SyntheticEvent<
|
|
|
130
130
|
|}>,
|
|
131
131
|
>;
|
|
132
132
|
|
|
133
|
+
// macOS-only // [TODO(macOS GH#774)
|
|
134
|
+
export type SettingChangeEvent = SyntheticEvent<
|
|
135
|
+
$ReadOnly<{|
|
|
136
|
+
enabled: boolean,
|
|
137
|
+
|}>,
|
|
138
|
+
>;
|
|
139
|
+
|
|
140
|
+
export type PasteEvent = SyntheticEvent<
|
|
141
|
+
$ReadOnly<{|
|
|
142
|
+
dataTransfer: {|
|
|
143
|
+
files: $ReadOnlyArray<{|
|
|
144
|
+
height: number,
|
|
145
|
+
size: number,
|
|
146
|
+
type: string,
|
|
147
|
+
uri: string,
|
|
148
|
+
width: number,
|
|
149
|
+
|}>,
|
|
150
|
+
items: $ReadOnlyArray<{|
|
|
151
|
+
kind: string,
|
|
152
|
+
type: string,
|
|
153
|
+
|}>,
|
|
154
|
+
types: $ReadOnlyArray<string>,
|
|
155
|
+
|},
|
|
156
|
+
|}>,
|
|
157
|
+
>;
|
|
158
|
+
// ]TODO(macOS GH#774)
|
|
159
|
+
|
|
133
160
|
type DataDetectorTypesType =
|
|
134
161
|
// iOS+macOS
|
|
135
162
|
| 'phoneNumber'
|
|
@@ -306,7 +333,7 @@ type IOSProps = $ReadOnly<{|
|
|
|
306
333
|
// [TODO(macOS GH#774)
|
|
307
334
|
/**
|
|
308
335
|
* If `false`, disables grammar-check.
|
|
309
|
-
* @platform
|
|
336
|
+
* @platform macos
|
|
310
337
|
*/
|
|
311
338
|
grammarCheck?: ?boolean,
|
|
312
339
|
// ]TODO(macOS GH#774)
|
|
@@ -637,6 +664,38 @@ export type Props = $ReadOnly<{|
|
|
|
637
664
|
*/
|
|
638
665
|
onChangeText?: ?(text: string) => mixed,
|
|
639
666
|
|
|
667
|
+
// [TODO(macOS GH#774)
|
|
668
|
+
/**
|
|
669
|
+
* Callback that is called when the text input's autoCorrect setting changes.
|
|
670
|
+
* This will be called with
|
|
671
|
+
* `{ nativeEvent: { enabled } }`.
|
|
672
|
+
* Does only work with 'multiline={true}'.
|
|
673
|
+
*
|
|
674
|
+
* @platform macos
|
|
675
|
+
*/
|
|
676
|
+
onAutoCorrectChange?: ?(e: SettingChangeEvent) => mixed,
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Callback that is called when the text input's spellCheck setting changes.
|
|
680
|
+
* This will be called with
|
|
681
|
+
* `{ nativeEvent: { enabled } }`.
|
|
682
|
+
* Does only work with 'multiline={true}'.
|
|
683
|
+
*
|
|
684
|
+
* @platform macos
|
|
685
|
+
*/
|
|
686
|
+
onSpellCheckChange?: ?(e: SettingChangeEvent) => mixed,
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Callback that is called when the text input's grammarCheck setting changes.
|
|
690
|
+
* This will be called with
|
|
691
|
+
* `{ nativeEvent: { enabled } }`.
|
|
692
|
+
* Does only work with 'multiline={true}'.
|
|
693
|
+
*
|
|
694
|
+
* @platform macos
|
|
695
|
+
*/
|
|
696
|
+
onGrammarCheckChange?: ?(e: SettingChangeEvent) => mixed,
|
|
697
|
+
// ]TODO(macOS GH#774)
|
|
698
|
+
|
|
640
699
|
/**
|
|
641
700
|
* DANGER: this API is not stable and will change in the future.
|
|
642
701
|
*
|
|
@@ -701,6 +760,13 @@ export type Props = $ReadOnly<{|
|
|
|
701
760
|
*/
|
|
702
761
|
onPressOut?: ?(event: PressEvent) => mixed,
|
|
703
762
|
|
|
763
|
+
/**
|
|
764
|
+
* Fired when a supported element is pasted
|
|
765
|
+
*
|
|
766
|
+
* @platform macos
|
|
767
|
+
*/
|
|
768
|
+
onPaste?: (event: PasteEvent) => void, // TODO(macOS GH#774)
|
|
769
|
+
|
|
704
770
|
/**
|
|
705
771
|
* Callback that is called when the text input selection is changed.
|
|
706
772
|
* This will be called with
|
|
@@ -1294,6 +1360,8 @@ function InternalTextInput(props: Props): React.Node {
|
|
|
1294
1360
|
onChangeSync={useOnChangeSync === true ? _onChangeSync : null}
|
|
1295
1361
|
onContentSizeChange={props.onContentSizeChange}
|
|
1296
1362
|
onFocus={_onFocus}
|
|
1363
|
+
onKeyDown={props.onKeyDown} // TODO(macOS GH#774)
|
|
1364
|
+
onKeyUp={props.onKeyUp} // TODO(macOS GH#774)
|
|
1297
1365
|
onScroll={_onScroll}
|
|
1298
1366
|
onSelectionChange={_onSelectionChange}
|
|
1299
1367
|
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
|
|
@@ -39,6 +39,7 @@ const ReactNativeViewViewConfigMacOS = {
|
|
|
39
39
|
accessibilityTraits: true,
|
|
40
40
|
draggedTypes: true,
|
|
41
41
|
enableFocusRing: true,
|
|
42
|
+
nextKeyViewTag: true,
|
|
42
43
|
onBlur: true,
|
|
43
44
|
onClick: true,
|
|
44
45
|
onDoubleClick: true,
|
|
@@ -48,12 +49,11 @@ const ReactNativeViewViewConfigMacOS = {
|
|
|
48
49
|
onFocus: true,
|
|
49
50
|
onKeyDown: true,
|
|
50
51
|
onKeyUp: true,
|
|
51
|
-
validKeysDown: true,
|
|
52
|
-
validKeysUp: true,
|
|
53
|
-
nextKeyViewTag: true,
|
|
54
52
|
onMouseEnter: true,
|
|
55
53
|
onMouseLeave: true,
|
|
56
54
|
tooltip: true,
|
|
55
|
+
validKeysDown: true,
|
|
56
|
+
validKeysUp: true,
|
|
57
57
|
},
|
|
58
58
|
};
|
|
59
59
|
|
|
@@ -71,16 +71,16 @@ type DirectEventProps = $ReadOnly<{|
|
|
|
71
71
|
onDoubleClick?: ?(event: SyntheticEvent<{}>) => mixed, // TODO(macOS GH#774)
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* This event is fired when the
|
|
75
|
-
*
|
|
74
|
+
* This event is fired when the scrollView's inverted property changes.
|
|
75
|
+
* @platform macos
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
onInvertedDidChange?: ?() => mixed, // TODO(macOS GH#774)
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
80
|
+
* This event is fired when the system's preferred scroller style changes.
|
|
81
|
+
* The `preferredScrollerStyle` key will be `legacy` or `overlay`.
|
|
82
82
|
*/
|
|
83
|
-
|
|
83
|
+
onPreferredScrollerStyleDidChange?: ?(event: ScrollEvent) => mixed, // TODO(macOS GH#774)
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* Invoked on mount and layout changes with:
|
|
@@ -420,6 +420,10 @@ type IOSViewProps = $ReadOnly<{|
|
|
|
420
420
|
* See https://reactnative.dev/docs/view#accessibilityElementsHidden
|
|
421
421
|
*/
|
|
422
422
|
accessibilityElementsHidden?: ?boolean,
|
|
423
|
+
/**
|
|
424
|
+
* Reverses the direction of scroll. Uses native inversion on macOS and scale transforms of -1 elsewhere
|
|
425
|
+
*/
|
|
426
|
+
inverted?: ?boolean, // TODO(macOS GH#774)
|
|
423
427
|
|
|
424
428
|
onDoubleClick?: ?(event: SyntheticEvent<{}>) => mixed, // TODO(macOS GH#774)
|
|
425
429
|
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
#if TARGET_OS_OSX // [TODO(macOS GH#774)
|
|
17
17
|
+ (void)getUrlEventHandler:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
|
|
18
|
+
+ (void)setAlwaysForegroundLastWindow:(BOOL)alwaysForeground;
|
|
18
19
|
#else // ]TODO(macOS GH#774)
|
|
19
20
|
+ (BOOL)application:(nonnull UIApplication *)app
|
|
20
21
|
openURL:(nonnull NSURL *)URL
|
|
@@ -21,6 +21,7 @@ NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
|
|
|
21
21
|
|
|
22
22
|
static NSString *initialURL = nil;
|
|
23
23
|
static BOOL moduleInitalized = NO;
|
|
24
|
+
static BOOL alwaysForegroundLastWindow = YES;
|
|
24
25
|
|
|
25
26
|
static void postNotificationWithURL(NSString *url, id sender)
|
|
26
27
|
{
|
|
@@ -60,6 +61,11 @@ RCT_EXPORT_MODULE()
|
|
|
60
61
|
return @[@"url"];
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
+ (void)setAlwaysForegroundLastWindow:(BOOL)alwaysForeground
|
|
65
|
+
{
|
|
66
|
+
alwaysForegroundLastWindow = alwaysForeground;
|
|
67
|
+
}
|
|
68
|
+
|
|
63
69
|
+ (void)getUrlEventHandler:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
|
|
64
70
|
{
|
|
65
71
|
// extract url value from the event
|
|
@@ -76,12 +82,13 @@ RCT_EXPORT_MODULE()
|
|
|
76
82
|
|
|
77
83
|
- (void)handleOpenURLNotification:(NSNotification *)notification
|
|
78
84
|
{
|
|
79
|
-
//
|
|
80
|
-
// and another app is maximized
|
|
85
|
+
// Activate app, because [NSApp mainWindow] returns nil when the app is hidden and another app is maximized
|
|
81
86
|
[NSApp activateIgnoringOtherApps:YES];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
// foreground top level window
|
|
88
|
+
if (alwaysForegroundLastWindow) {
|
|
89
|
+
NSWindow *lastWindow = [[NSApp windows] lastObject];
|
|
90
|
+
[lastWindow makeKeyAndOrderFront:nil];
|
|
91
|
+
}
|
|
85
92
|
[self sendEventWithName:@"url" body:notification.userInfo];
|
|
86
93
|
}
|
|
87
94
|
|
|
@@ -66,6 +66,24 @@ type OptionalProps<ItemT> = {|
|
|
|
66
66
|
* Optional custom style for multi-item rows generated when numColumns > 1.
|
|
67
67
|
*/
|
|
68
68
|
columnWrapperStyle?: ViewStyleProp,
|
|
69
|
+
// [TODO(macOS GH#774)
|
|
70
|
+
/**
|
|
71
|
+
* Allows you to 'select' a row using arrow keys. The selected row will have the prop `isSelected`
|
|
72
|
+
* passed in as true to it's renderItem / ListItemComponent. You can also imperatively select a row
|
|
73
|
+
* using the `selectRowAtIndex` method. You can set the initially selected row using the
|
|
74
|
+
* `initialSelectedIndex` prop.
|
|
75
|
+
* Keyboard Behavior:
|
|
76
|
+
* - ArrowUp: Select row above current selected row
|
|
77
|
+
* - ArrowDown: Select row below current selected row
|
|
78
|
+
* - Option+ArrowUp: Select the first row
|
|
79
|
+
* - Opton+ArrowDown: Select the last 'realized' row
|
|
80
|
+
* - Home: Scroll to top of list
|
|
81
|
+
* - End: Scroll to end of list
|
|
82
|
+
*
|
|
83
|
+
* @platform macos
|
|
84
|
+
*/
|
|
85
|
+
enableSelectionOnKeyPress?: ?boolean,
|
|
86
|
+
// ]TODO(macOS GH#774)
|
|
69
87
|
/**
|
|
70
88
|
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
|
|
71
89
|
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
|
|
@@ -111,8 +129,14 @@ type OptionalProps<ItemT> = {|
|
|
|
111
129
|
* `getItemLayout` to be implemented.
|
|
112
130
|
*/
|
|
113
131
|
initialScrollIndex?: ?number,
|
|
132
|
+
// [TODO(macOS GH#774)
|
|
133
|
+
/**
|
|
134
|
+
* The initially selected row, if `enableSelectionOnKeyPress` is set.
|
|
135
|
+
*/
|
|
136
|
+
initialSelectedIndex?: ?number,
|
|
137
|
+
// ]TODO(macOS GH#774)
|
|
114
138
|
/**
|
|
115
|
-
* Reverses the direction of scroll. Uses scale transforms of -1
|
|
139
|
+
* Reverses the direction of scroll. Uses native inversion on macOS and scale transforms of -1 elsewhere
|
|
116
140
|
*/
|
|
117
141
|
inverted?: ?boolean,
|
|
118
142
|
/**
|
|
@@ -35,7 +35,7 @@ import type {
|
|
|
35
35
|
ViewToken,
|
|
36
36
|
ViewabilityConfigCallbackPair,
|
|
37
37
|
} from './ViewabilityHelper';
|
|
38
|
-
import type {
|
|
38
|
+
import type {KeyEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
|
|
39
39
|
import {
|
|
40
40
|
VirtualizedListCellContextProvider,
|
|
41
41
|
VirtualizedListContext,
|
|
@@ -109,12 +109,24 @@ type OptionalProps = {|
|
|
|
109
109
|
* this for debugging purposes. Defaults to false.
|
|
110
110
|
*/
|
|
111
111
|
disableVirtualization?: ?boolean,
|
|
112
|
+
// [TODO(macOS GH#774)
|
|
112
113
|
/**
|
|
113
|
-
*
|
|
114
|
+
* Allows you to 'select' a row using arrow keys. The selected row will have the prop `isSelected`
|
|
115
|
+
* passed in as true to it's renderItem / ListItemComponent. You can also imperatively select a row
|
|
116
|
+
* using the `selectRowAtIndex` method. You can set the initially selected row using the
|
|
117
|
+
* `initialSelectedIndex` prop.
|
|
118
|
+
* Keyboard Behavior:
|
|
119
|
+
* - ArrowUp: Select row above current selected row
|
|
120
|
+
* - ArrowDown: Select row below current selected row
|
|
121
|
+
* - Option+ArrowUp: Select the first row
|
|
122
|
+
* - Opton+ArrowDown: Select the last 'realized' row
|
|
123
|
+
* - Home: Scroll to top of list
|
|
124
|
+
* - End: Scroll to end of list
|
|
114
125
|
*
|
|
115
126
|
* @platform macos
|
|
116
127
|
*/
|
|
117
|
-
enableSelectionOnKeyPress?: ?boolean,
|
|
128
|
+
enableSelectionOnKeyPress?: ?boolean,
|
|
129
|
+
// ]TODO(macOS GH#774)
|
|
118
130
|
/**
|
|
119
131
|
* A marker property for telling the list to re-render (since it implements `PureComponent`). If
|
|
120
132
|
* any of your `renderItem`, Header, Footer, etc. functions depend on anything outside of the
|
|
@@ -145,6 +157,12 @@ type OptionalProps = {|
|
|
|
145
157
|
* `getItemLayout` to be implemented.
|
|
146
158
|
*/
|
|
147
159
|
initialScrollIndex?: ?number,
|
|
160
|
+
// [TODO(macOS GH#774)
|
|
161
|
+
/**
|
|
162
|
+
* The initially selected row, if `enableSelectionOnKeyPress` is set.
|
|
163
|
+
*/
|
|
164
|
+
initialSelectedIndex?: ?number,
|
|
165
|
+
// ]TODO(macOS GH#774)
|
|
148
166
|
/**
|
|
149
167
|
* Reverses the direction of scroll. Uses scale transforms of -1.
|
|
150
168
|
*/
|
|
@@ -782,7 +800,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
782
800
|
(this.props.initialScrollIndex || 0) +
|
|
783
801
|
initialNumToRenderOrDefault(this.props.initialNumToRender),
|
|
784
802
|
) - 1,
|
|
785
|
-
selectedRowIndex:
|
|
803
|
+
selectedRowIndex: this.props.initialSelectedIndex ?? -1, // TODO(macOS GH#774)
|
|
786
804
|
};
|
|
787
805
|
|
|
788
806
|
if (this._isNestedWithSameOrientation()) {
|
|
@@ -845,7 +863,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
845
863
|
),
|
|
846
864
|
last: Math.max(0, Math.min(prevState.last, getItemCount(data) - 1)),
|
|
847
865
|
selectedRowIndex: Math.max(
|
|
848
|
-
|
|
866
|
+
-1, // Used to indicate no row is selected
|
|
849
867
|
Math.min(prevState.selectedRowIndex, getItemCount(data)),
|
|
850
868
|
), // TODO(macOS GH#774)
|
|
851
869
|
};
|
|
@@ -961,11 +979,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
961
979
|
this.props;
|
|
962
980
|
const {data, horizontal} = this.props;
|
|
963
981
|
const isVirtualizationDisabled = this._isVirtualizationDisabled();
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
982
|
+
// macOS natively supports inverted lists, thus not needing an inversion style
|
|
983
|
+
const inversionStyle =
|
|
984
|
+
this.props.inverted && Platform.OS !== 'macos' // TODO(macOS GH#774)
|
|
985
|
+
? horizontalOrDefault(this.props.horizontal)
|
|
986
|
+
? styles.horizontallyInverted
|
|
987
|
+
: styles.verticallyInverted
|
|
988
|
+
: null;
|
|
969
989
|
const cells = [];
|
|
970
990
|
const stickyIndicesFromProps = new Set(this.props.stickyHeaderIndices);
|
|
971
991
|
const stickyHeaderIndices = [];
|
|
@@ -1309,14 +1329,17 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1309
1329
|
}
|
|
1310
1330
|
|
|
1311
1331
|
_defaultRenderScrollComponent = props => {
|
|
1312
|
-
|
|
1313
|
-
if (!keyEventHandler) {
|
|
1314
|
-
keyEventHandler = this.props.enableSelectionOnKeyPress
|
|
1315
|
-
? this._handleKeyDown
|
|
1316
|
-
: null;
|
|
1317
|
-
}
|
|
1332
|
+
// [TODO(macOS GH#774)
|
|
1318
1333
|
const preferredScrollerStyleDidChangeHandler =
|
|
1319
|
-
this.props.onPreferredScrollerStyleDidChange;
|
|
1334
|
+
this.props.onPreferredScrollerStyleDidChange;
|
|
1335
|
+
const invertedDidChange = this.props.onInvertedDidChange;
|
|
1336
|
+
|
|
1337
|
+
const keyboardNavigationProps = {
|
|
1338
|
+
focusable: true,
|
|
1339
|
+
validKeysDown: ['ArrowUp', 'ArrowDown', 'Home', 'End'],
|
|
1340
|
+
onKeyDown: this._handleKeyDown,
|
|
1341
|
+
};
|
|
1342
|
+
// ]TODO(macOS GH#774)
|
|
1320
1343
|
const onRefresh = props.onRefresh;
|
|
1321
1344
|
if (this._isNestedWithSameOrientation()) {
|
|
1322
1345
|
// $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
|
|
@@ -1331,13 +1354,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1331
1354
|
return (
|
|
1332
1355
|
// $FlowFixMe[prop-missing] Invalid prop usage
|
|
1333
1356
|
<ScrollView
|
|
1334
|
-
{...props}
|
|
1335
1357
|
// [TODO(macOS GH#774)
|
|
1336
|
-
{...(props.enableSelectionOnKeyPress &&
|
|
1337
|
-
|
|
1358
|
+
{...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
|
|
1359
|
+
onInvertedDidChange={invertedDidChange}
|
|
1338
1360
|
onPreferredScrollerStyleDidChange={
|
|
1339
1361
|
preferredScrollerStyleDidChangeHandler
|
|
1340
1362
|
} // TODO(macOS GH#774)]
|
|
1363
|
+
{...props}
|
|
1341
1364
|
refreshControl={
|
|
1342
1365
|
props.refreshControl == null ? (
|
|
1343
1366
|
<RefreshControl
|
|
@@ -1355,12 +1378,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1355
1378
|
return (
|
|
1356
1379
|
// $FlowFixMe Invalid prop usage
|
|
1357
1380
|
<ScrollView
|
|
1358
|
-
|
|
1359
|
-
{...(props.enableSelectionOnKeyPress &&
|
|
1360
|
-
|
|
1381
|
+
// [TODO(macOS GH#774)
|
|
1382
|
+
{...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
|
|
1383
|
+
onInvertedDidChange={invertedDidChange}
|
|
1361
1384
|
onPreferredScrollerStyleDidChange={
|
|
1362
1385
|
preferredScrollerStyleDidChangeHandler
|
|
1363
1386
|
} // TODO(macOS GH#774)]
|
|
1387
|
+
{...props}
|
|
1364
1388
|
/>
|
|
1365
1389
|
);
|
|
1366
1390
|
}
|
|
@@ -1510,98 +1534,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1510
1534
|
};
|
|
1511
1535
|
|
|
1512
1536
|
// [TODO(macOS GH#774)
|
|
1513
|
-
_selectRowAboveIndex = rowIndex => {
|
|
1514
|
-
const rowAbove = rowIndex > 0 ? rowIndex - 1 : rowIndex;
|
|
1515
|
-
this.setState(state => {
|
|
1516
|
-
return {selectedRowIndex: rowAbove};
|
|
1517
|
-
});
|
|
1518
|
-
return rowAbove;
|
|
1519
|
-
};
|
|
1520
|
-
|
|
1521
1537
|
_selectRowAtIndex = rowIndex => {
|
|
1522
|
-
this.
|
|
1523
|
-
|
|
1524
|
-
});
|
|
1525
|
-
return rowIndex;
|
|
1526
|
-
};
|
|
1527
|
-
|
|
1528
|
-
_selectRowBelowIndex = rowIndex => {
|
|
1529
|
-
if (this.props.getItemCount) {
|
|
1530
|
-
const {data} = this.props;
|
|
1531
|
-
const itemCount = this.props.getItemCount(data);
|
|
1532
|
-
const rowBelow = rowIndex < itemCount - 1 ? rowIndex + 1 : rowIndex;
|
|
1533
|
-
this.setState(state => {
|
|
1534
|
-
return {selectedRowIndex: rowBelow};
|
|
1535
|
-
});
|
|
1536
|
-
return rowBelow;
|
|
1537
|
-
} else {
|
|
1538
|
-
return rowIndex;
|
|
1539
|
-
}
|
|
1540
|
-
};
|
|
1541
|
-
|
|
1542
|
-
_handleKeyDown = (event: ScrollEvent) => {
|
|
1543
|
-
if (this.props.onScrollKeyDown) {
|
|
1544
|
-
this.props.onScrollKeyDown(event);
|
|
1545
|
-
} else {
|
|
1546
|
-
if (Platform.OS === 'macos') {
|
|
1547
|
-
// $FlowFixMe Cannot get e.nativeEvent because property nativeEvent is missing in Event
|
|
1548
|
-
const nativeEvent = event.nativeEvent;
|
|
1549
|
-
const key = nativeEvent.key;
|
|
1550
|
-
|
|
1551
|
-
let prevIndex = -1;
|
|
1552
|
-
let newIndex = -1;
|
|
1553
|
-
if ('selectedRowIndex' in this.state) {
|
|
1554
|
-
prevIndex = this.state.selectedRowIndex;
|
|
1555
|
-
}
|
|
1538
|
+
const prevIndex = this.state.selectedRowIndex;
|
|
1539
|
+
const newIndex = rowIndex;
|
|
1540
|
+
this.setState({selectedRowIndex: newIndex});
|
|
1556
1541
|
|
|
1557
|
-
// const {data, getItem} = this.props;
|
|
1558
|
-
if (key === 'UP_ARROW') {
|
|
1559
|
-
newIndex = this._selectRowAboveIndex(prevIndex);
|
|
1560
|
-
this._handleSelectionChange(prevIndex, newIndex);
|
|
1561
|
-
} else if (key === 'DOWN_ARROW') {
|
|
1562
|
-
newIndex = this._selectRowBelowIndex(prevIndex);
|
|
1563
|
-
this._handleSelectionChange(prevIndex, newIndex);
|
|
1564
|
-
} else if (key === 'ENTER') {
|
|
1565
|
-
if (this.props.onSelectionEntered) {
|
|
1566
|
-
const item = this.props.getItem(this.props.data, prevIndex);
|
|
1567
|
-
if (this.props.onSelectionEntered) {
|
|
1568
|
-
this.props.onSelectionEntered(item);
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
} else if (key === 'OPTION_UP') {
|
|
1572
|
-
newIndex = this._selectRowAtIndex(0);
|
|
1573
|
-
this._handleSelectionChange(prevIndex, newIndex);
|
|
1574
|
-
} else if (key === 'OPTION_DOWN') {
|
|
1575
|
-
newIndex = this._selectRowAtIndex(this.state.last);
|
|
1576
|
-
this._handleSelectionChange(prevIndex, newIndex);
|
|
1577
|
-
} else if (key === 'PAGE_UP') {
|
|
1578
|
-
const maxY =
|
|
1579
|
-
event.nativeEvent.contentSize.height -
|
|
1580
|
-
event.nativeEvent.layoutMeasurement.height;
|
|
1581
|
-
const newOffset = Math.min(
|
|
1582
|
-
maxY,
|
|
1583
|
-
nativeEvent.contentOffset.y + -nativeEvent.layoutMeasurement.height,
|
|
1584
|
-
);
|
|
1585
|
-
this.scrollToOffset({animated: true, offset: newOffset});
|
|
1586
|
-
} else if (key === 'PAGE_DOWN') {
|
|
1587
|
-
const maxY =
|
|
1588
|
-
event.nativeEvent.contentSize.height -
|
|
1589
|
-
event.nativeEvent.layoutMeasurement.height;
|
|
1590
|
-
const newOffset = Math.min(
|
|
1591
|
-
maxY,
|
|
1592
|
-
nativeEvent.contentOffset.y + nativeEvent.layoutMeasurement.height,
|
|
1593
|
-
);
|
|
1594
|
-
this.scrollToOffset({animated: true, offset: newOffset});
|
|
1595
|
-
} else if (key === 'HOME') {
|
|
1596
|
-
this.scrollToOffset({animated: true, offset: 0});
|
|
1597
|
-
} else if (key === 'END') {
|
|
1598
|
-
this.scrollToEnd({animated: true});
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
|
-
_handleSelectionChange = (prevIndex, newIndex) => {
|
|
1605
1542
|
this.ensureItemAtIndexIsVisible(newIndex);
|
|
1606
1543
|
if (prevIndex !== newIndex) {
|
|
1607
1544
|
const item = this.props.getItem(this.props.data, newIndex);
|
|
@@ -1613,6 +1550,62 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1613
1550
|
});
|
|
1614
1551
|
}
|
|
1615
1552
|
}
|
|
1553
|
+
|
|
1554
|
+
return newIndex;
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
_selectRowAboveIndex = rowIndex => {
|
|
1558
|
+
const rowAbove = rowIndex > 0 ? rowIndex - 1 : rowIndex;
|
|
1559
|
+
this._selectRowAtIndex(rowAbove);
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
_selectRowBelowIndex = rowIndex => {
|
|
1563
|
+
const rowBelow = rowIndex < this.state.last ? rowIndex + 1 : rowIndex;
|
|
1564
|
+
this._selectRowAtIndex(rowBelow);
|
|
1565
|
+
};
|
|
1566
|
+
|
|
1567
|
+
_handleKeyDown = (event: KeyEvent) => {
|
|
1568
|
+
if (Platform.OS === 'macos') {
|
|
1569
|
+
this.props.onKeyDown?.(event);
|
|
1570
|
+
if (event.defaultPrevented) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
const nativeEvent = event.nativeEvent;
|
|
1575
|
+
const key = nativeEvent.key;
|
|
1576
|
+
|
|
1577
|
+
let selectedIndex = -1;
|
|
1578
|
+
if (this.state.selectedRowIndex >= 0) {
|
|
1579
|
+
selectedIndex = this.state.selectedRowIndex;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
if (key === 'ArrowUp') {
|
|
1583
|
+
if (nativeEvent.altKey) {
|
|
1584
|
+
// Option+Up selects the first element
|
|
1585
|
+
this._selectRowAtIndex(0);
|
|
1586
|
+
} else {
|
|
1587
|
+
this._selectRowAboveIndex(selectedIndex);
|
|
1588
|
+
}
|
|
1589
|
+
} else if (key === 'ArrowDown') {
|
|
1590
|
+
if (nativeEvent.altKey) {
|
|
1591
|
+
// Option+Down selects the last element
|
|
1592
|
+
this._selectRowAtIndex(this.state.last);
|
|
1593
|
+
} else {
|
|
1594
|
+
this._selectRowBelowIndex(selectedIndex);
|
|
1595
|
+
}
|
|
1596
|
+
} else if (key === 'Enter') {
|
|
1597
|
+
if (this.props.onSelectionEntered) {
|
|
1598
|
+
const item = this.props.getItem(this.props.data, selectedIndex);
|
|
1599
|
+
if (this.props.onSelectionEntered) {
|
|
1600
|
+
this.props.onSelectionEntered(item);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
} else if (key === 'Home') {
|
|
1604
|
+
this.scrollToOffset({animated: true, offset: 0});
|
|
1605
|
+
} else if (key === 'End') {
|
|
1606
|
+
this.scrollToEnd({animated: true});
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1616
1609
|
};
|
|
1617
1610
|
// ]TODO(macOS GH#774)
|
|
1618
1611
|
|