Skip to content

Commit

Permalink
Final Sticky Changes (#304)
Browse files Browse the repository at this point in the history
* import was not from web (#299)

* CR changes.

* Throwing exceptions for visibleIndexes and array sort.

* Handling index 0 cases.

* Updated doc with errors.
  • Loading branch information
ananyachandra14 authored and naqvitalha committed Feb 11, 2019
1 parent e59588a commit 6f2e80c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/guides/samplecode/web/Sample1.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A scrollable list with different item type
*/
import React, {Component} from 'react';
import {RecyclerListView, DataProvider, LayoutProvider} from 'recyclerlistview';
import {RecyclerListView, DataProvider, LayoutProvider} from 'recyclerlistview/web';

const ViewTypes = {
FULL: 0,
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/sticky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
All you need to do to get started is wrap your `RecyclerListView` component with the `StickyContainer` component and pass either or both `stickyHeaderIndices` and `stickyFooterIndices`.

### 1) Important points to note
* `stickyHeaderIndices` and `stickyFooterIndices` should be sorted arrays, otherwise behaviour will be unexpected.
* `StickyContainer` should have a single child component of type `RecyclerListView` or any that extends it.
* In your `RecyclerListView` component, pass ref as a function and not as a string.
* `stickyHeaderIndices` and `stickyFooterIndices` should be sorted arrays, otherwise error will be thrown.
* `StickyContainer` should have a single child component of type `RecyclerListView` or any that extends it, otherwise error will be thrown.
* In your `RecyclerListView` component, pass ref as a function and not as a string, otherwise error will be thrown.
```js
<RecyclerListView ref={this._setRef}/>

Expand Down
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.16",
"version": "2.0.0-beta.2",
"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
2 changes: 0 additions & 2 deletions scripts/publish-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
set -e

TARGET=$"/Users/talha.naqvi/Documents/Work/RLV-Demo/node_modules/recyclerlistview/dist" #target-path
#TARGET=$"/Users/ananya.chandra/Documents/ReactNativeRepos/ts-rex/node_modules/recyclerlistview/dist" #target-path
#TARGET=$"/Users/ananya.chandra/Documents/ReactNativeRepos/ugc-react-native/node_modules/recyclerlistview/dist" #target-path

npm run build

Expand Down
4 changes: 2 additions & 2 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
this._virtualRenderer.removeVisibleItemsListener();
}
if (this.props.onVisibleIndexesChanged) {
console.warn(Messages.VISIBLE_INDEXES_CHANGED_DEPRECATED); //tslint:disable-line
throw new CustomError(RecyclerListViewExceptions.usingOldVisibleIndexesChangedParam);
}
if (this.props.onVisibleIndicesChanged) {
this._virtualRenderer.attachVisibleItemsListener(this.props.onVisibleIndicesChanged!);
Expand Down Expand Up @@ -441,7 +441,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
private _initTrackers(): void {
this._assertDependencyPresence(this.props);
if (this.props.onVisibleIndexesChanged) {
console.warn(Messages.VISIBLE_INDEXES_CHANGED_DEPRECATED); //tslint:disable-line
throw new CustomError(RecyclerListViewExceptions.usingOldVisibleIndexesChangedParam);
}
if (this.props.onVisibleIndicesChanged) {
this._virtualRenderer.attachVisibleItemsListener(this.props.onVisibleIndicesChanged!);
Expand Down
8 changes: 8 additions & 0 deletions src/core/exceptions/RecyclerListViewExceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ const RecyclerListViewExceptions: {[key: string]: Exception} = {
message: "StickyContainer can only have a single child of type RecyclerListView.",
type: "WrongStickyChildTypeException",
},
usingOldVisibleIndexesChangedParam: {
message: "onVisibleIndexesChanged has been deprecated. Please use onVisibleIndicesChanged instead.",
type: "usingOldVisibleIndexesChangedParam",
},
stickyIndicesArraySortError: {
message: "The sticky indices array passed to StickyContainer isn't sorted in ascending order.",
type: "stickyIndicesArraySortError",
},
};
export default RecyclerListViewExceptions;
18 changes: 13 additions & 5 deletions src/core/sticky/StickyObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as React from "react";
import {Animated, StyleProp, ViewStyle} from "react-native";
import {Layout} from "../layoutmanager/LayoutManager";
import {Dimension} from "../dependencies/LayoutProvider";
import RecyclerListViewExceptions from "../exceptions/RecyclerListViewExceptions";
import CustomError from "../exceptions/CustomError";

export enum StickyType {
HEADER,
Expand Down Expand Up @@ -104,7 +106,10 @@ export default abstract class StickyObject<P extends StickyObjectProps, S extend
this._initParams();
this._offsetY = offsetY;
this.boundaryProcessing(offsetY, this.props.getDistanceFromWindow(), this._windowBound);
if (this._previousStickyIndex) {
if (this._previousStickyIndex !== undefined) {
if (this._previousStickyIndex * this.stickyTypeMultiplier >= this.currentStickyIndex * this.stickyTypeMultiplier) {
throw new CustomError(RecyclerListViewExceptions.stickyIndicesArraySortError);
}
const scrollY: number | undefined = this.getScrollY(offsetY, this._scrollableHeight);
if (this._previousHeight && this._currentYd && scrollY && scrollY < this._currentYd) {
if (scrollY > this._currentYd - this._previousHeight) {
Expand All @@ -118,7 +123,10 @@ export default abstract class StickyObject<P extends StickyObjectProps, S extend
this._stickyViewOffset.setValue(0);
}
}
if (this._nextStickyIndex) {
if (this._nextStickyIndex !== undefined) {
if (this._nextStickyIndex * this.stickyTypeMultiplier <= this.currentStickyIndex * this.stickyTypeMultiplier) {
throw new CustomError(RecyclerListViewExceptions.stickyIndicesArraySortError);
}
const scrollY: number | undefined = this.getScrollY(offsetY, this._scrollableHeight);
if (this._currentHeight && this._nextYd && scrollY && scrollY + this._currentHeight > this._nextYd) {
if (scrollY <= this._nextYd) {
Expand Down Expand Up @@ -182,17 +190,17 @@ export default abstract class StickyObject<P extends StickyObjectProps, S extend
this.currentStickyIndex = stickyIndices[this.currentIndex];
this._previousStickyIndex = stickyIndices[this.currentIndex - this.stickyTypeMultiplier];
this._nextStickyIndex = stickyIndices[this.currentIndex + this.stickyTypeMultiplier];
if (this.currentStickyIndex) {
if (this.currentStickyIndex !== undefined) {
this._currentLayout = this.props.getLayoutForIndex(this.currentStickyIndex);
this._currentY = this._currentLayout ? this._currentLayout.y : undefined;
this._currentHeight = this._currentLayout ? this._currentLayout.height : undefined;
this._currentYd = this._currentY && this._currentHeight ? this.getCurrentYd(this._currentY, this._currentHeight) : undefined;
}
if (this._previousStickyIndex) {
if (this._previousStickyIndex !== undefined) {
this._previousLayout = this.props.getLayoutForIndex(this._previousStickyIndex);
this._previousHeight = this._previousLayout ? this._previousLayout.height : undefined;
}
if (this._nextStickyIndex) {
if (this._nextStickyIndex !== undefined) {
this._nextLayout = this.props.getLayoutForIndex(this._nextStickyIndex);
this._nextY = this._nextLayout ? this._nextLayout.y : undefined;
this._nextHeight = this._nextLayout ? this._nextLayout.height : undefined;
Expand Down

0 comments on commit 6f2e80c

Please sign in to comment.