@@ -588,14 +588,10 @@ 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 . min ( frame . offset , visTop - frame . length ) ;
591
+ const newOffset = Math . max ( 0 , visTop - frame . length ) ;
592
592
this . scrollToOffset ( { offset : newOffset } ) ;
593
593
}
594
594
}
595
-
596
- selectRowAtIndex ( rowIndex : number ) {
597
- this . _selectRowAtIndex ( rowIndex ) ;
598
- }
599
595
// ]TODO(macOS GH#774)
600
596
601
597
recordInteraction ( ) {
@@ -886,13 +882,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
886
882
index = { ii }
887
883
inversionStyle = { inversionStyle }
888
884
item = { item }
889
- // [TODO(macOS GH#774)
890
- isSelected = {
891
- this . props . enableSelectionOnKeyPress &&
892
- this . state . selectedRowIndex === ii
893
- ? true
894
- : false
895
- } // TODO(macOS GH#774)]
885
+ isSelected = { this . state . selectedRowIndex === ii ? true : false } // TODO(macOS GH#774)
896
886
key = { key }
897
887
prevCellKey = { prevCellKey }
898
888
onUpdateSeparators = { this . _onUpdateSeparators }
@@ -1333,12 +1323,10 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1333
1323
// $FlowFixMe[prop-missing] Invalid prop usage
1334
1324
< ScrollView
1335
1325
{ ...props }
1336
- // [TODO(macOS GH#774)
1337
- { ...( props . enableSelectionOnKeyPress && { focusable : true } ) }
1338
- onScrollKeyDown = { keyEventHandler }
1326
+ onScrollKeyDown = { keyEventHandler } // TODO(macOS GH#774)
1339
1327
onPreferredScrollerStyleDidChange = {
1340
1328
preferredScrollerStyleDidChangeHandler
1341
- } // TODO(macOS GH#774)]
1329
+ } // TODO(macOS GH#774)
1342
1330
refreshControl = {
1343
1331
props . refreshControl == null ? (
1344
1332
< RefreshControl
@@ -1357,11 +1345,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1357
1345
// $FlowFixMe Invalid prop usage
1358
1346
< ScrollView
1359
1347
{ ...props }
1360
- { ...( props . enableSelectionOnKeyPress && { focusable : true } ) } // [TODO(macOS GH#774)
1361
- onScrollKeyDown = { keyEventHandler }
1348
+ onScrollKeyDown = { keyEventHandler } // TODO(macOS GH#774)
1362
1349
onPreferredScrollerStyleDidChange = {
1363
- preferredScrollerStyleDidChangeHandler
1364
- } // TODO(macOS GH#774)]
1350
+ // TODO(macOS GH#774)
1351
+ preferredScrollerStyleDidChangeHandler // TODO(macOS GH#774)
1352
+ }
1365
1353
/>
1366
1354
) ;
1367
1355
}
@@ -1519,13 +1507,6 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1519
1507
return rowAbove ;
1520
1508
} ;
1521
1509
1522
- _selectRowAtIndex = rowIndex => {
1523
- this . setState ( state => {
1524
- return { selectedRowIndex : rowIndex } ;
1525
- } ) ;
1526
- return rowIndex ;
1527
- } ;
1528
-
1529
1510
_selectRowBelowIndex = rowIndex => {
1530
1511
if ( this . props . getItemCount ) {
1531
1512
const { data} = this . props ;
@@ -1540,81 +1521,61 @@ class VirtualizedList extends React.PureComponent<Props, State> {
1540
1521
}
1541
1522
} ;
1542
1523
1543
- _handleKeyDown = ( event : ScrollEvent ) => {
1524
+ _handleKeyDown = ( e : ScrollEvent ) => {
1544
1525
if ( this . props . onScrollKeyDown ) {
1545
- this . props . onScrollKeyDown ( event ) ;
1526
+ this . props . onScrollKeyDown ( e ) ;
1546
1527
} else {
1547
1528
if ( Platform . OS === 'macos' ) {
1548
1529
// $FlowFixMe Cannot get e.nativeEvent because property nativeEvent is missing in Event
1549
- const nativeEvent = event . nativeEvent ;
1550
- const key = nativeEvent . key ;
1530
+ const event = e . nativeEvent ;
1531
+ const key = event . key ;
1551
1532
1552
1533
let prevIndex = - 1 ;
1553
1534
let newIndex = - 1 ;
1554
1535
if ( 'selectedRowIndex' in this . state ) {
1555
1536
prevIndex = this . state . selectedRowIndex ;
1556
1537
}
1557
1538
1558
- // const {data, getItem} = this.props;
1559
- if ( key === 'UP_ARROW' ) {
1560
- newIndex = this . _selectRowAboveIndex ( prevIndex ) ;
1561
- this . _handleSelectionChange ( prevIndex , newIndex ) ;
1562
- } else if ( key = = = 'DOWN_ARROW' ) {
1539
+ const { data, getItem} = this . props ;
1540
+ if ( key === 'DOWN_ARROW' ) {
1563
1541
newIndex = this . _selectRowBelowIndex ( prevIndex ) ;
1564
- this . _handleSelectionChange ( prevIndex , newIndex ) ;
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
+ }
1565
1568
} else if ( key === 'ENTER' ) {
1566
1569
if ( this . props . onSelectionEntered ) {
1567
- const item = this . props . getItem ( this . props . data , prevIndex ) ;
1570
+ const item = getItem ( data , prevIndex ) ;
1568
1571
if ( this . props . onSelectionEntered ) {
1569
1572
this . props . onSelectionEntered ( item ) ;
1570
1573
}
1571
1574
}
1572
- } else if ( key = = = 'OPTION_UP' ) {
1573
- newIndex = this . _selectRowAtIndex ( 0 ) ;
1574
- this . _handleSelectionChange ( prevIndex , newIndex ) ;
1575
- } else if ( key = = = 'OPTION_DOWN' ) {
1576
- newIndex = this . _selectRowAtIndex ( this . state . last ) ;
1577
- this . _handleSelectionChange ( prevIndex , newIndex ) ;
1578
- } else if ( key = = = 'PAGE_UP' ) {
1579
- const maxY =
1580
- event . nativeEvent . contentSize . height -
1581
- event . nativeEvent . layoutMeasurement . height ;
1582
- const newOffset = Math . min (
1583
- maxY ,
1584
- nativeEvent . contentOffset . y + - nativeEvent . layoutMeasurement . height ,
1585
- ) ;
1586
- this . scrollToOffset ( { animated : true , offset : newOffset } ) ;
1587
- } else if ( key = = = 'PAGE_DOWN' ) {
1588
- const maxY =
1589
- event . nativeEvent . contentSize . height -
1590
- event . nativeEvent . layoutMeasurement . height ;
1591
- const newOffset = Math . min (
1592
- maxY ,
1593
- nativeEvent . contentOffset . y + nativeEvent . layoutMeasurement . height ,
1594
- ) ;
1595
- this . scrollToOffset ( { animated : true , offset : newOffset } ) ;
1596
- } else if ( key = = = 'HOME' ) {
1597
- this . scrollToOffset ( { animated : true , offset : 0 } ) ;
1598
- } else if ( key = = = 'END' ) {
1599
- this . scrollToEnd ( { animated : true } ) ;
1600
1575
}
1601
1576
}
1602
1577
}
1603
1578
} ;
1604
-
1605
- _handleSelectionChange = ( prevIndex , newIndex ) => {
1606
- this . ensureItemAtIndexIsVisible ( newIndex ) ;
1607
- if ( prevIndex !== newIndex ) {
1608
- const item = this . props . getItem ( this . props . data , newIndex ) ;
1609
- if ( this . props . onSelectionChanged ) {
1610
- this . props . onSelectionChanged ( {
1611
- previousSelection : prevIndex ,
1612
- newSelection : newIndex ,
1613
- item : item ,
1614
- } ) ;
1615
- }
1616
- }
1617
- } ;
1618
1579
// ]TODO(macOS GH#774)
1619
1580
1620
1581
_renderDebugOverlay ( ) {
@@ -2221,7 +2182,6 @@ class CellRenderer extends React.Component<
2221
2182
return React . createElement ( ListItemComponent , {
2222
2183
item,
2223
2184
index,
2224
- isSelected,
2225
2185
separators : this . _separators ,
2226
2186
} ) ;
2227
2187
}
@@ -2298,7 +2258,6 @@ class CellRenderer extends React.Component<
2298
2258
{ itemSeparator }
2299
2259
</ CellRendererComponent >
2300
2260
) ;
2301
- // TODO(macOS GH#774)]
2302
2261
2303
2262
return (
2304
2263
< VirtualizedListCellContextProvider cellKey = { this . props . cellKey } >
0 commit comments