react-native-macos 0.66.73 → 0.66.76

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.
@@ -1179,82 +1179,6 @@ class ScrollView extends React.Component<Props, State> {
1179
1179
  }
1180
1180
 
1181
1181
  // [TODO(macOS GH#774)
1182
- _handleKeyDown = (event: ScrollEvent) => {
1183
- if (this.props.onScrollKeyDown) {
1184
- this.props.onScrollKeyDown(event);
1185
- } else {
1186
- if (Platform.OS === 'macos') {
1187
- const nativeEvent = event.nativeEvent;
1188
- const key = nativeEvent.key;
1189
- const kMinScrollOffset = 10;
1190
- if (key === 'PAGE_UP') {
1191
- this._handleScrollByKeyDown(event, {
1192
- x: nativeEvent.contentOffset.x,
1193
- y:
1194
- nativeEvent.contentOffset.y +
1195
- -nativeEvent.layoutMeasurement.height,
1196
- });
1197
- } else if (key === 'PAGE_DOWN') {
1198
- this._handleScrollByKeyDown(event, {
1199
- x: nativeEvent.contentOffset.x,
1200
- y:
1201
- nativeEvent.contentOffset.y +
1202
- nativeEvent.layoutMeasurement.height,
1203
- });
1204
- } else if (key === 'LEFT_ARROW') {
1205
- this._handleScrollByKeyDown(event, {
1206
- x:
1207
- nativeEvent.contentOffset.x +
1208
- -(this.props.horizontalLineScroll !== undefined
1209
- ? this.props.horizontalLineScroll
1210
- : kMinScrollOffset),
1211
- y: nativeEvent.contentOffset.y,
1212
- });
1213
- } else if (key === 'RIGHT_ARROW') {
1214
- this._handleScrollByKeyDown(event, {
1215
- x:
1216
- nativeEvent.contentOffset.x +
1217
- (this.props.horizontalLineScroll !== undefined
1218
- ? this.props.horizontalLineScroll
1219
- : kMinScrollOffset),
1220
- y: nativeEvent.contentOffset.y,
1221
- });
1222
- } else if (key === 'DOWN_ARROW') {
1223
- this._handleScrollByKeyDown(event, {
1224
- x: nativeEvent.contentOffset.x,
1225
- y:
1226
- nativeEvent.contentOffset.y +
1227
- (this.props.verticalLineScroll !== undefined
1228
- ? this.props.verticalLineScroll
1229
- : kMinScrollOffset),
1230
- });
1231
- } else if (key === 'UP_ARROW') {
1232
- this._handleScrollByKeyDown(event, {
1233
- x: nativeEvent.contentOffset.x,
1234
- y:
1235
- nativeEvent.contentOffset.y +
1236
- -(this.props.verticalLineScroll !== undefined
1237
- ? this.props.verticalLineScroll
1238
- : kMinScrollOffset),
1239
- });
1240
- }
1241
- }
1242
- }
1243
- };
1244
-
1245
- _handleScrollByKeyDown = (event: ScrollEvent, newOffset) => {
1246
- const maxX =
1247
- event.nativeEvent.contentSize.width -
1248
- event.nativeEvent.layoutMeasurement.width;
1249
- const maxY =
1250
- event.nativeEvent.contentSize.height -
1251
- event.nativeEvent.layoutMeasurement.height;
1252
- this.scrollTo({
1253
- x: Math.max(0, Math.min(maxX, newOffset.x)),
1254
- y: Math.max(0, Math.min(maxY, newOffset.y)),
1255
- });
1256
- };
1257
-
1258
1182
  _handlePreferredScrollerStyleDidChange = (event: ScrollEvent) => {
1259
1183
  this.setState({contentKey: this.state.contentKey + 1});
1260
1184
  }; // ]TODO(macOS GH#774)
@@ -1807,7 +1731,6 @@ class ScrollView extends React.Component<Props, State> {
1807
1731
  // Override the onContentSizeChange from props, since this event can
1808
1732
  // bubble up from TextInputs
1809
1733
  onContentSizeChange: null,
1810
- onScrollKeyDown: this._handleKeyDown, // TODO(macOS GH#774)
1811
1734
  onPreferredScrollerStyleDidChange: this
1812
1735
  ._handlePreferredScrollerStyleDidChange, // TODO(macOS GH#774)
1813
1736
  onLayout: this._handleLayout,
@@ -76,12 +76,6 @@ type DirectEventProps = $ReadOnly<{|
76
76
  */
77
77
  onPreferredScrollerStyleDidChange?: ?(event: ScrollEvent) => mixed, // TODO(macOS GH#774)
78
78
 
79
- /**
80
- * When `acceptsKeyboardFocus` is true, the system will try to invoke this function
81
- * when the user performs accessibility key down gesture.
82
- */
83
- onScrollKeyDown?: ?(event: ScrollEvent) => mixed, // TODO(macOS GH#774)
84
-
85
79
  /**
86
80
  * Invoked on mount and layout changes with:
87
81
  *
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 66,
15
- patch: 73,
15
+ patch: 76,
16
16
  prerelease: null,
17
17
  };
@@ -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,6 +129,12 @@ 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
139
  * Reverses the direction of scroll. Uses scale transforms of -1.
116
140
  */
@@ -369,6 +393,19 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
369
393
  }
370
394
  }
371
395
 
396
+ // [TODO(macOS GH#750)
397
+ /**
398
+ * Move selection to the specified index
399
+ *
400
+ * @platform macos
401
+ */
402
+ selectRowAtIndex(index: number) {
403
+ if (this._listRef) {
404
+ this._listRef.selectRowAtIndex(index);
405
+ }
406
+ }
407
+ // ]TODO(macOS GH#750)
408
+
372
409
  /**
373
410
  * Provides a handle to the underlying scroll responder.
374
411
  */
@@ -652,7 +689,6 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
652
689
  removeClippedSubviews={removeClippedSubviewsOrDefault(
653
690
  _removeClippedSubviews,
654
691
  )}
655
- accessibilityRole="table" // TODO(macOS GH#774): Inherit NSAccessibilityTable protocols
656
692
  {...this._renderer()}
