Skip to content

Commit

Permalink
Merge 407fb99 into 2478f9a
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jan 31, 2019
2 parents 2478f9a + 407fb99 commit c2995dd
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 22 deletions.
2 changes: 2 additions & 0 deletions packages/react-infinitegrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
A react component that can easily use [egjs-infinitegrid](https://github.com/naver/egjs-infinitegrid)

* [GridLayout Demo](https://codesandbox.io/s/030opyqkvw)
* [GridLayout with Parallax Demo](https://codesandbox.io/s/v3y0jr2ony)
* [JustifiedLayout Demo(typescript)](https://codesandbox.io/s/5w7vrr0kwk)
* [Youtube Demo](https://codesandbox.io/s/935xz7zy8r)
* [API Documentation](https://github.com/naver/egjs-infinitegrid/wiki/react-infinitegrid-API-documentation)


## Install
```bash
$ npm install @egjs/react-infinitegrid --save
Expand Down
53 changes: 48 additions & 5 deletions packages/react-infinitegrid/declaration/InfiniteGrid.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import {IInfiniteGridItem} from "@egjs/infinitegrid";

interface InfiniteGridProps {
tag?: string,
Expand All @@ -13,21 +14,63 @@ interface InfiniteGridProps {
horizontal?: boolean,
loading?: object | boolean,
transitionDuration?: number,
onAppend?: (param?: any) => void,
onPrepend?: (param?: any) => void,
onLayoutComplete?: (param?: any) => void,
onImageError?: (param?: any) => void,
onChange?: (param?: any) => void,
onAppend?: (param: OnAppendParameter) => void,
onPrepend?: (param: OnPrependParameter) => void,
onLayoutComplete?: (param: OnLayoutCompleteParameter) => void,
onImageError?: (param: any) => void,
onChange?: (param: OnChangeParameter) => void,
status?: object,
useFit?: boolean,
[others: string]: any,
}

interface OnAppendParameter {
currentTarget?: InfiniteGrid;
groupKey?: number | string;
startLoading?: (loadingStyle: object) => void;
endLoading?: (loadingStyle: object) => void;
}
interface OnPrependParameter {
currentTarget?: InfiniteGrid;
groupKey?: number | string;
startLoading?: (loadingStyle: object) => void;
endLoading?: (loadingStyle: object) => void;
}
interface OnChangeParameter {
currentTarget?: InfiniteGrid;
groupKey?: number | string;
isForward?: boolean;
horizontal?: boolean;
scrollPos?: number;
orgScrollPos?: number;
}
interface OnImageErrorParameter {
currentTarget?: InfiniteGrid;
target?: HTMLElement;
element?: HTMLElement;
item?: IInfiniteGridItem;
itemIndex?: number;
}
interface OnLayoutCompleteParameter {
currentTarget?: InfiniteGrid;
fromCache?: boolean;
target?: IInfiniteGridItem[];
isAppend?: boolean;
isTrusted?: boolean;
isLayout?: boolean;
isScroll?: boolean;
scrollPos?: number;
orgScrollPos?: number;
size?: number;
endLoading?: (loadginStyle: object) => void;
}

declare class InfiniteGrid extends React.Component<InfiniteGridProps> {
layout(isRelayout?: boolean): this;
resize(): this;
setStatus(status: object, applyScrollPos?: boolean): this;
getStatus(): object;
getItems(includeCached?: boolean): IInfiniteGridItem[];
clear(): this;
}
declare class GridLayout extends InfiniteGrid {}
Expand Down
21 changes: 10 additions & 11 deletions packages/react-infinitegrid/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/react-infinitegrid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egjs/react-infinitegrid",
"version": "1.3.0",
"version": "1.4.0-rc3",
"description": "A react component that can easily use egjs-infinitegrid",
"types": "declaration/index.d.ts",
"module": "dist/esm/index.js",
Expand All @@ -12,11 +12,11 @@
"license": "MIT",
"homepage": "https://github.com/naver/egjs-infinitegrid",
"dependencies": {
"@egjs/infinitegrid": "^3.5.1"
"@egjs/infinitegrid": "^3.5.2"
},
"peerDependencies": {
"react": "^15.4.2 || ^16.0.0",
"react-dom": "^15.4.2 || ^16.0.0"
"react": "^15.4.2 || ^16.0.0 || ^17.0.0",
"react-dom": "^15.4.2 || ^16.0.0 || 17.0.0"
},
"keywords": [
"react",
Expand Down
14 changes: 12 additions & 2 deletions packages/react-infinitegrid/src/InfiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ export default class InfiniteGrid extends Component {
this._renderer && this._renderer.destroy();
this._manager && this._manager.destroy();
}
getItems(includeCached) {
return includeCached ? this._items.pluck("items") : this._infinite.getVisibleItems();
}
getStatus(startKey = "", endKey = "") {
const state = Object.assign({}, this.state);
const datas = {};
Expand Down Expand Up @@ -654,6 +657,7 @@ export default class InfiniteGrid extends Component {
return;
}
this.props.onAppend({
currentTarget: this,
groupKey: this.state.endKey,
startLoading: loadingStyle => {
this.startLoading(true, loadingStyle);
Expand Down Expand Up @@ -701,6 +705,7 @@ export default class InfiniteGrid extends Component {
this._fit(true);
}
this.props.onPrepend({
currentTarget: this,
groupKey: this.state.startKey,
startLoading: loadingStyle => {
this.startLoading(false, loadingStyle);
Expand Down Expand Up @@ -797,12 +802,16 @@ export default class InfiniteGrid extends Component {
const component = group ? group.children[index] : -1;
const componentIndex = this.state.children.indexOf(component);

this.props.onImageError({target, element, item, itemIndex: componentIndex});
this.props.onImageError({
currentTarget: this, target, element, item, itemIndex: componentIndex,
});
},
});
}
_onCheck({isForward, scrollPos, horizontal, orgScrollPos}) {
this.props.onChange({isForward, horizontal, scrollPos, orgScrollPos});
this.props.onChange({
currentTarget: this, isForward, horizontal, scrollPos, orgScrollPos,
});
if (this._isProcessing()) {
return;
}
Expand Down Expand Up @@ -882,6 +891,7 @@ export default class InfiniteGrid extends Component {
this._infinite.recycle(scrollPos, isAppend);
}
this.props.onLayoutComplete({
currentTarget: this,
target: items,
fromCache,
isAppend,
Expand Down
39 changes: 39 additions & 0 deletions packages/react-infinitegrid/test/InfiniteGrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,45 @@ describe(`test layout`, function () {
});
}, 100);
});
it (`should check getItems method`, async() => {
// Given
this.el.style.width = "300px";
const rendered = ReactDOM.render(<GridLayout className="test1" align="center" isOverflowScroll={true} style={{height: "500px"}}>
<div style={{width: "120px", height: "100px"}}></div>
<div style={{width: "120px", height: "100px"}}></div>
<div style={{width: "120px", height: "200px"}}></div>
<div style={{width: "120px", height: "100px"}}></div>
<div style={{width: "120px", height: "400px"}}></div>
<div style={{width: "120px", height: "440px"}}></div>
<div style={{width: "120px", height: "130px"}}></div>
<div style={{width: "120px", height: "100px"}}></div>

<div data-groupkey="1" style={{width: "120px", height: "200px"}}></div>
<div data-groupkey="1" style={{width: "120px", height: "100px"}}></div>
<div data-groupkey="1" style={{width: "120px", height: "400px"}}></div>
<div data-groupkey="1" style={{width: "120px", height: "440px"}}></div>
<div data-groupkey="1" style={{width: "120px", height: "130px"}}></div>
<div data-groupkey="1" style={{width: "120px", height: "100px"}}></div>
</GridLayout>, this.el);

await wait();
// When
// all items
const items = rendered.getItems(true);

// group 0's items
const items2 = rendered.getItems();

// group 1's items
rendered._infinite.setCursor("start", 1);
rendered._infinite.setCursor("end", 1);
const items3 = rendered.getItems();

// Then
expect(items.length).to.be.equals(14);
expect(items2.length).to.be.equals(8);
expect(items3.length).to.be.equals(6);
});
it (`should check getStatus(startKey, endKey)`, async () => {
// Given
this.el.style.width = "300px";
Expand Down

0 comments on commit c2995dd

Please sign in to comment.