Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy and paste order bug created by inverted FlatList #2345

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ exports[`components/Text prop "numberOfLines" value is set 1`] = `

exports[`components/Text prop "numberOfLines" value is set to one 1`] = `
<div
class="css-text-901oao css-textMultiLine-cens5h"
class="css-text-901oao css-textOneLine-nfaoni"
dir="auto"
/>
`;
Expand Down
12 changes: 10 additions & 2 deletions packages/react-native-web/src/exports/Text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ const Text: React.AbstractComponent<TextProps, HTMLElement & PlatformMethods> =
const classList = [
classes.text,
hasTextAncestor === true && classes.textHasAncestor,
numberOfLines != null && classes.textMultiLine
numberOfLines === 1 && classes.textOneLine,
numberOfLines != null && numberOfLines > 1 && classes.textMultiLine
];
const style = [
props.style,
numberOfLines != null && { WebkitLineClamp: numberOfLines },
numberOfLines != null && numberOfLines > 1 && { WebkitLineClamp: numberOfLines },
selectable === true && styles.selectable,
selectable === false && styles.notSelectable,
onPress && styles.pressable
Expand Down Expand Up @@ -179,6 +180,13 @@ const classes = css.create({
font: 'inherit',
whiteSpace: 'inherit'
},
textOneLine: {
maxWidth: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'pre',
wordWrap: 'normal'
},
// See #13
textMultiLine: {
display: '-webkit-box',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ type State = {
class VirtualizedList extends React.PureComponent<Props, State> {
static contextType: typeof VirtualizedListContext = VirtualizedListContext;

pushOrUnshift(input: Array<any>, item: Item) {
if (this.props.inverted) {
input.unshift(item)
} else {
input.push(item)
}
}

// scrollToEnd may be janky without getItemLayout prop
scrollToEnd(params?: ?{animated?: ?boolean, ...}) {
const animated = params ? params.animated : true;
Expand Down Expand Up @@ -707,7 +715,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
);
} else if (this.props.onViewableItemsChanged) {
const onViewableItemsChanged = this.props.onViewableItemsChanged
this._viewabilityTuples.push({
this.pushOrUnshift(this._viewabilityTuples, {
viewabilityHelper: new ViewabilityHelper(this.props.viewabilityConfig),
onViewableItemsChanged,
});
Expand Down Expand Up @@ -807,9 +815,9 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const key = keyExtractor(item, ii);
this._indicesToKeys.set(ii, key);
if (stickyIndicesFromProps.has(ii + stickyOffset)) {
stickyHeaderIndices.push(cells.length);
this.pushOrUnshift(stickyHeaderIndices, cells.length);
}
cells.push(
this.pushOrUnshift(cells,
<CellRenderer
CellRendererComponent={CellRendererComponent}
ItemSeparatorComponent={ii < end ? ItemSeparatorComponent : undefined}
Expand Down Expand Up @@ -879,15 +887,15 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const stickyHeaderIndices = [];
if (ListHeaderComponent) {
if (stickyIndicesFromProps.has(0)) {
stickyHeaderIndices.push(0);
this.pushOrUnshift(stickyHeaderIndices, 0);
}
const element = React.isValidElement(ListHeaderComponent) ? (
ListHeaderComponent
) : (
// $FlowFixMe
<ListHeaderComponent />
);
cells.push(
this.pushOrUnshift(cells,
<VirtualizedListCellContextProvider
cellKey={this._getCellKey() + '-header'}
key="$header">
Expand Down Expand Up @@ -936,7 +944,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
stickyBlock.offset -
initBlock.offset -
(this.props.initialScrollIndex ? 0 : initBlock.length);
cells.push(
this.pushOrUnshift(cells,
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
* suppresses an error found when Flow v0.111 was deployed. To
* see the error, delete this comment and run Flow. */
Expand All @@ -953,7 +961,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const trailSpace =
this._getFrameMetricsApprox(first).offset -
(stickyBlock.offset + stickyBlock.length);
cells.push(
this.pushOrUnshift(cells,
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
* suppresses an error found when Flow v0.111 was deployed. To
* see the error, delete this comment and run Flow. */
Expand All @@ -969,7 +977,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
const firstSpace =
this._getFrameMetricsApprox(first).offset -
(initBlock.offset + initBlock.length);
cells.push(
this.pushOrUnshift(cells,
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment
* suppresses an error found when Flow v0.111 was deployed. To see
* the error, delete this comment and run Flow. */
Expand Down Expand Up @@ -1006,7 +1014,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
endFrame.offset +
endFrame.length -
(lastFrame.offset + lastFrame.length);
cells.push(
this.pushOrUnshift(cells,
/* $FlowFixMe(>=0.111.0 site=react_native_fb) This comment suppresses
* an error found when Flow v0.111 was deployed. To see the error,
* delete this comment and run Flow. */
Expand All @@ -1022,7 +1030,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
// $FlowFixMe
<ListEmptyComponent />
)): any);
cells.push(
this.pushOrUnshift(cells,
React.cloneElement(element, {
key: '$empty',
onLayout: event => {
Expand All @@ -1042,7 +1050,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
// $FlowFixMe
<ListFooterComponent />
);
cells.push(
this.pushOrUnshift(cells,
<VirtualizedListCellContextProvider
cellKey={this._getFooterCellKey()}
key="$footer">
Expand Down Expand Up @@ -1195,6 +1203,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {

_defaultRenderScrollComponent = props => {
const onRefresh = props.onRefresh;
const inversionStyle = this.props.inverted
? this.props.horizontal
? styles.rowReverse
: styles.columnReverse
: null;

if (this._isNestedWithSameOrientation()) {
// $FlowFixMe - Typing ReactNativeComponent revealed errors
return <View {...props} />;
Expand Down Expand Up @@ -1223,11 +1237,23 @@ class VirtualizedList extends React.PureComponent<Props, State> {
props.refreshControl
)
}
contentContainerStyle={StyleSheet.compose(
inversionStyle,
this.props.contentContainerStyle,
)}
/>
);
} else {
// $FlowFixMe Invalid prop usage
return <ScrollView {...props} />;
return (
<ScrollView
{...props}
contentContainerStyle={StyleSheet.compose(
inversionStyle,
this.props.contentContainerStyle,
)}
/>
);
}
};

Expand Down Expand Up @@ -1367,7 +1393,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
* error found when Flow v0.68 was deployed. To see the error delete this
* comment and run Flow. */
if (frame.inLayout) {
framesInLayout.push(frame);
this.pushOrUnshift(framesInLayout, frame);
}
}
const windowTop = this._getFrameMetricsApprox(this.state.first).offset;
Expand Down Expand Up @@ -1690,6 +1716,13 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._getFrameMetricsApprox,
this._scrollMetrics,
);

// revert the state if calculations are off
// this would only happen on the inverted flatlist (probably a bug with overscroll-behavior)
// when scrolled from bottom all the way up until onEndReached is triggered
if (newState.first === newState.last) {
newState = state
}
}
}
} else {
Expand Down