657
693
  />
658
694
  );
@@ -35,7 +35,7 @@ import type {
35
35
  ViewToken,
36
36
  ViewabilityConfigCallbackPair,
37
37
  } from './ViewabilityHelper';
38
- import type {ScrollEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
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
- * Handles key down events and updates selection based on the key event
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, // TODO(macOS GH#774)
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
  */
@@ -588,10 +606,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
588
606
  const newOffset = Math.min(contentLength, visTop + (frameEnd - visEnd));
589
607
  this.scrollToOffset({offset: newOffset});
590
608
  } else if (frame.offset < visTop) {
591
- const newOffset = Math.max(0, visTop - frame.length);
609
+ const newOffset = Math.min(frame.offset, visTop - frame.length);
592
610
  this.scrollToOffset({offset: newOffset});
593
611
  }
594
612
  }
613
+
614
+ selectRowAtIndex(rowIndex: number) {
615
+ this._selectRowAtIndex(rowIndex);
616
+ }
595
617
  // ]TODO(macOS GH#774)
596
618
 
597
619
  recordInteraction() {
@@ -776,7 +798,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
776
798
  (this.props.initialScrollIndex || 0) +
777
799
  initialNumToRenderOrDefault(this.props.initialNumToRender),
778
800
  ) - 1,
779
- selectedRowIndex: 0, // TODO(macOS GH#774)
801
+ selectedRowIndex: this.props.initialSelectedIndex ?? -1, // TODO(macOS GH#774)
780
802
  };
781
803
 
782
804
  if (this._isNestedWithSameOrientation()) {
@@ -839,7 +861,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
839
861
  ),
840
862
  last: Math.max(0, Math.min(prevState.last, getItemCount(data) - 1)),
841
863
  selectedRowIndex: Math.max(
842
- 0,
864
+ -1, // Used to indicate no row is selected
843
865
  Math.min(prevState.selectedRowIndex, getItemCount(data)),
844
866
  ), // TODO(macOS GH#774)
845
867
  };
@@ -882,7 +904,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
882
904
  index={ii}
883
905
  inversionStyle={inversionStyle}
884
906
  item={item}
885
- isSelected={this.state.selectedRowIndex === ii ? true : false} // TODO(macOS GH#774)
907
+ // [TODO(macOS GH#774)
908
+ isSelected={
909
+ this.props.enableSelectionOnKeyPress &&
910
+ this.state.selectedRowIndex === ii
911
+ ? true
912
+ : false
913
+ } // TODO(macOS GH#774)]
886
914
  key={key}
887
915
  prevCellKey={prevCellKey}
888
916
  onUpdateSeparators={this._onUpdateSeparators}
@@ -1300,14 +1328,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1300
1328
  }
1301
1329
 
