Skip to content

Commit

Permalink
Use right edge of ScrollView viewport for scrollMetrics.offset in RTL
Browse files Browse the repository at this point in the history
Summary:
The offset we record should be the one closest to the reference zero-point in the coordinate space. This makes scroller offset reference match the cell reference we keep in D47978631.

Changelog:
[General][Fixed] - Use right edge of ScrollView viewport for `scrollMetrics.offset` in RTL

bypass-github-export-checks

Reviewed By: lenaic

Differential Revision: D48132236

fbshipit-source-id: 3307081e5e859f1b4afbc15a84c5be1b33915206
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Aug 8, 2023
1 parent c0c4507 commit 0e69050
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1668,10 +1668,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
const timestamp = e.timeStamp;
let visibleLength = this._selectLength(e.nativeEvent.layoutMeasurement);
let contentLength = this._selectLength(e.nativeEvent.contentSize);
let offset = this._offsetFromScrollEvent(
e.nativeEvent.contentOffset,
e.nativeEvent.contentSize,
);
let offset = this._offsetFromScrollEvent(e);
let dOffset = offset - this._scrollMetrics.offset;

if (this._isNestedWithSameOrientation()) {
Expand Down Expand Up @@ -1735,24 +1732,18 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
this._scheduleCellsToRenderUpdate();
};

_offsetFromScrollEvent(
contentOffset: $ReadOnly<{
x: number,
y: number,
...
}>,
contentSize: $ReadOnly<{
width: number,
height: number,
...
}>,
): number {
_offsetFromScrollEvent(e: ScrollEvent): number {
const {contentOffset, contentSize, layoutMeasurement} = e.nativeEvent;
const {horizontal, rtl} = this._orientation();
if (Platform.OS === 'ios' || !(horizontal && rtl)) {
return this._selectOffset(contentOffset);
}

return this._selectLength(contentSize) - this._selectOffset(contentOffset);
return (
this._selectLength(contentSize) -
(this._selectOffset(contentOffset) +
this._selectLength(layoutMeasurement))
);
}

_scheduleCellsToRenderUpdate(opts?: {allowImmediateExecution?: boolean}) {
Expand Down

0 comments on commit 0e69050

Please sign in to comment.