Skip to content

Commit 0f875bf

Browse files
authored
Merge branch '0.68-stable' into list-with-mouse-68
2 parents 9d920e3 + 5904164 commit 0f875bf

File tree

17 files changed

+447
-393
lines changed

17 files changed

+447
-393
lines changed

Brewfile.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
"monterey": {
178178
"HOMEBREW_VERSION": "3.5.4",
179179
"HOMEBREW_PREFIX": "/usr/local",
180-
"Homebrew/homebrew-core": "73764017344e0191108318286ca340cbbb813359",
180+
"Homebrew/homebrew-core": "141aed5d76a7f039398bcdb4c39a0f25265ebcf2",
181181
"CLT": "13.4.0.0.1.1651278267",
182182
"Xcode": "13.4.1",
183183
"macOS": "12.4"

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ GEM
6363
fuzzy_match (2.0.4)
6464
gh_inspector (1.1.3)
6565
httpclient (2.8.3)
66-
i18n (1.11.0)
66+
i18n (1.12.0)
6767
concurrent-ruby (~> 1.0)
6868
json (2.6.2)
6969
minitest (5.16.2)
@@ -76,7 +76,7 @@ GEM
7676
ruby-macho (2.5.1)
7777
typhoeus (1.4.0)
7878
ethon (>= 0.9.0)
79-
tzinfo (2.0.4)
79+
tzinfo (2.0.5)
8080
concurrent-ruby (~> 1.0)
8181
xcodeproj (1.22.0)
8282
CFPropertyList (>= 2.3.3, < 4.0)
@@ -94,4 +94,4 @@ DEPENDENCIES
9494
cocoapods (~> 1.11, >= 1.11.2)
9595

9696
BUNDLED WITH
97-
2.3.17
97+
2.3.18

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,42 +1206,10 @@ class ScrollView extends React.Component<Props, State> {
12061206
nativeEvent.contentOffset.y +
12071207
nativeEvent.layoutMeasurement.height,
12081208
});
1209-
} else if (key === 'LEFT_ARROW') {
1210-
this._handleScrollByKeyDown(event, {
1211-
x:
1212-
nativeEvent.contentOffset.x +
1213-
-(this.props.horizontalLineScroll !== undefined
1214-
? this.props.horizontalLineScroll
1215-
: kMinScrollOffset),
1216-
y: nativeEvent.contentOffset.y,
1217-
});
1218-
} else if (key === 'RIGHT_ARROW') {
1219-
this._handleScrollByKeyDown(event, {
1220-
x:
1221-
nativeEvent.contentOffset.x +
1222-
(this.props.horizontalLineScroll !== undefined
1223-
? this.props.horizontalLineScroll
1224-
: kMinScrollOffset),
1225-
y: nativeEvent.contentOffset.y,
1226-
});
1227-
} else if (key === 'DOWN_ARROW') {
1228-
this._handleScrollByKeyDown(event, {
1229-
x: nativeEvent.contentOffset.x,
1230-
y:
1231-
nativeEvent.contentOffset.y +
1232-
(this.props.verticalLineScroll !== undefined
1233-
? this.props.verticalLineScroll
1234-
: kMinScrollOffset),
1235-
});
1236-
} else if (key === 'UP_ARROW') {
1237-
this._handleScrollByKeyDown(event, {
1238-
x: nativeEvent.contentOffset.x,
1239-
y:
1240-
nativeEvent.contentOffset.y +
1241-
-(this.props.verticalLineScroll !== undefined
1242-
? this.props.verticalLineScroll
1243-
: kMinScrollOffset),
1244-
});
1209+
} else if (key === 'HOME') {
1210+
this.scrollTo({x: 0, y: 0});
1211+
} else if (key === 'END') {
1212+
this.scrollToEnd({animated: true});
12451213
}
12461214
}
12471215
}

Libraries/Core/ReactNativeVersion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
exports.version = {
1717
major: 0,
1818
minor: 68,
19-
patch: 11,
19+
patch: 12,
2020
prerelease: null,
2121
};