1302
1330
  _defaultRenderScrollComponent = props => {
1303
- let keyEventHandler = this.props.onScrollKeyDown; // [TODO(macOS GH#774)
1304
- if (!keyEventHandler) {
1305
- keyEventHandler = this.props.enableSelectionOnKeyPress
1306
- ? this._handleKeyDown
1307
- : null;
1308
- }
1331
+ // [TODO(macOS GH#774)
1309
1332
  const preferredScrollerStyleDidChangeHandler = this.props
1310
- .onPreferredScrollerStyleDidChange; // ]TODO(macOS GH#774)
1333
+ .onPreferredScrollerStyleDidChange;
1334
+
1335
+ const keyboardNavigationProps = {
1336
+ focusable: true,
1337
+ validKeysDown: ['ArrowUp', 'ArrowDown', 'Home', 'End'],
1338
+ onKeyDown: this._handleKeyDown,
1339
+ };
1340
+ // ]TODO(macOS GH#774)
1311
1341
  const onRefresh = props.onRefresh;
1312
1342
  if (this._isNestedWithSameOrientation()) {
1313
1343
  // $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
@@ -1322,11 +1352,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1322
1352
  return (
1323
1353
  // $FlowFixMe[prop-missing] Invalid prop usage
1324
1354
  <ScrollView
1325
- {...props}
1326
- onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1355
+ // [TODO(macOS GH#774)
1356
+ {...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
1327
1357
  onPreferredScrollerStyleDidChange={
1328
1358
  preferredScrollerStyleDidChangeHandler
1329
- } // TODO(macOS GH#774)
1359
+ } // TODO(macOS GH#774)]
1360
+ {...props}
1330
1361
  refreshControl={
1331
1362
  props.refreshControl == null ? (
1332
1363
  <RefreshControl
@@ -1344,12 +1375,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1344
1375
  return (
1345
1376
  // $FlowFixMe Invalid prop usage
1346
1377
  <ScrollView
1347
- {...props}
1348
- onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1378
+ // [TODO(macOS GH#774)
1379
+ {...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
1349
1380
  onPreferredScrollerStyleDidChange={
1350
- // TODO(macOS GH#774)
1351
- preferredScrollerStyleDidChangeHandler // TODO(macOS GH#774)
1352
- }
1381
+ preferredScrollerStyleDidChangeHandler
1382
+ } // TODO(macOS GH#774)]
1383
+ {...props}
1353
1384
  />
1354
1385
  );
1355
1386
  }
@@ -1499,80 +1530,76 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1499
1530
  };
1500
1531
 
1501
1532
  // [TODO(macOS GH#774)
1533
+ _selectRowAtIndex = rowIndex => {
1534
+ const prevIndex = this.state.selectedRowIndex;
1535
+ const newIndex = rowIndex;
1536
+ this.setState({selectedRowIndex: newIndex});
1537
+
1538
+ this.ensureItemAtIndexIsVisible(newIndex);
1539
+ if (prevIndex !== newIndex) {
1540
+ const item = this.props.getItem(this.props.data, newIndex);
1541
+ if (this.props.onSelectionChanged) {
1542
+ this.props.onSelectionChanged({
1543
+ previousSelection: prevIndex,
1544
+ newSelection: newIndex,
1545
+ item: item,
1546
+ });
1547
+ }
1548
+ }
1549
+
1550
+ return newIndex;
1551
+ };
1552
+
1502
1553
  _selectRowAboveIndex = rowIndex => {
1503
1554
  const rowAbove = rowIndex > 0 ? rowIndex - 1 : rowIndex;
1504
- this.setState(state => {
1505
- return {selectedRowIndex: rowAbove};
1506
- });
1507
- return rowAbove;
1555
+ this._selectRowAtIndex(rowAbove);
1508
1556
  };
1509
1557
 
1510
1558
  _selectRowBelowIndex = rowIndex => {
1511
- if (this.props.getItemCount) {
1512
- const {data} = this.props;
1513
- const itemCount = this.props.getItemCount(data);
1514
- const rowBelow = rowIndex < itemCount - 1 ? rowIndex + 1 : rowIndex;
1515
- this.setState(state => {
1516
- return {selectedRowIndex: rowBelow};
1517
- });
1518
- return rowBelow;
1519
- } else {
1520
- return rowIndex;
1521
- }
1559
+ const rowBelow = rowIndex < this.state.last ? rowIndex + 1 : rowIndex;
1560
+ this._selectRowAtIndex(rowBelow);
1522
1561
  };
1523
1562
 
1524
- _handleKeyDown = (e: ScrollEvent) => {
1525
- if (this.props.onScrollKeyDown) {
1526
- this.props.onScrollKeyDown(e);
1527
- } else {
1528
- if (Platform.OS === 'macos') {
1529
- // $FlowFixMe Cannot get e.nativeEvent because property nativeEvent is missing in Event
1530
- const event = e.nativeEvent;
1531
- const key = event.key;
1532
-
1533
- let prevIndex = -1;
1534
- let newIndex = -1;
1535
- if ('selectedRowIndex' in this.state) {
1536
- prevIndex = this.state.selectedRowIndex;
1537
- }
1563
+ _handleKeyDown = (event: KeyEvent) => {
1564
+ if (Platform.OS === 'macos') {
1565
+ this.props.onKeyDown?.(event);
1566
+ if (event.defaultPrevented) {
1567
+ return;
1568
+ }
1538
1569
 
1539
- const {data, getItem} = this.props;
1540
- if (key === 'DOWN_ARROW') {
1541
- newIndex = this._selectRowBelowIndex(prevIndex);
1542
- this.ensureItemAtIndexIsVisible(newIndex);
1543
-
1544
- if (prevIndex !== newIndex) {
1545
- const item = getItem(data, newIndex);
1546
- if (this.props.onSelectionChanged) {
1547
- this.props.onSelectionChanged({
1548
- previousSelection: prevIndex,
1549
- newSelection: newIndex,
1550
- item: item,
1551
- });
1552
- }
1553
- }
1554
- } else if (key === 'UP_ARROW') {
1555
- newIndex = this._selectRowAboveIndex(prevIndex);
1556
- this.ensureItemAtIndexIsVisible(newIndex);
1557
-
1558
- if (prevIndex !== newIndex) {
1559
- const item = getItem(data, newIndex);
1560
- if (this.props.onSelectionChanged) {
1561
- this.props.onSelectionChanged({
1562
- previousSelection: prevIndex,
1563
- newSelection: newIndex,
1564
- item: item,
1565
- });
1566
- }
1567
- }
1568
- } else if (key === 'ENTER') {
1570
+ const nativeEvent = event.nativeEvent;
1571
+ const key = nativeEvent.key;
1572
+
1573
+ let selectedIndex = -1;
1574
+ if (this.state.selectedRowIndex >= 0) {
1575
+ selectedIndex = this.state.selectedRowIndex;
1576
+ }
1577
+
1578
+ if (key === 'ArrowUp') {
1579
+ if (nativeEvent.altKey) {
1580
+ // Option+Up selects the first element
1581
+ this._selectRowAtIndex(0);
1582
+ } else {
1583
+ this._selectRowAboveIndex(selectedIndex);
1584
+ }
1585
+ } else if (key === 'ArrowDown') {
1586
+ if (nativeEvent.altKey) {
1587
+ // Option+Down selects the last element
1588
+ this._selectRowAtIndex(this.state.last);
1589
+ } else {
1590
+ this._selectRowBelowIndex(selectedIndex);
1591
+ }
1592
+ } else if (key === 'Enter') {
1593
+ if (this.props.onSelectionEntered) {
1594
+ const item = this.props.getItem(this.props.data, selectedIndex);
1569
1595
  if (this.props.onSelectionEntered) {
1570
- const item = getItem(data, prevIndex);
1571
- if (this.props.onSelectionEntered) {
1572
- this.props.onSelectionEntered(item);
1573
- }
1596
+ this.props.onSelectionEntered(item);
1574
1597
  }
1575
1598
  }
1599
+ } else if (key === 'Home') {
1600
+ this.scrollToOffset({animated: true, offset: 0});
1601
+ } else if (key === 'End') {
1602
+ this.scrollToEnd({animated: true});
1576
1603
  }
1577
1604
  }
1578
1605
  };
@@ -2182,6 +2209,7 @@ class CellRenderer extends React.Component<
2182
2209
  return React.createElement(ListItemComponent, {
2183
2210
  item,
2184
2211
  index,
2212
+ isSelected,
2185
2213
  separators: this._separators,
2186
2214
  });
2187
2215
  }
@@ -2258,6 +2286,7 @@ class CellRenderer extends React.Component<
2258
2286
  {itemSeparator}
2259
2287
  </CellRendererComponent>
2260
2288
  );
2289
+ // TODO(macOS GH#774)]
2261
2290
 
2262
2291
  return (
2263
2292
  <VirtualizedListCellContextProvider cellKey={this.props.cellKey}>
@@ -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 {ScrollEvent} from '../Types/CoreEventTypes'; // TODO(macOS GH#774)
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: ScrollEvent) => {
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 === 'DOWN_ARROW') {
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 === 'UP_ARROW') {
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 === 'ENTER') {
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);
@@ -133,7 +133,6 @@ export type ScrollEvent = SyntheticEvent<
133
133
  |}>,
134
134
  zoomScale?: number,
135
135
  responderIgnoreScroll?: boolean,
136
- key?: string, // TODO(macOS GH#774)
137
136
  preferredScrollerStyle?: string, // TODO(macOS GH#774)
138
137
  |}>,
139
138
  >;
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(66),
26
- RCTVersionPatch: @(73),
26
+ RCTVersionPatch: @(76),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -27,6 +27,10 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
27
27
 
28
28
  - (BOOL)becomeFirstResponder;
29
29
  - (BOOL)resignFirstResponder;
30
+
31
+ #if TARGET_OS_OSX
32
+ - (BOOL)handleKeyboardEvent:(NSEvent *)event;
33
+ #endif
30
34
  // ]TODO(OSS Candidate ISS#2710739)
31
35
 
32
36
  /**
@@ -1613,177 +1613,38 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
1613
1613
  #pragma mark - Keyboard Events
1614
1614
 
1615
1615
  #if TARGET_OS_OSX
1616
- NSString* const leftArrowPressKey = @"ArrowLeft";
1617
- NSString* const rightArrowPressKey = @"ArrowRight";
1618
- NSString* const upArrowPressKey = @"ArrowUp";
1619
- NSString* const downArrowPressKey = @"ArrowDown";
1620
-
1621
- - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event downPress:(BOOL)downPress {
1622
- // modifiers
1623
- BOOL capsLockKey = NO;
1624
- BOOL shiftKey = NO;
1625
- BOOL controlKey = NO;
1626
- BOOL optionKey = NO;
1627
- BOOL commandKey = NO;
1628
- BOOL numericPadKey = NO;
1629
- BOOL helpKey = NO;
1630
- BOOL functionKey = NO;
1631
- // commonly used key short-cuts
1632
- BOOL leftArrowKey = NO;
1633
- BOOL rightArrowKey = NO;
1634
- BOOL upArrowKey = NO;
1635
- BOOL downArrowKey = NO;
1636
- BOOL tabKeyPressed = NO;
1637
- BOOL escapeKeyPressed = NO;
1638
- NSString *key = event.charactersIgnoringModifiers;
1639
- if ([key length] == 0) {
1640
- return nil;
1641
- }
1642
- unichar const code = [key characterAtIndex:0];
1643
-
1644
- // detect arrow key presses
1645
- if (code == NSLeftArrowFunctionKey) {
1646
- leftArrowKey = YES;
1647
- } else if (code == NSRightArrowFunctionKey) {
1648
- rightArrowKey = YES;
1649
- } else if (code == NSUpArrowFunctionKey) {
1650
- upArrowKey = YES;
1651
- } else if (code == NSDownArrowFunctionKey) {
1652
- downArrowKey = YES;
1653
- }
1654
-
1655
- // detect special key presses via the key code
1656
- switch (event.keyCode) {
1657
- case 48: // Tab
1658
- tabKeyPressed = YES;
1659
- break;
1660
- case 53: // Escape
1661
- escapeKeyPressed = YES;
1662
- break;
1663
- default:
1664
- break;
1616
+ - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
1617
+ BOOL keyDown = event.type == NSEventTypeKeyDown;
1618
+ NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
1619
+ NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
1620
+
1621
+ // Only post events for keys we care about
1622
+ if (![validKeys containsObject:key]) {
1623
+ return nil;
1665
1624
  }
1666
1625
 
1667
- // detect modifier flags
1668
- if (event.modifierFlags & NSEventModifierFlagCapsLock) {
1669
- capsLockKey = YES;
1670
- } else if (event.modifierFlags & NSEventModifierFlagShift) {
1671
- shiftKey = YES;
1672
- } else if (event.modifierFlags & NSEventModifierFlagControl) {
1673
- controlKey = YES;
1674
- } else if (event.modifierFlags & NSEventModifierFlagOption) {
1675
- optionKey = YES;
1676
- } else if (event.modifierFlags & NSEventModifierFlagCommand) {
1677
- commandKey = YES;
1678
- } else if (event.modifierFlags & NSEventModifierFlagNumericPad) {
1679
- numericPadKey = YES;
1680
- } else if (event.modifierFlags & NSEventModifierFlagHelp) {
1681
- helpKey = YES;
1682
- } else if (event.modifierFlags & NSEventModifierFlagFunction) {
1683
- functionKey = YES;
1684
- }
1685
-
1686
- RCTViewKeyboardEvent *keyboardEvent = nil;
1687
- // only post events for keys we care about
1688
- if (downPress) {
1689
- NSString *keyToReturn = [self keyIsValid:key left:leftArrowKey right:rightArrowKey up:upArrowKey down:downArrowKey tabKey:tabKeyPressed escapeKey:escapeKeyPressed validKeys:[self validKeysDown]];
1690
- if (keyToReturn != nil) {
1691
- keyboardEvent = [RCTViewKeyboardEvent keyDownEventWithReactTag:self.reactTag
1692
- capsLockKey:capsLockKey
1693
- shiftKey:shiftKey
1694
- ctrlKey:controlKey
1695
- altKey:optionKey
1696
- metaKey:commandKey
1697
- numericPadKey:numericPadKey
1698
- helpKey:helpKey
1699
- functionKey:functionKey
1700
- leftArrowKey:leftArrowKey
1701
- rightArrowKey:rightArrowKey
1702
- upArrowKey:upArrowKey
1703
- downArrowKey:downArrowKey
1704
- key:keyToReturn];
1705
- }
1706
- } else {
1707
- NSString *keyToReturn = [self keyIsValid:key left:leftArrowKey right:rightArrowKey up:upArrowKey down:downArrowKey tabKey:tabKeyPressed escapeKey:escapeKeyPressed validKeys:[self validKeysUp]];
1708
- if (keyToReturn != nil) {
1709
- keyboardEvent = [RCTViewKeyboardEvent keyUpEventWithReactTag:self.reactTag
1710
- capsLockKey:capsLockKey
1711
- shiftKey:shiftKey
1712
- ctrlKey:controlKey
1713
- altKey:optionKey
1714
- metaKey:commandKey
1715
- numericPadKey:numericPadKey
1716
- helpKey:helpKey
1717
- functionKey:functionKey
1718
- leftArrowKey:leftArrowKey
1719
- rightArrowKey:rightArrowKey
1720
- upArrowKey:upArrowKey
1721
- downArrowKey:downArrowKey
1722
- key:keyToReturn];
1626
+ return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
1627
+ }
1628
+
1629
+ - (BOOL)handleKeyboardEvent:(NSEvent *)event {
1630
+ if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
1631
+ RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event];
1632
+ if (keyboardEvent) {
1633
+ [_eventDispatcher sendEvent:keyboardEvent];
1634
+ return YES;
1723
1635
  }
1724
1636
  }
1725
- return keyboardEvent;
1726
- }
1727
-
1728
- // check if the user typed key matches a key we need to send an event for
1729
- // translate key codes over to JS compatible keys
1730
- - (NSString*)keyIsValid:(NSString*)key left:(BOOL)leftArrowPressed right:(BOOL)rightArrowPressed up:(BOOL)upArrowPressed down:(BOOL)downArrowPressed tabKey:(BOOL)tabKeyPressed escapeKey:(BOOL)escapeKeyPressed validKeys:(NSArray<NSString*>*)validKeys {
1731
- NSString *keyToReturn = key;
1732
-
1733
- // Allow the flexibility of defining special keys in multiple ways
1734
- BOOL enterKeyValidityCheck = [key isEqualToString:@"\r"] && ([validKeys containsObject:@"Enter"] || [validKeys containsObject:@"\r"]);
1735
- BOOL tabKeyValidityCheck = tabKeyPressed && ([validKeys containsObject:@"Tab"]); // tab has to be checked via a key code so we can't just use the key itself here
1736
- BOOL escapeKeyValidityCheck = escapeKeyPressed && ([validKeys containsObject:@"Esc"] || [validKeys containsObject:@"Escape"]); // escape has to be checked via a key code so we can't just use the key itself here
1737
- BOOL leftArrowValidityCheck = [validKeys containsObject:leftArrowPressKey] && leftArrowPressed;
1738
- BOOL rightArrowValidityCheck = [validKeys containsObject:rightArrowPressKey] && rightArrowPressed;
1739
- BOOL upArrowValidityCheck = [validKeys containsObject:upArrowPressKey] && upArrowPressed;
1740
- BOOL downArrowValidityCheck = [validKeys containsObject:downArrowPressKey] && downArrowPressed;
1741
-
1742
- if (tabKeyValidityCheck) {
1743
- keyToReturn = @"Tab";
1744
- } else if (escapeKeyValidityCheck) {
1745
- keyToReturn = @"Escape";
1746
- } else if (enterKeyValidityCheck) {
1747
- keyToReturn = @"Enter";
1748
- } else if (leftArrowValidityCheck) {
1749
- keyToReturn = leftArrowPressKey;
1750
- } else if (rightArrowValidityCheck) {
1751
- keyToReturn = rightArrowPressKey;
1752
- } else if (upArrowValidityCheck) {
1753
- keyToReturn = upArrowPressKey;
1754
- } else if (downArrowValidityCheck) {
1755
- keyToReturn = downArrowPressKey;
1756
- } else if (![validKeys containsObject:key]) {
1757
- keyToReturn = nil;
1758
- }
1759
-
1760
- return keyToReturn;
1637
+ return NO;
1761
1638
  }
1762
1639
 
1763
1640
  - (void)keyDown:(NSEvent *)event {
1764
- if (self.onKeyDown == nil) {
1765
- [super keyDown:event];
1766
- return;
1767
- }
1768
-
1769
- RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event downPress:YES];
1770
- if (keyboardEvent != nil) {
1771
- [_eventDispatcher sendEvent:keyboardEvent];
1772
- } else {
1641
+ if (![self handleKeyboardEvent:event]) {
1773
1642
  [super keyDown:event];
1774
1643
  }
1775
1644
  }
1776
1645
 
1777
1646
  - (void)keyUp:(NSEvent *)event {
1778
- if (self.onKeyUp == nil) {
1779
- [super keyUp:event];
1780
- return;
1781
- }
1782
-
1783
- RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event downPress:NO];
1784
- if (keyboardEvent != nil) {
1785
- [_eventDispatcher sendEvent:keyboardEvent];
1786
- } else {
1647
+ if (![self handleKeyboardEvent:event]) {
1787
1648
  [super keyUp:event];
1788
1649
  }
1789
1650
  }
@@ -7,33 +7,11 @@
7
7
  #import <React/RCTComponentEvent.h>
8
8
 
9
9
  @interface RCTViewKeyboardEvent : RCTComponentEvent
10
- + (instancetype)keyDownEventWithReactTag:(NSNumber *)reactTag
11
- capsLockKey:(BOOL)capsLockKey
12
- shiftKey:(BOOL)shiftKey
13
- ctrlKey:(BOOL)controlKey
14
- altKey:(BOOL)optionKey
15
- metaKey:(BOOL)commandKey
16
- numericPadKey:(BOOL)numericPadKey
17
- helpKey:(BOOL)helpKey
18
- functionKey:(BOOL)functionKey
19
- leftArrowKey:(BOOL)leftArrowKey
20
- rightArrowKey:(BOOL)rightArrowKey
21
- upArrowKey:(BOOL)upArrowKey
22
- downArrowKey:(BOOL)downArrowKey
23
- key:(NSString *)key;
24
10
 
25
- + (instancetype)keyUpEventWithReactTag:(NSNumber *)reactTag
26
- capsLockKey:(BOOL)capsLockKey
27
- shiftKey:(BOOL)shiftKey
28
- ctrlKey:(BOOL)controlKey
29
- altKey:(BOOL)optionKey
30
- metaKey:(BOOL)commandKey
31
- numericPadKey:(BOOL)numericPadKey
32
- helpKey:(BOOL)helpKey
33
- functionKey:(BOOL)functionKey
34
- leftArrowKey:(BOOL)leftArrowKey
35
- rightArrowKey:(BOOL)rightArrowKey
36
- upArrowKey:(BOOL)upArrowKey
37
- downArrowKey:(BOOL)downArrowKey
38
- key:(NSString *)key;
11
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
12
+ + (NSDictionary *)bodyFromEvent:(NSEvent *)event;
13
+ + (NSString *)keyFromEvent:(NSEvent *)event;
14
+ + (instancetype)keyEventFromEvent:(NSEvent *)event reactTag:(NSNumber *)reactTag;
15
+ #endif // TODO(macOS GH#774)
16
+
39
17
  @end
@@ -9,69 +9,74 @@
9
9
  #import <React/RCTAssert.h>
10
10
 
11
11
  @implementation RCTViewKeyboardEvent
12
- // Keyboard mappings are aligned cross-platform as much as possible as per this doc https://github.com/microsoft/react-native-windows/blob/master/vnext/proposals/active/keyboard-reconcile-desktop.md
13
- + (instancetype)keyDownEventWithReactTag:(NSNumber *)reactTag
14
- capsLockKey:(BOOL)capsLockKey
15
- shiftKey:(BOOL)shiftKey
16
- ctrlKey:(BOOL)controlKey
17
- altKey:(BOOL)optionKey
18
- metaKey:(BOOL)commandKey
19
- numericPadKey:(BOOL)numericPadKey
20
- helpKey:(BOOL)helpKey
21
- functionKey:(BOOL)functionKey
22
- leftArrowKey:(BOOL)leftArrowKey
23
- rightArrowKey:(BOOL)rightArrowKey
24
- upArrowKey:(BOOL)upArrowKey
25
- downArrowKey:(BOOL)downArrowKey
26
- key:(NSString *)key {
27
- RCTViewKeyboardEvent *event = [[self alloc] initWithName:@"keyDown"
28
- viewTag:reactTag
29
- body:@{ @"capsLockKey" : @(capsLockKey),
30
- @"shiftKey" : @(shiftKey),
31
- @"ctrlKey" : @(controlKey),
32
- @"altKey" : @(optionKey),
33
- @"metaKey" : @(commandKey),
34
- @"numericPadKey" : @(numericPadKey),
35
- @"helpKey" : @(helpKey),
36
- @"functionKey" : @(functionKey),
37
- @"ArrowLeft" : @(leftArrowKey),
38
- @"ArrowRight" : @(rightArrowKey),
39
- @"ArrowUp" : @(upArrowKey),
40
- @"ArrowDown" : @(downArrowKey),
41
- @"key" : key }];
42
- return event;
12
+
13
+ #if TARGET_OS_OSX // TODO(macOS GH#774)
14
+ + (NSDictionary *)bodyFromEvent:(NSEvent *)event
15
+ {
16
+ NSString *key = [self keyFromEvent:event];
17
+ NSEventModifierFlags modifierFlags = event.modifierFlags;
18
+
19
+ return @{
20
+ @"key" : key,
21
+ @"capsLockKey" : (modifierFlags & NSEventModifierFlagCapsLock) ? @YES : @NO,
22
+ @"shiftKey" : (modifierFlags & NSEventModifierFlagShift) ? @YES : @NO,
23
+ @"ctrlKey" : (modifierFlags & NSEventModifierFlagControl) ? @YES : @NO,
24
+ @"altKey" : (modifierFlags & NSEventModifierFlagOption) ? @YES : @NO,
25
+ @"metaKey" : (modifierFlags & NSEventModifierFlagCommand) ? @YES : @NO,
26
+ @"numericPadKey" : (modifierFlags & NSEventModifierFlagNumericPad) ? @YES : @NO,
27
+ @"helpKey" : (modifierFlags & NSEventModifierFlagHelp) ? @YES : @NO,
28
+ @"functionKey" : (modifierFlags & NSEventModifierFlagFunction) ? @YES : @NO,
29
+ };
43
30
  }
44
31
 
45
- +(instancetype)keyUpEventWithReactTag:(NSNumber *)reactTag
46
- capsLockKey:(BOOL)capsLockKey
47
- shiftKey:(BOOL)shiftKey
48
- ctrlKey:(BOOL)controlKey
49
- altKey:(BOOL)optionKey
50
- metaKey:(BOOL)commandKey
51
- numericPadKey:(BOOL)numericPadKey
52
- helpKey:(BOOL)helpKey
53
- functionKey:(BOOL)functionKey
54
- leftArrowKey:(BOOL)leftArrowKey
55
- rightArrowKey:(BOOL)rightArrowKey
56
- upArrowKey:(BOOL)upArrowKey
57
- downArrowKey:(BOOL)downArrowKey
58
- key:(NSString *)key {
59
- RCTViewKeyboardEvent *event = [[self alloc] initWithName:@"keyUp"
60
- viewTag:reactTag
61
- body:@{ @"capsLockKey" : @(capsLockKey),
62
- @"shiftKey" : @(shiftKey),
63
- @"ctrlKey" : @(controlKey),
64
- @"altKey" : @(optionKey),
65
- @"metaKey" : @(commandKey),
66
- @"numericPadKey" : @(numericPadKey),
67
- @"helpKey" : @(helpKey),
68
- @"functionKey" : @(functionKey),
69
- @"ArrowLeft" : @(leftArrowKey),
70
- @"ArrowRight" : @(rightArrowKey),
71
- @"ArrowUp" : @(upArrowKey),
72
- @"ArrowDown" : @(downArrowKey),
73
- @"key" : key }];
74
- return event;
32
+ + (NSString *)keyFromEvent:(NSEvent *)event
33
+ {
34
+ NSString *key = event.charactersIgnoringModifiers;
35
+ unichar const code = key.length > 0 ? [key characterAtIndex:0] : 0;
36
+
37
+ if (event.keyCode == 48) {
38
+ return @"Tab";
39
+ } else if (event.keyCode == 53) {
40
+ return @"Escape";
41
+ } else if (code == NSEnterCharacter || code == NSNewlineCharacter || code == NSCarriageReturnCharacter) {
42
+ return @"Enter";
43
+ } else if (code == NSLeftArrowFunctionKey) {
44
+ return @"ArrowLeft";
45
+ } else if (code == NSRightArrowFunctionKey) {
46
+ return @"ArrowRight";
47
+ } else if (code == NSUpArrowFunctionKey) {
48
+ return @"ArrowUp";
49
+ } else if (code == NSDownArrowFunctionKey) {
50
+ return @"ArrowDown";
51
+ } else if (code == NSBackspaceCharacter || code == NSDeleteCharacter) {
52
+ return @"Backspace";
53
+ } else if (code == NSDeleteFunctionKey) {
54
+ return @"Delete";
55
+ } else if (code == NSHomeFunctionKey) {
56
+ return @"Home";
57
+ } else if (code == NSEndFunctionKey) {
58
+ return @"End";
59
+ } else if (code == NSPageUpFunctionKey) {
60
+ return @"PageUp";
61
+ } else if (code == NSPageDownFunctionKey) {
62
+ return @"PageDown";
63
+ }
64
+
65
+ return key;
66
+ }
67
+
68
+ // Keyboard mappings are aligned cross-platform as much as possible as per this doc https://github.com/microsoft/react-native-windows/blob/master/vnext/proposals/active/keyboard-reconcile-desktop.md
69
+ + (instancetype)keyEventFromEvent:(NSEvent *)event reactTag:(NSNumber *)reactTag
70
+ {
71
+ // Ignore "dead keys" (key press that waits for another key to make a character)
72
+ if (!event.charactersIgnoringModifiers.length) {
73
+ return nil;
74
+ }
75
+
76
+ return [[self alloc] initWithName:(event.type == NSEventTypeKeyDown ? @"keyDown" : @"keyUp")
77
+ viewTag:reactTag
78
+ body:[self bodyFromEvent:event]];
75
79
  }
80
+ #endif // TODO(macOS GH#774)
76
81
 
77
82
  @end
@@ -486,18 +486,8 @@ RCT_EXPORT_VIEW_PROPERTY(onDragLeave, RCTDirectEventBlock)
486
486
  RCT_EXPORT_VIEW_PROPERTY(onDrop, RCTDirectEventBlock)
487
487
  RCT_EXPORT_VIEW_PROPERTY(onKeyDown, RCTDirectEventBlock) // macOS keyboard events
488
488
  RCT_EXPORT_VIEW_PROPERTY(onKeyUp, RCTDirectEventBlock) // macOS keyboard events
489
- RCT_CUSTOM_VIEW_PROPERTY(validKeysDown, NSArray<NSString*>, RCTView)
490
- {
491
- if ([view respondsToSelector:@selector(setValidKeysDown:)]) {
492
- view.validKeysDown = [RCTConvert NSArray:json];
493
- }
494
- }
495
- RCT_CUSTOM_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>, RCTView)
496
- {
497
- if ([view respondsToSelector:@selector(setValidKeysUp:)]) {
498
- view.validKeysUp = [RCTConvert NSArray:json];
499
- }
500
- }
489
+ RCT_EXPORT_VIEW_PROPERTY(validKeysDown, NSArray<NSString*>)
490
+ RCT_EXPORT_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>)
501
491
  #endif // ]TODO(macOS GH#774)
502
492
  #if TARGET_OS_OSX // [TODO(macOS GH#768)
503
493
  RCT_CUSTOM_VIEW_PROPERTY(nextKeyViewTag, NSNumber, RCTView)
@@ -64,7 +64,6 @@
64
64
  @property (nonatomic, copy) RCTDirectEventBlock onScrollEndDrag;
65
65
  @property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollBegin;
66
66
  @property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollEnd;
67
- @property (nonatomic, copy) RCTDirectEventBlock onScrollKeyDown; // TODO(macOS GH#774)
68
67
  @property (nonatomic, copy) RCTDirectEventBlock onPreferredScrollerStyleDidChange; // TODO(macOS GH#774)
69
68
 
70
69
  - (void)flashScrollIndicators; // TODO(macOS GH#774)
@@ -22,6 +22,8 @@
22
22
 
23
23
  #if !TARGET_OS_OSX // TODO(macOS GH#774)
24
24
  #import "RCTRefreshControl.h"
25
+ #else
26
+ #import "RCTViewKeyboardEvent.h"
25
27
  #endif // TODO(macOS GH#774)
26
28
 
27
29
  /**
@@ -1183,59 +1185,58 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1183
1185
  }];
1184
1186
  }
1185
1187
 
1186
- #if TARGET_OS_OSX // [TODO(macOS GH#774)
1187
-
1188
- - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode
1189
- {
1190
- switch (keyCode)
1191
- {
1192
- case 36:
1193
- return @"ENTER";
1194
-
1195
- case 116:
1196
- return @"PAGE_UP";
1197
-
1198
- case 121:
1199
- return @"PAGE_DOWN";
1200
-
1201
- case 123:
1202
- return @"LEFT_ARROW";
1203
-
1204
- case 124:
1205
- return @"RIGHT_ARROW";
1206
-
1207
- case 125:
1208
- return @"DOWN_ARROW";
1188
+ // [TODO(macOS GH#774)
1189
+ #pragma mark - Keyboard Events
1209
1190
 
1210
- case 126:
1211
- return @"UP_ARROW";
1212
- }
1213
- return @"";
1214
- }
1215
-
1216
- - (void)keyDown:(UIEvent*)theEvent
1217
- {
1218
- // Don't emit a scroll event if tab was pressed while the scrollview is first responder
1219
- if (self == [[self window] firstResponder] &&
1220
- theEvent.keyCode != 48) {
1221
- NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode];
1222
- RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1223
- } else {
1224
- [super keyDown:theEvent];
1225
-
1226
- // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1227
- // automatically scroll to make the view visible to make it navigable via keyboard.
1228
- if ([theEvent keyCode] == 48) { //tab key
1229
- id firstResponder = [[self window] firstResponder];
1230
- if ([firstResponder isKindOfClass:[NSView class]] &&
1231
- [firstResponder isDescendantOf:[_scrollView documentView]]) {
1232
- NSView *view = (NSView*)firstResponder;
1233
- NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1234
- [view convertRect:view.frame toView:_scrollView.documentView];
1235
- [[_scrollView documentView] scrollRectToVisible:visibleRect];
1236
- }
1237
- }
1238
- }
1191
+ #if TARGET_OS_OSX
1192
+ - (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
1193
+ BOOL keyDown = event.type == NSEventTypeKeyDown;
1194
+ NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
1195
+ NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
1196
+
1197
+ // Only post events for keys we care about
1198
+ if (![validKeys containsObject:key]) {
1199
+ return nil;
1200
+ }
1201
+
1202
+ return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
1203
+ }
1204
+
1205
+ - (BOOL)handleKeyboardEvent:(NSEvent *)event {
1206
+ if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
1207
+ RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event];
1208
+ if (keyboardEvent) {
1209
+ [_eventDispatcher sendEvent:keyboardEvent];
1210
+ return YES;
1211
+ }
1212
+ }
1213
+ return NO;
1214
+ }
1215
+
1216
+ - (void)keyDown:(NSEvent *)event {
1217
+ if (![self handleKeyboardEvent:event]) {
1218
+ [super keyDown:event];
1219
+
1220
+ // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1221
+ // automatically scroll to make the view visible to make it navigable via keyboard.
1222
+ NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
1223
+ if ([key isEqualToString:@"Tab"]) {
1224
+ id firstResponder = [[self window] firstResponder];
1225
+ if ([firstResponder isKindOfClass:[NSView class]] &&
1226
+ [firstResponder isDescendantOf:[_scrollView documentView]]) {
1227
+ NSView *view = (NSView*)firstResponder;
1228
+ NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1229
+ [view convertRect:view.frame toView:_scrollView.documentView];
1230
+ [[_scrollView documentView] scrollRectToVisible:visibleRect];
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+
1236
+ - (void)keyUp:(NSEvent *)event {
1237
+ if (![self handleKeyboardEvent:event]) {
1238
+ [super keyUp:event];
1239
+ }
1239
1240
  }
1240
1241
 
1241
1242
  static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
@@ -1250,7 +1251,8 @@ static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
1250
1251
  - (void)preferredScrollerStyleDidChange:(__unused NSNotification *)notification {
1251
1252
  RCT_SEND_SCROLL_EVENT(onPreferredScrollerStyleDidChange, (@{ @"preferredScrollerStyle": RCTStringForScrollerStyle([NSScroller preferredScrollerStyle])}));
1252
1253
  }
1253
- #endif // ]TODO(macOS GH#774)
1254
+ #endif
1255
+ // ]TODO(macOS GH#774)
1254
1256
 
1255
1257
  // Note: setting several properties of UIScrollView has the effect of
1256
1258
  // resetting its contentOffset to {0, 0}. To prevent this, we generate
@@ -103,7 +103,6 @@ RCT_EXPORT_VIEW_PROPERTY(onScrollToTop, RCTDirectEventBlock)
103
103
  RCT_EXPORT_VIEW_PROPERTY(onScrollEndDrag, RCTDirectEventBlock)
104
104
  RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollBegin, RCTDirectEventBlock)
105
105
  RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollEnd, RCTDirectEventBlock)
106
- RCT_EXPORT_OSX_VIEW_PROPERTY(onScrollKeyDown, RCTDirectEventBlock) // TODO(macOS GH#774)
107
106
  RCT_EXPORT_OSX_VIEW_PROPERTY(onPreferredScrollerStyleDidChange, RCTDirectEventBlock) // TODO(macOS GH#774)
108
107
  RCT_EXPORT_VIEW_PROPERTY(inverted, BOOL)
109
108
  #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
@@ -285,29 +285,37 @@
285
285
 
286
286
  - (void)reactFocus
287
287
  {
288
- if (![self becomeFirstResponder]) {
289
- self.reactIsFocusNeeded = YES;
290
- }
288
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
289
+ if (![[self window] makeFirstResponder:self]) {
290
+ #else
291
+ if (![self becomeFirstResponder]) {
292
+ #endif //// TODO(macOS GH#774)]
293
+ self.reactIsFocusNeeded = YES;
294
+ }
291
295
  }
292
296
 
293
297
  - (void)reactFocusIfNeeded
294
298
  {
295
- if (self.reactIsFocusNeeded) {
296
- if ([self becomeFirstResponder]) {
297
- self.reactIsFocusNeeded = NO;
298
- }
299
- }
299
+ if (self.reactIsFocusNeeded) {
300
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
301
+ if ([[self window] makeFirstResponder:self]) {
302
+ #else
303
+ if ([self becomeFirstResponder]) {
304
+ #endif // TODO(macOS GH#774)]
305
+ self.reactIsFocusNeeded = NO;
306
+ }
307
+ }
300
308
  }
301
309
 
302
310
  - (void)reactBlur
303
311
  {
304
- #if TARGET_OS_OSX // TODO(macOS GH#774)
312
+ #if TARGET_OS_OSX // [TODO(macOS GH#774)
305
313
  if (self == [[self window] firstResponder]) {
306
314
  [[self window] makeFirstResponder:[[self window] nextResponder]];
307
315
  }
308
316
  #else
309
317
  [self resignFirstResponder];
310
- #endif
318
+ #endif // TODO(macOS GH#774)]
311
319
  }
312
320
 
313
321
  #pragma mark - Layout
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.66.73
1
+ VERSION_NAME=0.66.76
2
2
  GROUP=com.facebook.react
3
3
 
4
4
  POM_NAME=ReactNative
@@ -17,6 +17,6 @@ public class ReactNativeVersion {
17
17
  public static final Map<String, Object> VERSION = MapBuilder.<String, Object>of(
18
18
  "major", 0,
19
19
  "minor", 66,
20
- "patch", 73,
20
+ "patch", 76,
21
21
  "prerelease", null);
22
22
  }
@@ -17,7 +17,7 @@ namespace facebook::react {
17
17
  constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 66;
20
- int32_t Patch = 73;
20
+ int32_t Patch = 76;
21
21
  std::string_view Prerelease = "";
22
22
  } ReactNativeVersion;
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-macos",
3
- "version": "0.66.73",
3
+ "version": "0.66.76",
4
4
  "bin": "./cli.js",
5
5
  "description": "React Native for macOS",
6
6
  "license": "MIT",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "react": "17.0.2",
14
- "react-native": "0.66.73"
14
+ "react-native": "0.66.76"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@babel/core": "^7.12.9",