react-native-macos 0.68.31 → 0.68.32
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 +0 -45
- package/Libraries/Components/View/ViewPropTypes.js +0 -6
- package/Libraries/Core/ReactNativeVersion.js +1 -1
- package/Libraries/Lists/FlatList.js +24 -0
- package/Libraries/Lists/VirtualizedList.js +94 -106
- package/Libraries/Lists/VirtualizedSectionList.js +9 -5
- package/Libraries/Types/CoreEventTypes.js +0 -1
- package/React/Base/RCTVersion.m +1 -1
- package/React/Views/RCTView.h +4 -0
- package/React/Views/RCTView.m +20 -159
- package/React/Views/RCTViewKeyboardEvent.h +6 -28
- package/React/Views/RCTViewKeyboardEvent.m +66 -61
- package/React/Views/RCTViewManager.m +2 -12
- package/React/Views/ScrollView/RCTScrollView.h +0 -1
- package/React/Views/ScrollView/RCTScrollView.m +49 -62
- package/React/Views/ScrollView/RCTScrollViewManager.m +0 -1
- 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/template/package.json +1 -1
|
@@ -1184,50 +1184,6 @@ class ScrollView extends React.Component<Props, State> {
|
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
1186
|
// [TODO(macOS GH#774)
|
|
1187
|
-
_handleKeyDown = (event: ScrollEvent) => {
|
|
1188
|
-
if (this.props.onScrollKeyDown) {
|
|
1189
|
-
this.props.onScrollKeyDown(event);
|
|
1190
|
-
} else {
|
|
1191
|
-
if (Platform.OS === 'macos') {
|
|
1192
|
-
const nativeEvent = event.nativeEvent;
|
|
1193
|
-
const key = nativeEvent.key;
|
|
1194
|
-
const kMinScrollOffset = 10;
|
|
1195
|
-
if (key === 'PAGE_UP') {
|
|
1196
|
-
this._handleScrollByKeyDown(event, {
|
|
1197
|
-
x: nativeEvent.contentOffset.x,
|
|
1198
|
-
y:
|
|
1199
|
-
nativeEvent.contentOffset.y +
|
|
1200
|
-
-nativeEvent.layoutMeasurement.height,
|
|
1201
|
-
});
|
|
1202
|
-
} else if (key === 'PAGE_DOWN') {
|
|
1203
|
-
this._handleScrollByKeyDown(event, {
|
|
1204
|
-
x: nativeEvent.contentOffset.x,
|
|
1205
|
-
y:
|
|
1206
|
-
nativeEvent.contentOffset.y +
|
|
1207
|
-
nativeEvent.layoutMeasurement.height,
|
|
1208
|
-
});
|
|
1209
|
-
} else if (key === 'HOME') {
|
|
1210
|
-
this.scrollTo({x: 0, y: 0});
|
|
1211
|
-
} else if (key === 'END') {
|
|
1212
|
-
this.scrollToEnd({animated: true});
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
|
-
_handleScrollByKeyDown = (event: ScrollEvent, newOffset) => {
|
|
1219
|
-
const maxX =
|
|
1220
|
-
event.nativeEvent.contentSize.width -
|
|
1221
|
-
event.nativeEvent.layoutMeasurement.width;
|
|
1222
|
-
const maxY =
|
|
1223
|
-
event.nativeEvent.contentSize.height -
|
|
1224
|
-
event.nativeEvent.layoutMeasurement.height;
|
|
1225
|
-
this.scrollTo({
|
|
1226
|
-
x: Math.max(0, Math.min(maxX, newOffset.x)),
|
|
1227
|
-
y: Math.max(0, Math.min(maxY, newOffset.y)),
|
|
1228
|
-
});
|
|
1229
|
-
};
|
|
1230
|
-
|
|
1231
1187
|
_handlePreferredScrollerStyleDidChange = (event: ScrollEvent) => {
|
|
1232
1188
|
this.setState({contentKey: this.state.contentKey + 1});
|
|
1233
1189
|
}; // ]TODO(macOS GH#774)
|
|
@@ -1783,7 +1739,6 @@ class ScrollView extends React.Component<Props, State> {
|
|
|
1783
1739
|
// Override the onContentSizeChange from props, since this event can
|
|
1784
1740
|
// bubble up from TextInputs
|
|
1785
1741
|
onContentSizeChange: null,
|
|
1786
|
-
onScrollKeyDown: this._handleKeyDown, // TODO(macOS GH#774)
|
|
1787
1742
|
onPreferredScrollerStyleDidChange:
|
|
1788
1743
|
this._handlePreferredScrollerStyleDidChange, // TODO(macOS GH#774)
|
|
1789
1744
|
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 `focusable` 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
|
*
|
|
@@ -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
|
*/
|
|
@@ -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
|
};
|
|
@@ -1309,14 +1327,16 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1309
1327
|
}
|
|
1310
1328
|
|
|
1311
1329
|
_defaultRenderScrollComponent = props => {
|
|
1312
|
-
|
|
1313
|
-
if (!keyEventHandler) {
|
|
1314
|
-
keyEventHandler = this.props.enableSelectionOnKeyPress
|
|
1315
|
-
? this._handleKeyDown
|
|
1316
|
-
: null;
|
|
1317
|
-
}
|
|
1330
|
+
// [TODO(macOS GH#774)
|
|
1318
1331
|
const preferredScrollerStyleDidChangeHandler =
|
|
1319
|
-
this.props.onPreferredScrollerStyleDidChange;
|
|
1332
|
+
this.props.onPreferredScrollerStyleDidChange;
|
|
1333
|
+
|
|
1334
|
+
const keyboardNavigationProps = {
|
|
1335
|
+
focusable: true,
|
|
1336
|
+
validKeysDown: ['ArrowUp', 'ArrowDown', 'Home', 'End'],
|
|
1337
|
+
onKeyDown: this._handleKeyDown,
|
|
1338
|
+
};
|
|
1339
|
+
// ]TODO(macOS GH#774)
|
|
1320
1340
|
const onRefresh = props.onRefresh;
|
|
1321
1341
|
if (this._isNestedWithSameOrientation()) {
|
|
1322
1342
|
// $FlowFixMe[prop-missing] - Typing ReactNativeComponent revealed errors
|
|
@@ -1333,8 +1353,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1333
1353
|
<ScrollView
|
|
1334
1354
|
{...props}
|
|
1335
1355
|
// [TODO(macOS GH#774)
|
|
1336
|
-
{...(props.enableSelectionOnKeyPress &&
|
|
1337
|
-
onScrollKeyDown={keyEventHandler}
|
|
1356
|
+
{...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
|
|
1338
1357
|
onPreferredScrollerStyleDidChange={
|
|
1339
1358
|
preferredScrollerStyleDidChangeHandler
|
|
1340
1359
|
} // TODO(macOS GH#774)]
|
|
@@ -1356,8 +1375,8 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1356
1375
|
// $FlowFixMe Invalid prop usage
|
|
1357
1376
|
<ScrollView
|
|
1358
1377
|
{...props}
|
|
1359
|
-
|
|
1360
|
-
|
|
1378
|
+
// [TODO(macOS GH#774)
|
|
1379
|
+
{...(props.enableSelectionOnKeyPress && keyboardNavigationProps)}
|
|
1361
1380
|
onPreferredScrollerStyleDidChange={
|
|
1362
1381
|
preferredScrollerStyleDidChangeHandler
|
|
1363
1382
|
} // TODO(macOS GH#774)]
|
|
@@ -1510,98 +1529,11 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1510
1529
|
};
|
|
1511
1530
|
|
|
1512
1531
|
// [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
1532
|
_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
|
-
}
|
|
1556
|
-
|
|
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
|
-
};
|
|
1533
|
+
const prevIndex = this.state.selectedRowIndex;
|
|
1534
|
+
const newIndex = rowIndex;
|
|
1535
|
+
this.setState({selectedRowIndex: newIndex});
|
|
1603
1536
|
|
|
1604
|
-
_handleSelectionChange = (prevIndex, newIndex) => {
|
|
1605
1537
|
this.ensureItemAtIndexIsVisible(newIndex);
|
|
1606
1538
|
if (prevIndex !== newIndex) {
|
|
1607
1539
|
const item = this.props.getItem(this.props.data, newIndex);
|
|
@@ -1613,6 +1545,62 @@ class VirtualizedList extends React.PureComponent<Props, State> {
|
|
|
1613
1545
|
});
|
|
1614
1546
|
}
|
|
1615
1547
|
}
|
|
1548
|
+
|
|
1549
|
+
return newIndex;
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
_selectRowAboveIndex = rowIndex => {
|
|
1553
|
+
const rowAbove = rowIndex > 0 ? rowIndex - 1 : rowIndex;
|
|
1554
|
+
this._selectRowAtIndex(rowAbove);
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
_selectRowBelowIndex = rowIndex => {
|
|
1558
|
+
const rowBelow = rowIndex < this.state.last ? rowIndex + 1 : rowIndex;
|
|
1559
|
+
this._selectRowAtIndex(rowBelow);
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
_handleKeyDown = (event: KeyEvent) => {
|
|
1563
|
+
if (Platform.OS === 'macos') {
|
|
1564
|
+
this.props.onKeyDown?.(event);
|
|
1565
|
+
if (event.defaultPrevented) {
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
const nativeEvent = event.nativeEvent;
|
|
1570
|
+
const key = nativeEvent.key;
|
|
1571
|
+
|
|
1572
|
+
let selectedIndex = -1;
|
|
1573
|
+
if (this.state.selectedRowIndex >= 0) {
|
|
1574
|
+
selectedIndex = this.state.selectedRowIndex;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
if (key === 'ArrowUp') {
|
|
1578
|
+
if (nativeEvent.altKey) {
|
|
1579
|
+
// Option+Up selects the first element
|
|
1580
|
+
this._selectRowAtIndex(0);
|
|
1581
|
+
} else {
|
|
1582
|
+
this._selectRowAboveIndex(selectedIndex);
|
|
1583
|
+
}
|
|
1584
|
+
} else if (key === 'ArrowDown') {
|
|
1585
|
+
if (nativeEvent.altKey) {
|
|
1586
|
+
// Option+Down selects the last element
|
|
1587
|
+
this._selectRowAtIndex(this.state.last);
|
|
1588
|
+
} else {
|
|
1589
|
+
this._selectRowBelowIndex(selectedIndex);
|
|
1590
|
+
}
|
|
1591
|
+
} else if (key === 'Enter') {
|
|
1592
|
+
if (this.props.onSelectionEntered) {
|
|
1593
|
+
const item = this.props.getItem(this.props.data, selectedIndex);
|
|
1594
|
+
if (this.props.onSelectionEntered) {
|
|
1595
|
+
this.props.onSelectionEntered(item);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
} else if (key === 'Home') {
|
|
1599
|
+
this.scrollToOffset({animated: true, offset: 0});
|
|
1600
|
+
} else if (key === 'End') {
|
|
1601
|
+
this.scrollToEnd({animated: true});
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1616
1604
|
};
|
|
1617
1605
|
// ]TODO(macOS GH#774)
|
|
1618
1606
|
|
|
@@ -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 {
|
|
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:
|
|
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 === '
|
|
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 === '
|
|
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 === '
|
|
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);
|
package/React/Base/RCTVersion.m
CHANGED
package/React/Views/RCTView.h
CHANGED
|
@@ -25,6 +25,10 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
|
|
|
25
25
|
|
|
26
26
|
- (BOOL)becomeFirstResponder;
|
|
27
27
|
- (BOOL)resignFirstResponder;
|
|
28
|
+
|
|
29
|
+
#if TARGET_OS_OSX
|
|
30
|
+
- (BOOL)handleKeyboardEvent:(NSEvent *)event;
|
|
31
|
+
#endif
|
|
28
32
|
// ]TODO(OSS Candidate ISS#2710739)
|
|
29
33
|
|
|
30
34
|
/**
|
package/React/Views/RCTView.m
CHANGED
|
@@ -1619,177 +1619,38 @@ setBorderColor() setBorderColor(Top) setBorderColor(Right) setBorderColor(Bottom
|
|
|
1619
1619
|
#pragma mark - Keyboard Events
|
|
1620
1620
|
|
|
1621
1621
|
#if TARGET_OS_OSX
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
NSString
|
|
1625
|
-
NSString*
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
BOOL shiftKey = NO;
|
|
1631
|
-
BOOL controlKey = NO;
|
|
1632
|
-
BOOL optionKey = NO;
|
|
1633
|
-
BOOL commandKey = NO;
|
|
1634
|
-
BOOL numericPadKey = NO;
|
|
1635
|
-
BOOL helpKey = NO;
|
|
1636
|
-
BOOL functionKey = NO;
|
|
1637
|
-
// commonly used key short-cuts
|
|
1638
|
-
BOOL leftArrowKey = NO;
|
|
1639
|
-
BOOL rightArrowKey = NO;
|
|
1640
|
-
BOOL upArrowKey = NO;
|
|
1641
|
-
BOOL downArrowKey = NO;
|
|
1642
|
-
BOOL tabKeyPressed = NO;
|
|
1643
|
-
BOOL escapeKeyPressed = NO;
|
|
1644
|
-
NSString *key = event.charactersIgnoringModifiers;
|
|
1645
|
-
if ([key length] == 0) {
|
|
1646
|
-
return nil;
|
|
1647
|
-
}
|
|
1648
|
-
unichar const code = [key characterAtIndex:0];
|
|
1649
|
-
|
|
1650
|
-
// detect arrow key presses
|
|
1651
|
-
if (code == NSLeftArrowFunctionKey) {
|
|
1652
|
-
leftArrowKey = YES;
|
|
1653
|
-
} else if (code == NSRightArrowFunctionKey) {
|
|
1654
|
-
rightArrowKey = YES;
|
|
1655
|
-
} else if (code == NSUpArrowFunctionKey) {
|
|
1656
|
-
upArrowKey = YES;
|
|
1657
|
-
} else if (code == NSDownArrowFunctionKey) {
|
|
1658
|
-
downArrowKey = YES;
|
|
1659
|
-
}
|
|
1660
|
-
|
|
1661
|
-
// detect special key presses via the key code
|
|
1662
|
-
switch (event.keyCode) {
|
|
1663
|
-
case 48: // Tab
|
|
1664
|
-
tabKeyPressed = YES;
|
|
1665
|
-
break;
|
|
1666
|
-
case 53: // Escape
|
|
1667
|
-
escapeKeyPressed = YES;
|
|
1668
|
-
break;
|
|
1669
|
-
default:
|
|
1670
|
-
break;
|
|
1622
|
+
- (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
|
|
1623
|
+
BOOL keyDown = event.type == NSEventTypeKeyDown;
|
|
1624
|
+
NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
|
|
1625
|
+
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
|
|
1626
|
+
|
|
1627
|
+
// Only post events for keys we care about
|
|
1628
|
+
if (![validKeys containsObject:key]) {
|
|
1629
|
+
return nil;
|
|
1671
1630
|
}
|
|
1672
1631
|
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
} else if (event.modifierFlags & NSEventModifierFlagCommand) {
|
|
1683
|
-
commandKey = YES;
|
|
1684
|
-
} else if (event.modifierFlags & NSEventModifierFlagNumericPad) {
|
|
1685
|
-
numericPadKey = YES;
|
|
1686
|
-
} else if (event.modifierFlags & NSEventModifierFlagHelp) {
|
|
1687
|
-
helpKey = YES;
|
|
1688
|
-
} else if (event.modifierFlags & NSEventModifierFlagFunction) {
|
|
1689
|
-
functionKey = YES;
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
RCTViewKeyboardEvent *keyboardEvent = nil;
|
|
1693
|
-
// only post events for keys we care about
|
|
1694
|
-
if (downPress) {
|
|
1695
|
-
NSString *keyToReturn = [self keyIsValid:key left:leftArrowKey right:rightArrowKey up:upArrowKey down:downArrowKey tabKey:tabKeyPressed escapeKey:escapeKeyPressed validKeys:[self validKeysDown]];
|
|
1696
|
-
if (keyToReturn != nil) {
|
|
1697
|
-
keyboardEvent = [RCTViewKeyboardEvent keyDownEventWithReactTag:self.reactTag
|
|
1698
|
-
capsLockKey:capsLockKey
|
|
1699
|
-
shiftKey:shiftKey
|
|
1700
|
-
ctrlKey:controlKey
|
|
1701
|
-
altKey:optionKey
|
|
1702
|
-
metaKey:commandKey
|
|
1703
|
-
numericPadKey:numericPadKey
|
|
1704
|
-
helpKey:helpKey
|
|
1705
|
-
functionKey:functionKey
|
|
1706
|
-
leftArrowKey:leftArrowKey
|
|
1707
|
-
rightArrowKey:rightArrowKey
|
|
1708
|
-
upArrowKey:upArrowKey
|
|
1709
|
-
downArrowKey:downArrowKey
|
|
1710
|
-
key:keyToReturn];
|
|
1711
|
-
}
|
|
1712
|
-
} else {
|
|
1713
|
-
NSString *keyToReturn = [self keyIsValid:key left:leftArrowKey right:rightArrowKey up:upArrowKey down:downArrowKey tabKey:tabKeyPressed escapeKey:escapeKeyPressed validKeys:[self validKeysUp]];
|
|
1714
|
-
if (keyToReturn != nil) {
|
|
1715
|
-
keyboardEvent = [RCTViewKeyboardEvent keyUpEventWithReactTag:self.reactTag
|
|
1716
|
-
capsLockKey:capsLockKey
|
|
1717
|
-
shiftKey:shiftKey
|
|
1718
|
-
ctrlKey:controlKey
|
|
1719
|
-
altKey:optionKey
|
|
1720
|
-
metaKey:commandKey
|
|
1721
|
-
numericPadKey:numericPadKey
|
|
1722
|
-
helpKey:helpKey
|
|
1723
|
-
functionKey:functionKey
|
|
1724
|
-
leftArrowKey:leftArrowKey
|
|
1725
|
-
rightArrowKey:rightArrowKey
|
|
1726
|
-
upArrowKey:upArrowKey
|
|
1727
|
-
downArrowKey:downArrowKey
|
|
1728
|
-
key:keyToReturn];
|
|
1632
|
+
return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
- (BOOL)handleKeyboardEvent:(NSEvent *)event {
|
|
1636
|
+
if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
|
|
1637
|
+
RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event];
|
|
1638
|
+
if (keyboardEvent) {
|
|
1639
|
+
[_eventDispatcher sendEvent:keyboardEvent];
|
|
1640
|
+
return YES;
|
|
1729
1641
|
}
|
|
1730
1642
|
}
|
|
1731
|
-
return
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
// check if the user typed key matches a key we need to send an event for
|
|
1735
|
-
// translate key codes over to JS compatible keys
|
|
1736
|
-
- (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 {
|
|
1737
|
-
NSString *keyToReturn = key;
|
|
1738
|
-
|
|
1739
|
-
// Allow the flexibility of defining special keys in multiple ways
|
|
1740
|
-
BOOL enterKeyValidityCheck = [key isEqualToString:@"\r"] && ([validKeys containsObject:@"Enter"] || [validKeys containsObject:@"\r"]);
|
|
1741
|
-
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
|
|
1742
|
-
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
|
|
1743
|
-
BOOL leftArrowValidityCheck = [validKeys containsObject:leftArrowPressKey] && leftArrowPressed;
|
|
1744
|
-
BOOL rightArrowValidityCheck = [validKeys containsObject:rightArrowPressKey] && rightArrowPressed;
|
|
1745
|
-
BOOL upArrowValidityCheck = [validKeys containsObject:upArrowPressKey] && upArrowPressed;
|
|
1746
|
-
BOOL downArrowValidityCheck = [validKeys containsObject:downArrowPressKey] && downArrowPressed;
|
|
1747
|
-
|
|
1748
|
-
if (tabKeyValidityCheck) {
|
|
1749
|
-
keyToReturn = @"Tab";
|
|
1750
|
-
} else if (escapeKeyValidityCheck) {
|
|
1751
|
-
keyToReturn = @"Escape";
|
|
1752
|
-
} else if (enterKeyValidityCheck) {
|
|
1753
|
-
keyToReturn = @"Enter";
|
|
1754
|
-
} else if (leftArrowValidityCheck) {
|
|
1755
|
-
keyToReturn = leftArrowPressKey;
|
|
1756
|
-
} else if (rightArrowValidityCheck) {
|
|
1757
|
-
keyToReturn = rightArrowPressKey;
|
|
1758
|
-
} else if (upArrowValidityCheck) {
|
|
1759
|
-
keyToReturn = upArrowPressKey;
|
|
1760
|
-
} else if (downArrowValidityCheck) {
|
|
1761
|
-
keyToReturn = downArrowPressKey;
|
|
1762
|
-
} else if (![validKeys containsObject:key]) {
|
|
1763
|
-
keyToReturn = nil;
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
return keyToReturn;
|
|
1643
|
+
return NO;
|
|
1767
1644
|
}
|
|
1768
1645
|
|
|
1769
1646
|
- (void)keyDown:(NSEvent *)event {
|
|
1770
|
-
if (self
|
|
1771
|
-
[super keyDown:event];
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event downPress:YES];
|
|
1776
|
-
if (keyboardEvent != nil) {
|
|
1777
|
-
[_eventDispatcher sendEvent:keyboardEvent];
|
|
1778
|
-
} else {
|
|
1647
|
+
if (![self handleKeyboardEvent:event]) {
|
|
1779
1648
|
[super keyDown:event];
|
|
1780
1649
|
}
|
|
1781
1650
|
}
|
|
1782
1651
|
|
|
1783
1652
|
- (void)keyUp:(NSEvent *)event {
|
|
1784
|
-
if (self
|
|
1785
|
-
[super keyUp:event];
|
|
1786
|
-
return;
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event downPress:NO];
|
|
1790
|
-
if (keyboardEvent != nil) {
|
|
1791
|
-
[_eventDispatcher sendEvent:keyboardEvent];
|
|
1792
|
-
} else {
|
|
1653
|
+
if (![self handleKeyboardEvent:event]) {
|
|
1793
1654
|
[super keyUp:event];
|
|
1794
1655
|
}
|
|
1795
1656
|
}
|
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
+(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
@@ -490,18 +490,8 @@ RCT_EXPORT_VIEW_PROPERTY(onDragLeave, RCTDirectEventBlock)
|
|
|
490
490
|
RCT_EXPORT_VIEW_PROPERTY(onDrop, RCTDirectEventBlock)
|
|
491
491
|
RCT_EXPORT_VIEW_PROPERTY(onKeyDown, RCTDirectEventBlock) // macOS keyboard events
|
|
492
492
|
RCT_EXPORT_VIEW_PROPERTY(onKeyUp, RCTDirectEventBlock) // macOS keyboard events
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if ([view respondsToSelector:@selector(setValidKeysDown:)]) {
|
|
496
|
-
view.validKeysDown = [RCTConvert NSArray:json];
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
RCT_CUSTOM_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>, RCTView)
|
|
500
|
-
{
|
|
501
|
-
if ([view respondsToSelector:@selector(setValidKeysUp:)]) {
|
|
502
|
-
view.validKeysUp = [RCTConvert NSArray:json];
|
|
503
|
-
}
|
|
504
|
-
}
|
|
493
|
+
RCT_EXPORT_VIEW_PROPERTY(validKeysDown, NSArray<NSString*>)
|
|
494
|
+
RCT_EXPORT_VIEW_PROPERTY(validKeysUp, NSArray<NSString*>)
|
|
505
495
|
#endif // ]TODO(macOS GH#774)
|
|
506
496
|
#if TARGET_OS_OSX // [TODO(macOS GH#768)
|
|
507
497
|
RCT_CUSTOM_VIEW_PROPERTY(nextKeyViewTag, NSNumber, RCTView)
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
@property (nonatomic, copy) RCTDirectEventBlock onScrollEndDrag;
|
|
66
66
|
@property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollBegin;
|
|
67
67
|
@property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollEnd;
|
|
68
|
-
@property (nonatomic, copy) RCTDirectEventBlock onScrollKeyDown; // TODO(macOS GH#774)
|
|
69
68
|
@property (nonatomic, copy) RCTDirectEventBlock onPreferredScrollerStyleDidChange; // TODO(macOS GH#774)
|
|
70
69
|
|
|
71
70
|
- (void)flashScrollIndicators; // TODO(macOS GH#774)
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|
#if !TARGET_OS_OSX // TODO(macOS GH#774)
|
|
25
25
|
#import "RCTRefreshControl.h"
|
|
26
|
+
#else
|
|
27
|
+
#import "RCTViewKeyboardEvent.h"
|
|
26
28
|
#endif // TODO(macOS GH#774)
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -1261,74 +1263,58 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidScrollToTop, onScrollToTop)
|
|
|
1261
1263
|
}];
|
|
1262
1264
|
}
|
|
1263
1265
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
- (NSString*)keyCommandFromKeyCode:(NSInteger)keyCode modifierFlags:(NSEventModifierFlags)modifierFlags
|
|
1267
|
-
{
|
|
1268
|
-
switch (keyCode)
|
|
1269
|
-
{
|
|
1270
|
-
case 36:
|
|
1271
|
-
return @"ENTER";
|
|
1272
|
-
|
|
1273
|
-
case 115:
|
|
1274
|
-
return @"HOME";
|
|
1275
|
-
|
|
1276
|
-
case 116:
|
|
1277
|
-
return @"PAGE_UP";
|
|
1278
|
-
|
|
1279
|
-
case 119:
|
|
1280
|
-
return @"END";
|
|
1281
|
-
|
|
1282
|
-
case 121:
|
|
1283
|
-
return @"PAGE_DOWN";
|
|
1284
|
-
|
|
1285
|
-
case 123:
|
|
1286
|
-
return @"LEFT_ARROW";
|
|
1287
|
-
|
|
1288
|
-
case 124:
|
|
1289
|
-
return @"RIGHT_ARROW";
|
|
1266
|
+
// [TODO(macOS GH#774)
|
|
1267
|
+
#pragma mark - Keyboard Events
|
|
1290
1268
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1269
|
+
#if TARGET_OS_OSX
|
|
1270
|
+
- (RCTViewKeyboardEvent*)keyboardEvent:(NSEvent*)event {
|
|
1271
|
+
BOOL keyDown = event.type == NSEventTypeKeyDown;
|
|
1272
|
+
NSArray<NSString *> *validKeys = keyDown ? self.validKeysDown : self.validKeysUp;
|
|
1273
|
+
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
|
|
1274
|
+
|
|
1275
|
+
// Only post events for keys we care about
|
|
1276
|
+
if (![validKeys containsObject:key]) {
|
|
1277
|
+
return nil;
|
|
1278
|
+
}
|
|
1297
1279
|
|
|
1298
|
-
|
|
1299
|
-
if (modifierFlags & NSEventModifierFlagOption) {
|
|
1300
|
-
return @"OPTION_UP";
|
|
1301
|
-
} else {
|
|
1302
|
-
return @"UP_ARROW";
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
return @"";
|
|
1280
|
+
return [RCTViewKeyboardEvent keyEventFromEvent:event reactTag:self.reactTag];
|
|
1306
1281
|
}
|
|
1307
1282
|
|
|
1308
|
-
- (
|
|
1309
|
-
{
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
RCT_SEND_SCROLL_EVENT(onScrollKeyDown, (@{ @"key": keyCommand}));
|
|
1315
|
-
} else {
|
|
1316
|
-
[super keyDown:theEvent];
|
|
1283
|
+
- (BOOL)handleKeyboardEvent:(NSEvent *)event {
|
|
1284
|
+
if (event.type == NSEventTypeKeyDown ? self.onKeyDown : self.onKeyUp) {
|
|
1285
|
+
RCTViewKeyboardEvent *keyboardEvent = [self keyboardEvent:event];
|
|
1286
|
+
if (keyboardEvent) {
|
|
1287
|
+
[_eventDispatcher sendEvent:keyboardEvent];
|
|
1288
|
+
return YES;
|
|
1317
1289
|
}
|
|
1318
1290
|
}
|
|
1291
|
+
return NO;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
- (void)keyDown:(NSEvent *)event {
|
|
1295
|
+
if (![self handleKeyboardEvent:event]) {
|
|
1296
|
+
[super keyDown:event];
|
|
1297
|
+
|
|
1298
|
+
// AX: if a tab key was pressed and the first responder is currently clipped by the scroll view,
|
|
1299
|
+
// automatically scroll to make the view visible to make it navigable via keyboard.
|
|
1300
|
+
NSString *key = [RCTViewKeyboardEvent keyFromEvent:event];
|
|
1301
|
+
if ([key isEqualToString:@"Tab"]) {
|
|
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
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1319
1313
|
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
if ([firstResponder isKindOfClass:[NSView class]] &&
|
|
1325
|
-
[firstResponder isDescendantOf:[_scrollView documentView]]) {
|
|
1326
|
-
NSView *view = (NSView*)firstResponder;
|
|
1327
|
-
NSRect visibleRect = ([view superview] == [_scrollView documentView]) ? NSInsetRect(view.frame, -1, -1) :
|
|
1328
|
-
[view convertRect:view.frame toView:_scrollView.documentView];
|
|
1329
|
-
[[_scrollView documentView] scrollRectToVisible:visibleRect];
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1314
|
+
- (void)keyUp:(NSEvent *)event {
|
|
1315
|
+
if (![self handleKeyboardEvent:event]) {
|
|
1316
|
+
[super keyUp:event];
|
|
1317
|
+
}
|
|
1332
1318
|
}
|
|
1333
1319
|
|
|
1334
1320
|
static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
|
|
@@ -1343,7 +1329,8 @@ static NSString *RCTStringForScrollerStyle(NSScrollerStyle scrollerStyle) {
|
|
|
1343
1329
|
- (void)preferredScrollerStyleDidChange:(__unused NSNotification *)notification {
|
|
1344
1330
|
RCT_SEND_SCROLL_EVENT(onPreferredScrollerStyleDidChange, (@{ @"preferredScrollerStyle": RCTStringForScrollerStyle([NSScroller preferredScrollerStyle])}));
|
|
1345
1331
|
}
|
|
1346
|
-
#endif
|
|
1332
|
+
#endif
|
|
1333
|
+
// ]TODO(macOS GH#774)
|
|
1347
1334
|
|
|
1348
1335
|
// Note: setting several properties of UIScrollView has the effect of
|
|
1349
1336
|
// resetting its contentOffset to {0, 0}. To prevent this, we generate
|
|
@@ -99,7 +99,6 @@ RCT_EXPORT_VIEW_PROPERTY(onScrollToTop, RCTDirectEventBlock)
|
|
|
99
99
|
RCT_EXPORT_VIEW_PROPERTY(onScrollEndDrag, RCTDirectEventBlock)
|
|
100
100
|
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollBegin, RCTDirectEventBlock)
|
|
101
101
|
RCT_EXPORT_VIEW_PROPERTY(onMomentumScrollEnd, RCTDirectEventBlock)
|
|
102
|
-
RCT_EXPORT_OSX_VIEW_PROPERTY(onScrollKeyDown, RCTDirectEventBlock) // TODO(macOS GH#774)
|
|
103
102
|
RCT_EXPORT_OSX_VIEW_PROPERTY(onPreferredScrollerStyleDidChange, RCTDirectEventBlock) // TODO(macOS GH#774)
|
|
104
103
|
RCT_EXPORT_VIEW_PROPERTY(inverted, BOOL)
|
|
105
104
|
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* in a CODEGEN_CONFIG_FILENAME file.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
const {
|
|
19
|
+
const {execFileSync} = require('child_process');
|
|
20
20
|
const fs = require('fs');
|
|
21
21
|
const os = require('os');
|
|
22
22
|
const path = require('path');
|
|
@@ -185,14 +185,16 @@ function main(appRootDir, outputPath) {
|
|
|
185
185
|
console.log(
|
|
186
186
|
'\n\n[Codegen] >>>>> Building react-native-codegen package',
|
|
187
187
|
);
|
|
188
|
-
|
|
188
|
+
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
189
|
+
execFileSync('yarn', ['install'], {
|
|
189
190
|
cwd: codegenCliPath,
|
|
190
191
|
stdio: 'inherit',
|
|
191
192
|
});
|
|
192
|
-
|
|
193
|
+
execFileSync('yarn', ['build'], {
|
|
193
194
|
cwd: codegenCliPath,
|
|
194
195
|
stdio: 'inherit',
|
|
195
196
|
});
|
|
197
|
+
// ]TODO(macOS GH#774)
|
|
196
198
|
}
|
|
197
199
|
} else if (fs.existsSync(CODEGEN_NPM_PATH)) {
|
|
198
200
|
codegenCliPath = CODEGEN_NPM_PATH;
|
|
@@ -235,8 +237,7 @@ function main(appRootDir, outputPath) {
|
|
|
235
237
|
console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
|
|
236
238
|
// Generate one schema for the entire library...
|
|
237
239
|
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
238
|
-
execFileSync(
|
|
239
|
-
'node',
|
|
240
|
+
execFileSync('node', [
|
|
240
241
|
path.join(
|
|
241
242
|
codegenCliPath,
|
|
242
243
|
'lib',
|
|
@@ -246,17 +247,17 @@ function main(appRootDir, outputPath) {
|
|
|
246
247
|
),
|
|
247
248
|
pathToSchema,
|
|
248
249
|
pathToJavaScriptSources,
|
|
249
|
-
); // ]TODO(macOS GH#774)
|
|
250
|
+
]); // ]TODO(macOS GH#774)
|
|
250
251
|
console.log(`[Codegen] Generated schema: ${pathToSchema}`);
|
|
251
252
|
|
|
252
253
|
// ...then generate native code artifacts.
|
|
254
|
+
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
253
255
|
const libraryTypeArg = library.config.type
|
|
254
|
-
?
|
|
255
|
-
:
|
|
256
|
+
? ['--libraryType', library.config.type]
|
|
257
|
+
: null; // ]TODO(macOS GH#774)
|
|
256
258
|
fs.mkdirSync(pathToTempOutputDir, {recursive: true});
|
|
257
259
|
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
258
|
-
execFileSync(
|
|
259
|
-
'node',
|
|
260
|
+
execFileSync('node', [
|
|
260
261
|
path.join(RN_ROOT, 'scripts', 'generate-specs-cli.js'),
|
|
261
262
|
'--platform',
|
|
262
263
|
'ios',
|
|
@@ -266,13 +267,17 @@ function main(appRootDir, outputPath) {
|
|
|
266
267
|
pathToTempOutputDir,
|
|
267
268
|
'--libraryName',
|
|
268
269
|
library.config.name,
|
|
269
|
-
libraryTypeArg,
|
|
270
|
-
); // ]TODO(macOS GH#774)
|
|
270
|
+
...libraryTypeArg,
|
|
271
|
+
]); // ]TODO(macOS GH#774)
|
|
271
272
|
|
|
272
273
|
// Finally, copy artifacts to the final output directory.
|
|
273
274
|
fs.mkdirSync(pathToOutputDirIOS, {recursive: true});
|
|
274
275
|
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
275
|
-
execFileSync('cp',
|
|
276
|
+
execFileSync('cp', [
|
|
277
|
+
'-R',
|
|
278
|
+
path.join(pathToTempOutputDir, '/'),
|
|
279
|
+
pathToOutputDirIOS,
|
|
280
|
+
]); // ]TODO(macOS GH#774)
|
|
276
281
|
console.log(`[Codegen] Generated artifacts: ${pathToOutputDirIOS}`);
|
|
277
282
|
|
|
278
283
|
// Filter the react native core library out.
|
|
@@ -295,16 +300,15 @@ function main(appRootDir, outputPath) {
|
|
|
295
300
|
// Generate FabricComponentProvider.
|
|
296
301
|
// Only for iOS at this moment.
|
|
297
302
|
// [TODO(macOS GH#774) - use execFileSync to help keep shell commands clean
|
|
298
|
-
execFileSync(
|
|
299
|
-
'node',
|
|
303
|
+
execFileSync('node', [
|
|
300
304
|
path.join(RN_ROOT, 'scripts', 'generate-provider-cli.js'),
|
|
301
305
|
'--platform',
|
|
302
306
|
'ios',
|
|
303
|
-
'--
|
|
307
|
+
'--schemaListPath',
|
|
304
308
|
schemaListTmpPath,
|
|
305
309
|
'--outputDir',
|
|
306
310
|
iosOutputDir,
|
|
307
|
-
); // ]TODO(macOS GH#774)
|
|
311
|
+
]); // ]TODO(macOS GH#774)
|
|
308
312
|
console.log(`Generated provider in: ${iosOutputDir}`);
|
|
309
313
|
}
|
|
310
314
|
} catch (err) {
|