Skip to content

Commit

Permalink
Optional anchoring (#213)
Browse files Browse the repository at this point in the history
* remove requestAnimationFrame polyfill

* Adding option to disable anchoring
  • Loading branch information
naqvitalha authored and muskeinsingh committed Jul 20, 2018
1 parent 3a25674 commit 026e96c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recyclerlistview",
"version": "1.4.0-beta.9",
"version": "1.4.0-beta.10",
"description": "The listview that you need and deserve. It was built for performance, uses cell recycling to achieve smooth scrolling.",
"main": "dist/reactnative/index.js",
"types": "dist/reactnative/index.d.ts",
Expand Down
6 changes: 5 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
if (forceFullRender || this.props.layoutProvider !== newProps.layoutProvider || this.props.isHorizontal !== newProps.isHorizontal) {
//TODO:Talha use old layout manager
this._virtualRenderer.setLayoutManager(newProps.layoutProvider.newLayoutManager(this._layout, newProps.isHorizontal));
this._virtualRenderer.refreshWithAnchor();
if (newProps.layoutProvider.shouldRefreshWithAnchoring) {
this._virtualRenderer.refreshWithAnchor();
} else {
this._virtualRenderer.refresh();
}
this._refreshViewability();
} else if (this.props.dataProvider !== newProps.dataProvider) {
const layoutManager = this._virtualRenderer.getLayoutManager();
Expand Down
6 changes: 4 additions & 2 deletions src/core/dependencies/LayoutProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { Layout, WrapGridLayoutManager, LayoutManager } from "../layoutmanager/L
*/

export abstract class BaseLayoutProvider {
//Unset if your new layout provider doesn't require firstVisibleIndex preservation on application
public shouldRefreshWithAnchoring: boolean = true;

//Return your layout manager, you get all required dependencies here. Also, make sure to use cachedLayouts. RLV might cache layouts and give back to
//in cases of conxtext preservation. Make sure you use them if provided.
public abstract newLayoutManager(renderWindowSize: Dimension, isHorizontal?: boolean, cachedLayouts?: Layout[]): LayoutManager;
Expand All @@ -34,8 +37,7 @@ export class LayoutProvider extends BaseLayoutProvider {
private _tempDim: Dimension;
private _lastLayoutManager: WrapGridLayoutManager | undefined;

constructor(getLayoutTypeForIndex: (index: number) => string | number,
setLayoutForType: (type: string | number, dim: Dimension, index: number) => void) {
constructor(getLayoutTypeForIndex: (index: number) => string | number, setLayoutForType: (type: string | number, dim: Dimension, index: number) => void) {
super();
this._getLayoutTypeForIndex = getLayoutTypeForIndex;
this._setLayoutForType = setLayoutForType;
Expand Down

0 comments on commit 026e96c

Please sign in to comment.