react-native-macos 0.66.59 → 0.66.60

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.
@@ -1201,42 +1201,10 @@ class ScrollView extends React.Component<Props, State> {
1201
1201
  nativeEvent.contentOffset.y +
1202
1202
  nativeEvent.layoutMeasurement.height,
1203
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
- });
1204
+ } else if (key === 'HOME') {
1205
+ this.scrollTo({x: 0, y: 0});
1206
+ } else if (key === 'END') {
1207
+ this.scrollToEnd({animated: true});
1240
1208
  }
1241
1209
  }
1242
1210
  }
@@ -12,6 +12,6 @@
12
12
  exports.version = {
13
13
  major: 0,
14
14
  minor: 66,
15
- patch: 59,
15
+ patch: 60,
16
16
  prerelease: null,
17
17
  };
@@ -588,7 +588,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
588
588
  const newOffset = Math.min(contentLength, visTop + (frameEnd - visEnd));
589
589
  this.scrollToOffset({offset: newOffset});
590
590
  } else if (frame.offset < visTop) {
591
- const newOffset = Math.max(0, visTop - frame.length);
591
+ const newOffset = Math.min(frame.offset, visTop - frame.length);
592
592
  this.scrollToOffset({offset: newOffset});
593
593
  }
594
594
  }
@@ -882,7 +882,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
882
882
  index={ii}
883
883
  inversionStyle={inversionStyle}
884
884
  item={item}
885
- isSelected={this.state.selectedRowIndex === ii ? true : false} // TODO(macOS GH#774)
885
+ // [TODO(macOS GH#774)
886
+ isSelected={
887
+ this.props.enableSelectionOnKeyPress &&
888
+ this.state.selectedRowIndex === ii
889
+ ? true
890
+ : false
891
+ } // TODO(macOS GH#774)]
886
892
  key={key}
887
893
  prevCellKey={prevCellKey}
888
894
  onUpdateSeparators={this._onUpdateSeparators}
@@ -1323,10 +1329,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1323
1329
  // $FlowFixMe[prop-missing] Invalid prop usage
1324
1330
  <ScrollView
1325
1331
  {...props}
1326
- onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1332
+ // [TODO(macOS GH#774)
1333
+ {...(props.enableSelectionOnKeyPress && {focusable: true})}
1334
+ onScrollKeyDown={keyEventHandler}
1327
1335
  onPreferredScrollerStyleDidChange={
1328
1336
  preferredScrollerStyleDidChangeHandler
1329
- } // TODO(macOS GH#774)
1337
+ } // TODO(macOS GH#774)]
1330
1338
  refreshControl={
1331
1339
  props.refreshControl == null ? (
1332
1340
  <RefreshControl
@@ -1345,11 +1353,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1345
1353
  // $FlowFixMe Invalid prop usage
1346
1354
  <ScrollView
1347
1355
  {...props}
1348
- onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1356
+ {...(props.enableSelectionOnKeyPress && {focusable: true})} // [TODO(macOS GH#774)
1357
+ onScrollKeyDown={keyEventHandler}
1349
1358
  onPreferredScrollerStyleDidChange={
1350
- // TODO(macOS GH#774)
1351
- preferredScrollerStyleDidChangeHandler // TODO(macOS GH#774)
1352
- }
1359
+ preferredScrollerStyleDidChangeHandler
1360
+ } // TODO(macOS GH#774)]
1353
1361
  />
1354
1362
  );
1355
1363
  }
@@ -1507,6 +1515,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1507
1515
  return rowAbove;
1508
1516
  };
1509
1517
 
1518
+ _selectRowAtIndex = rowIndex => {
1519
+ this.setState(state => {
1520
+ return {selectedRowIndex: rowIndex};
1521
+ });
1522
+ return rowIndex;
1523
+ };
1524
+
1510
1525
  _selectRowBelowIndex = rowIndex => {
1511
1526
  if (this.props.getItemCount) {
1512
1527
  const {data} = this.props;
@@ -1521,14 +1536,14 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1521
1536
  }
1522
1537
  };
1523
1538
 
