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 horizontal recyclerlistview in android RTL #753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
this._pendingScrollToOffset = offset;
}, (index) => {
return this.props.dataProvider.getStableId(index);
}, !props.disableRecycling);
}, !props.disableRecycling, props.dataProvider.getSize());

if (this.props.windowCorrectionConfig) {
let windowCorrection;
Expand Down
21 changes: 14 additions & 7 deletions src/core/ViewabilityTracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BinarySearch from "../utils/BinarySearch";
import { Dimension } from "./dependencies/LayoutProvider";
import { Layout } from "./layoutmanager/LayoutManager";
import { I18nManager, Platform } from "react-native";
/***
* Given an offset this utility can compute visible items. Also tracks previously visible items to compute items which get hidden or visible
* Virtual renderer uses callbacks from this utility to main recycle pool and the render stack.
Expand Down Expand Up @@ -38,8 +39,9 @@ export default class ViewabilityTracker {
private _layouts: Layout[] = [];
private _actualOffset: number;
private _defaultCorrection: WindowCorrection;
private _itemsCount: number;

constructor(renderAheadOffset: number, initialOffset: number) {
constructor(renderAheadOffset: number, initialOffset: number, itemsCount: number) {
this._currentOffset = Math.max(0, initialOffset);
this._maxOffset = 0;
this._actualOffset = 0;
Expand All @@ -58,6 +60,7 @@ export default class ViewabilityTracker {

this._relevantDim = { start: 0, end: 0 };
this._defaultCorrection = { startCorrection: 0, endCorrection: 0, windowShift: 0 };
this._itemsCount = itemsCount;
}

public init(windowCorrection: WindowCorrection): void {
Expand Down Expand Up @@ -241,22 +244,26 @@ export default class ViewabilityTracker {
newEngagedIndexes: number[]): boolean {
const itemRect = this._layouts[index];
let isFound = false;
const newIndex =
I18nManager.isRTL && Platform.OS === "android"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
I18nManager.isRTL && Platform.OS === "android"
I18nManager.isRTL && Platform.OS === "android" && this._isHorizontal

To not mess up the vertical lists we need to make sure this check only applies to horizontal scrollview

? this._itemsCount - 1 - index
: index;
this._setRelevantBounds(itemRect, relevantDim);
if (this._itemIntersectsVisibleWindow(relevantDim.start, relevantDim.end)) {
if (insertOnTop) {
newVisibleIndexes.splice(0, 0, index);
newEngagedIndexes.splice(0, 0, index);
newVisibleIndexes.splice(0, 0, newIndex);
newEngagedIndexes.splice(0, 0, newIndex);
} else {
newVisibleIndexes.push(index);
newEngagedIndexes.push(index);
newVisibleIndexes.push(newIndex);
newEngagedIndexes.push(newIndex);
}
isFound = true;
} else if (this._itemIntersectsEngagedWindow(relevantDim.start, relevantDim.end)) {
//TODO: This needs to be optimized
if (insertOnTop) {
newEngagedIndexes.splice(0, 0, index);
newEngagedIndexes.splice(0, 0, newIndex);
} else {
newEngagedIndexes.push(index);
newEngagedIndexes.push(newIndex);

}
isFound = true;
Expand Down
11 changes: 8 additions & 3 deletions src/core/VirtualRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ export default class VirtualRenderer {
private _viewabilityTracker: ViewabilityTracker | null = null;
private _dimensions: Dimension | null;
private _optimizeForAnimations: boolean = false;
private _itemsCount: number;

constructor(renderStackChanged: (renderStack: RenderStack) => void,
scrollOnNextUpdate: (point: Point) => void,
fetchStableId: StableIdProvider,
isRecyclingEnabled: boolean) {
isRecyclingEnabled: boolean,
itemsCount: number) {
//Keeps track of items that need to be rendered in the next render cycle
this._renderStack = {};

Expand All @@ -78,6 +80,8 @@ export default class VirtualRenderer {
this._startKey = 0;

this.onVisibleItemsChanged = null;

this._itemsCount = itemsCount;
}

public getLayoutDimension(): Dimension {
Expand Down Expand Up @@ -192,9 +196,10 @@ export default class VirtualRenderer {
if (this._params) {
this._viewabilityTracker = new ViewabilityTracker(
Default.value<number>(this._params.renderAheadOffset, 0),
Default.value<number>(this._params.initialOffset, 0));
Default.value<number>(this._params.initialOffset, 0),
this._itemsCount);
} else {
this._viewabilityTracker = new ViewabilityTracker(0, 0);
this._viewabilityTracker = new ViewabilityTracker(0, 0, this._itemsCount);
}
this._prepareViewabilityTracker();
}
Expand Down