Libraries/Lists/VirtualizedList.js

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
588588
const newOffset = Math.min(contentLength, visTop + (frameEnd - visEnd));
589589
this.scrollToOffset({offset: newOffset});
590590
} else if (frame.offset < visTop) {
591-
const newOffset = Math.max(0, visTop - frame.length);
591+
const newOffset = Math.min(frame.offset, visTop - frame.length);
592592
this.scrollToOffset({offset: newOffset});
593593
}
594594
}
@@ -888,7 +888,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
888888
index={ii}
889889
inversionStyle={inversionStyle}
890890
item={item}
891-
isSelected={this.state.selectedRowIndex === ii ? true : false} // TODO(macOS GH#774)
891+
// [TODO(macOS GH#774)
892+
isSelected={
893+
this.props.enableSelectionOnKeyPress &&
894+
this.state.selectedRowIndex === ii
895+
? true
896+
: false
897+
} // TODO(macOS GH#774)]
892898
key={key}
893899
prevCellKey={prevCellKey}
894900
onUpdateSeparators={this._onUpdateSeparators}
@@ -1326,10 +1332,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13261332
// $FlowFixMe[prop-missing] Invalid prop usage
13271333
<ScrollView
13281334
{...props}
1329-
onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1335+
// [TODO(macOS GH#774)
1336+
{...(props.enableSelectionOnKeyPress && {focusable: true})}
1337+
onScrollKeyDown={keyEventHandler}
13301338
onPreferredScrollerStyleDidChange={
13311339
preferredScrollerStyleDidChangeHandler
1332-
} // TODO(macOS GH#774)
1340+
} // TODO(macOS GH#774)]
13331341
refreshControl={
13341342
props.refreshControl == null ? (
13351343
<RefreshControl
@@ -1348,11 +1356,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
13481356
// $FlowFixMe Invalid prop usage
13491357
<ScrollView
13501358
{...props}
1351-
onScrollKeyDown={keyEventHandler} // TODO(macOS GH#774)
1359+
{...(props.enableSelectionOnKeyPress && {focusable: true})} // [TODO(macOS GH#774)
1360+
onScrollKeyDown={keyEventHandler}
13521361
onPreferredScrollerStyleDidChange={
1353-
// TODO(macOS GH#774)
1354-
preferredScrollerStyleDidChangeHandler // TODO(macOS GH#774)
1355-
}
1362+
preferredScrollerStyleDidChangeHandler
1363+
} // TODO(macOS GH#774)]
13561364
/>
13571365
);
13581366
}
@@ -1510,6 +1518,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
15101518
return rowAbove;
15111519
};
15121520

1521+
_selectRowAtIndex = rowIndex => {
1522+
this.setState(state => {
1523+
return {selectedRowIndex: rowIndex};
1524+
});
1525+
return rowIndex;
1526+
};
1527+
15131528
_selectRowBelowIndex = rowIndex => {
15141529
if (this.props.getItemCount) {
15151530
const {data} = this.props;
@@ -1524,61 +1539,81 @@ class VirtualizedList extends React.PureComponent<Props, State> {
15241539
}
15251540
};
15261541

1527-
_handleKeyDown = (e: ScrollEvent) => {
1542+
_handleKeyDown = (event: ScrollEvent) => {
15281543
if (this.props.onScrollKeyDown) {
1529-
this.props.onScrollKeyDown(e);
1544+
this.props.onScrollKeyDown(event);
15301545
} else {
15311546
if (Platform.OS === 'macos') {
15321547
// $FlowFixMe Cannot get e.nativeEvent because property nativeEvent is missing in Event
1533-
const event = e.nativeEvent;
1534-
const key = event.key;
1548+
const nativeEvent = event.nativeEvent;
1549+
const key = nativeEvent.key;
15351550

15361551
let prevIndex = -1;
15371552
let newIndex = -1;
15381553
if ('selectedRowIndex' in this.state) {
15391554
prevIndex = this.state.selectedRowIndex;
15401555
}
15411556

1542-
const {data, getItem} = this.props;
1543-
if (key === 'DOWN_ARROW') {
1544-
newIndex = this._selectRowBelowIndex(prevIndex);
1545-
this.ensureItemAtIndexIsVisible(newIndex);
1546-
1547-
if (prevIndex !== newIndex) {
1548-
const item = getItem(data, newIndex);
1549-
if (this.props.onSelectionChanged) {
1550-
this.props.onSelectionChanged({
1551-
previousSelection: prevIndex,
1552-
newSelection: newIndex,
1553-
item: item,
1554-
});
1555-
}
1556-
}
1557-
} else if (key === 'UP_ARROW') {
1557+
// const {data, getItem} = this.props;
1558+
if (key === 'UP_ARROW') {
15581559
newIndex = this._selectRowAboveIndex(prevIndex);
1559-
this.ensureItemAtIndexIsVisible(newIndex);
1560-
1561-
if (prevIndex !== newIndex) {
1562-
const item = getItem(data, newIndex);
1563-
if (this.props.onSelectionChanged) {
1564-
this.props.onSelectionChanged({
1565-
previousSelection: prevIndex,
1566-
newSelection: newIndex,
1567-
item: item,
1568-
});
1569-
}
1570-
}
1560+
this._handleSelectionChange(prevIndex, newIndex);
1561+
} else if (key === 'DOWN_ARROW') {
1562+
newIndex = this._selectRowBelowIndex(prevIndex);
1563+
this._handleSelectionChange(prevIndex, newIndex);
15711564
} else if (key === 'ENTER') {
15721565
if (this.props.onSelectionEntered) {
1573-
const item = getItem(data, prevIndex);
1566+
const item = this.props.getItem(this.props.data, prevIndex);
15741567
if (this.props.onSelectionEntered) {
15751568
this.props.onSelectionEntered(item);
15761569
}
15771570
}
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});
15781599
}
15791600
}
15801601
}
15811602
};
1603+
1604+
_handleSelectionChange = (prevIndex, newIndex) => {
1605+
this.ensureItemAtIndexIsVisible(newIndex);
1606+
if (prevIndex !== newIndex) {
1607+
const item = this.props.getItem(this.props.data, newIndex);
1608+
if (this.props.onSelectionChanged) {
1609+
this.props.onSelectionChanged({
1610+
previousSelection: prevIndex,
1611+
newSelection: newIndex,
1612+
item: item,
1613+
});
1614+
}
1615+
}
1616+
};
15821617
// ]TODO(macOS GH#774)
15831618

15841619
_renderDebugOverlay() {
@@ -2176,6 +2211,7 @@ class CellRenderer extends React.Component<
21762211
return React.createElement(ListItemComponent, {
21772212
item,
21782213
index,
2214+
isSelected,
21792215
separators: this._separators,
21802216
});
21812217
}
@@ -2252,6 +2288,7 @@ class CellRenderer extends React.Component<
22522288
{itemSeparator}
22532289
</CellRendererComponent>
22542290
);
2291+
// TODO(macOS GH#774)]
22552292