1524
- _handleKeyDown = (e: ScrollEvent) => {
1539
+ _handleKeyDown = (event: ScrollEvent) => {
1525
1540
  if (this.props.onScrollKeyDown) {
1526
- this.props.onScrollKeyDown(e);
1541
+ this.props.onScrollKeyDown(event);
1527
1542
  } else {
1528
1543
  if (Platform.OS === 'macos') {
1529
1544
  // $FlowFixMe Cannot get e.nativeEvent because property nativeEvent is missing in Event
1530
- const event = e.nativeEvent;
1531
- const key = event.key;
1545
+ const nativeEvent = event.nativeEvent;
1546
+ const key = nativeEvent.key;
1532
1547
 
1533
1548
  let prevIndex = -1;
1534
1549
  let newIndex = -1;
@@ -1536,46 +1551,66 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1536
1551
  prevIndex = this.state.selectedRowIndex;
1537
1552
  }
1538
1553
 
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') {
1554
+ // const {data, getItem} = this.props;
1555
+ if (key === 'UP_ARROW') {
1555
1556
  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
- }
1557
+ this._handleSelectionChange(prevIndex, newIndex);
1558
+ } else if (key === 'DOWN_ARROW') {
1559
+ newIndex = this._selectRowBelowIndex(prevIndex);
1560
+ this._handleSelectionChange(prevIndex, newIndex);
1568
1561
  } else if (key === 'ENTER') {
1569
1562
  if (this.props.onSelectionEntered) {
1570
- const item = getItem(data, prevIndex);
1563
+ const item = this.props.getItem(this.props.data, prevIndex);
1571
1564
  if (this.props.onSelectionEntered) {
1572
1565
  this.props.onSelectionEntered(item);
1573
1566
  }
1574
1567
  }
1568
+ } else if (key === 'OPTION_UP') {
1569
+ newIndex = this._selectRowAtIndex(0);
1570
+ this._handleSelectionChange(prevIndex, newIndex);
1571
+ } else if (key === 'OPTION_DOWN') {
1572
+ newIndex = this._selectRowAtIndex(this.state.last);
1573
+ this._handleSelectionChange(prevIndex, newIndex);
1574
+ } else if (key === 'PAGE_UP') {
1575
+ const maxY =
1576
+ event.nativeEvent.contentSize.height -
1577
+ event.nativeEvent.layoutMeasurement.height;
1578
+ const newOffset = Math.min(
1579
+ maxY,
1580
+ nativeEvent.contentOffset.y + -nativeEvent.layoutMeasurement.height,
1581
+ );
1582
+ this.scrollToOffset({animated: true, offset: newOffset});
1583
+ } else if (key === 'PAGE_DOWN') {
1584
+ const maxY =
1585
+ event.nativeEvent.contentSize.height -
1586
+ event.nativeEvent.layoutMeasurement.height;
1587
+ const newOffset = Math.min(
1588
+ maxY,
1589
+ nativeEvent.contentOffset.y + nativeEvent.layoutMeasurement.height,
1590
+ );
1591
+ this.scrollToOffset({animated: true, offset: newOffset});
1592
+ } else if (key === 'HOME') {
1593
+ this.scrollToOffset({animated: true, offset: 0});
1594
+ } else if (key === 'END') {
1595
+ this.scrollToEnd({animated: true});
1575
1596
  }
1576
1597
  }
1577
1598
  }
1578
1599
  };
1600
+
1601
+ _handleSelectionChange = (prevIndex, newIndex) => {
1602
+ this.ensureItemAtIndexIsVisible(newIndex);
1603
+ if (prevIndex !== newIndex) {
1604
+ const item = this.props.getItem(this.props.data, newIndex);
1605
+ if (this.props.onSelectionChanged) {
1606
+ this.props.onSelectionChanged({
1607
+ previousSelection: prevIndex,
1608
+ newSelection: newIndex,
1609
+ item: item,
1610
+ });
1611
+ }
1612
+ }
1613
+ };
1579
1614
  // ]TODO(macOS GH#774)
1580
1615
 
1581
1616
  _renderDebugOverlay() {
@@ -2182,6 +2217,7 @@ class CellRenderer extends React.Component<
2182
2217
  return React.createElement(ListItemComponent, {
2183
2218
  item,
2184
2219
  index,
2220
+ isSelected,
2185
2221
  separators: this._separators,
2186
2222
  });
2187
2223
  }
