Skip to content

Commit

Permalink
Right align scrollToIndex in RTL
Browse files Browse the repository at this point in the history
Summary:
This fixes up behavior on Android so that `scrollToIndex` aligns the right edge of the cell of the given index to the right edge of the scrollview viewport. We do not incorporate RTL on iOS which inverts x/y coordinates from scroller (but not layout).

Changelog:
[General][Fixed] - Right align scrollToIndex in RTL

Differential Revision: D47978637

fbshipit-source-id: 4548098b755d40102a5442bed81deef94a8e39d6
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Aug 2, 2023
1 parent 8e6bc9e commit 655171a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,24 +1492,24 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
...
}>,
): number {
let offset = this._selectOffset(metrics);

const {horizontal, rtl} = this._orientation();
if (horizontal && rtl && Platform.OS !== 'ios') {
offset = this._selectLength(contentSize) - offset;
if (Platform.OS === 'ios' || !(horizontal && rtl)) {
return this._selectOffset(metrics);
}

return offset;
return this._selectLength(contentSize) - this._selectOffset(metrics);
}

_cartesianScrollOffset(offset: number): {x?: number, y?: number} {
const {horizontal, rtl} = this._orientation();
const normalizedOffset =
horizontal && rtl && Platform.OS !== 'ios'
? this._listMetrics.getContentLength() - offset
: offset;
if (Platform.OS === 'ios' || !(horizontal && rtl)) {
return horizontal ? {x: offset} : {y: offset};
}

const cartOffset = this._listMetrics.cartesianOffset(normalizedOffset);
// Add the visible length of the scrollview so that the offset is right-aligned
const cartOffset = this._listMetrics.cartesianOffset(
offset + this._scrollMetrics.visibleLength,
);
return horizontal ? {x: cartOffset} : {y: cartOffset};
}

Expand Down

0 comments on commit 655171a

Please sign in to comment.