22562293
return (
22572294
<VirtualizedListCellContextProvider cellKey={this.props.cellKey}>

React/Base/RCTVersion.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
__rnVersion = @{
2828
RCTVersionMajor: @(0),
2929
RCTVersionMinor: @(68),
30-
RCTVersionPatch: @(11),
30+
RCTVersionPatch: @(12),
3131
RCTVersionPrerelease: [NSNull null],
3232
};
3333
});

React/Views/ScrollView/RCTScrollView.m

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,16 +1258,22 @@ - (void)uiManagerWillPerformMounting:(RCTUIManager *)manager
12581258

12591259
#if TARGET_OS_OSX // [TODO(macOS GH#774)
12601260

1261-
- (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode
1261+
- (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode modifierFlags:(NSEventModifierFlags)modifierFlags
12621262
{
12631263
switch (keyCode)
12641264
{
12651265
case 36:
12661266
return @"ENTER";
12671267

1268+
case 115:
1269+
return @"HOME";
1270+
12681271
case 116:
12691272
return @"PAGE_UP";
12701273

1274+
case 119:
1275+
return @"END";
1276+
12711277
case 121:
12721278
return @"PAGE_DOWN";
12731279

@@ -1278,35 +1284,44 @@ - (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode
12781284
return @"RIGHT_ARROW";
12791285

12801286
case 125:
1281-
return @"DOWN_ARROW";
1287+
if (modifierFlags & NSEventModifierFlagOption) {
1288+
return @"OPTION_DOWN";
1289+
} else {
1290+
return @"DOWN_ARROW";
1291+
}
12821292

12831293
case 126:
1284-
return @"UP_ARROW";
1294+
if (modifierFlags & NSEventModifierFlagOption) {
1295+
return @"OPTION_UP";
1296+
} else {
1297+
return @"UP_ARROW";
1298+
}
12851299
}
12861300
return @"";
12871301
}
12881302

12891303
- (void)keyDown:(UIEvent*)theEvent
12901304
{
12911305
// Don't emit a scroll event if tab was pressed while the scrollview is first responder
1292-
if (self == [[self window] firstResponder] &&
1293-
theEvent.keyCode != 48) {
1294-
NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode];
1295-
RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1296-
} else {
1297-
[super keyDown:theEvent];
1298-
1299-
// AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1300-
// automatically scroll to make the view visible to make it navigable via keyboard.
1301-
if ([theEvent keyCode] == 48) { //tab key
1302-
id firstResponder = [[self window] firstResponder];
1303-
if ([firstResponder isKindOfClass:[NSView class]] &&
1304-
[firstResponder isDescendantOf:[_scrollView documentView]]) {
1305-
NSView *view = (NSView*)firstResponder;
1306-
NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1307-
[view convertRect:view.frame toView:_scrollView.documentView];
1308-
[[_scrollView documentView] scrollRectToVisible:visibleRect];
1309-
}
1306+
if (!(self == [[self window] firstResponder] && theEvent.keyCode == 48)) {
1307+
NSString *keyCommand = [self keyCommandFromKeyCode:theEvent.keyCode modifierFlags:theEvent.modifierFlags];
1308+
if (![keyCommand isEqual: @""]) {
1309+
RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
1310+
} else {
1311+
[super keyDown:theEvent];
1312+
}
1313+
}
1314+
1315+
// AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
1316+
// automatically scroll to make the view visible to make it navigable via keyboard.
1317+
if ([theEvent keyCode] == 48) { //tab key
1318+
id firstResponder = [[self window] firstResponder];
1319+
if ([firstResponder isKindOfClass:[NSView class]] &&
1320+
[firstResponder isDescendantOf:[_scrollView documentView]]) {
1321+
NSView *view = (NSView*)firstResponder;
1322+
NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
1323+
[view convertRect:view.frame toView:_scrollView.documentView];
1324+
[[_scrollView documentView] scrollRectToVisible:visibleRect];
13101325
}
13111326
}
13121327
}

0 commit comments

Comments
 (0)