@@ -2258,6 +2294,7 @@ class CellRenderer extends React.Component<
2258
2294
  {itemSeparator}
2259
2295
  </CellRendererComponent>
2260
2296
  );
2297
+ // TODO(macOS GH#774)]
2261
2298
 
2262
2299
  return (
2263
2300
  <VirtualizedListCellContextProvider cellKey={this.props.cellKey}>
@@ -23,7 +23,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
23
23
  __rnVersion = @{
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(66),
26
- RCTVersionPatch: @(59),
26
+ RCTVersionPatch: @(60),
27
27
  RCTVersionPrerelease: [NSNull null],
28
28
  };
29
29
  });
@@ -1180,16 +1180,22 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1180
1180
 
1181
1181
  #if TARGET_OS_OSX // [TODO(macOS GH#774)
1182
1182
 
1183
- - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode
1183
+ - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode modifierFlags:(NSEventModifierFlags)modifierFlags
1184
1184
  {
1185
1185
  switch (keyCode)
1186
1186
  {
1187
1187
  case 36:
1188
1188
  return @"ENTER";
1189
1189
 
1190
+ case 115:
1191
+ return @"HOME";
1192
+
1190
1193
  case 116:
1191
1194
  return @"PAGE_UP";
1192
1195
 
1196
+ case 119:
1197
+ return @"END";
1198
+
1193
1199
  case 121:
1194
1200
  return @"PAGE_DOWN";
1195
1201
 
@@ -1200,10 +1206,18 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1200
1206
  return @"RIGHT_ARROW";
1201
1207
 
1202
1208
  case 125:
1203
- return @"DOWN_ARROW";
1209
+ if (modifierFlags & NSEventModifierFlagOption) {
1210
+ return @"OPTION_DOWN";
1211
+ } else {
1212
+ return @"DOWN_ARROW";
1213
+ }
1204
1214
 
1205
1215
  case 126:
1206
- return @"UP_ARROW";
1216
+ if (modifierFlags & NSEventModifierFlagOption) {
1217
+ return @"OPTION_UP";
1218
+ } else {
1219
+ return @"UP_ARROW";
1220
+ }
1207
1221
  }
1208
1222
  return @"";
1209
1223
  }
@@ -1211,24 +1225,25 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
1211
1225
  - (void)keyDown:(UIEvent*)theEvent
1212
1226
  {
1213
1227
  // Don't emit a scroll event if tab was pressed while the scrollview is first responder
1214
- if (self == [[self window] firstResponder] &&
1215
- theEvent.keyCode != 48) {
1216
- NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode];
1217
- RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1218
- } else {
1219
- [super keyDown:theEvent];
1220
-
1221
- // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1222
- // automatically scroll to make the view visible to make it navigable via keyboard.
1223
- if ([theEvent keyCode] == 48) { //tab key
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
- }
1228
+ if (!(self == [[self window] firstResponder] && theEvent.keyCode == 48)) {
1229
+ NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode modifierFlags:theEvent.modifierFlags];
1230
+ if (![keyCommand isEqual: @""]) {
1231
+ RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1232
+ } else {
1233
+ [super keyDown:theEvent];
1234
+ }
1235
+ }
1236
+
1237
+ // AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1238
+ // automatically scroll to make the view visible to make it navigable via keyboard.
1239
+ if ([theEvent keyCode] == 48) { //tab key
1240
+ id firstResponder = [[self window] firstResponder];
1241
+ if ([firstResponder isKindOfClass:[NSView class]] &&
1242
+ [firstResponder isDescendantOf:[_scrollView documentView]]) {
1243
+ NSView *view = (NSView*)firstResponder;
1244
+ NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1245
+ [view convertRect:view.frame toView:_scrollView.documentView];
1246
+ [[_scrollView documentView] scrollRectToVisible:visibleRect];
1232
1247
  }
1233
1248
  }
1234
1249
  }
@@ -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.59
1
+ VERSION_NAME=0.66.60
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", 59,
20
+ "patch", 60,
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 = 59;
20
+ int32_t Patch = 60;
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.59",
3
+ "version": "0.66.60",
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.59"
14
+ "react-native": "0.66.60"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@babel/core": "^7.12.9",