add loop property & fix bug caused by renderPage cache

This commit is contained in:
王劲鹏 2020-04-09 16:58:47 +08:00 committed by osborn
parent d1f32b7f5c
commit c44c3e5353
12 changed files with 58 additions and 39 deletions

View File

@ -33,9 +33,10 @@ import pub.doric.async.AsyncResult;
import pub.doric.shader.ViewNode;
/**
* @Description: com.github.penfeizhou.doric.widget
* @Description: pub.doric.shader.slider
* @Author: pengfei.zhou
* @CreateDate: 2019-11-12
* @UpdateDate: 2020-04-09
*/
class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
@ -44,6 +45,8 @@ class SlideAdapter extends RecyclerView.Adapter<SlideAdapter.DoricViewHolder> {
int batchCount = 3;
SparseArray<String> itemValues = new SparseArray<>();
String renderPageFuncId;
boolean loop;
SlideAdapter(SliderNode sliderNode) {
this.sliderNode = sliderNode;
}

View File

@ -34,9 +34,10 @@ import pub.doric.shader.SuperNode;
import pub.doric.shader.ViewNode;
/**
* @Description: pub.doric.shader
* @Description: pub.doric.shader.slider
* @Author: pengfei.zhou
* @CreateDate: 2019-11-19
* @UpdateDate: 2020-04-09
*/
@DoricPlugin(name = "Slider")
public class SliderNode extends SuperNode<RecyclerView> {
@ -150,6 +151,10 @@ public class SliderNode extends SuperNode<RecyclerView> {
case "onPageSlided":
this.onPageSlidedFuncId = prop.asString().toString();
break;
case "loop":
boolean loop = prop.asBoolean().value();
slideAdapter.loop = loop;
break;
default:
super.blend(view, name, prop);
break;

View File

@ -30,6 +30,7 @@ class SliderPanel extends Panel {
}),
slider({
itemCount: 100,
loop: true,
renderPage: (idx) => {
return slideItem(image({
imageUrl: imageUrls[idx % imageUrls.length],

View File

@ -1957,12 +1957,9 @@ var Slider = /** @class */ (function (_super) {
return this.cachedViews.values();
};
Slider.prototype.getItem = function (itemIdx) {
var view = this.cachedViews.get("" + itemIdx);
if (view === undefined) {
view = this.renderPage(itemIdx);
var view = this.renderPage(itemIdx);
view.superview = this;
this.cachedViews.set("" + itemIdx, view);
}
return view;
};
Slider.prototype.isDirty = function () {
@ -2004,6 +2001,10 @@ var Slider = /** @class */ (function (_super) {
Property,
__metadata$6("design:type", Function)
], Slider.prototype, "onPageSlided", void 0);
__decorate$6([
Property,
__metadata$6("design:type", Boolean)
], Slider.prototype, "loop", void 0);
return Slider;
}(Superview));
function slider(config) {

View File

@ -1457,12 +1457,9 @@ class Slider extends Superview {
return this.cachedViews.values();
}
getItem(itemIdx) {
let view = this.cachedViews.get(`${itemIdx}`);
if (view === undefined) {
view = this.renderPage(itemIdx);
let view = this.renderPage(itemIdx);
view.superview = this;
this.cachedViews.set(`${itemIdx}`, view);
}
return view;
}
isDirty() {
@ -1503,6 +1500,10 @@ __decorate$6([
Property,
__metadata$6("design:type", Function)
], Slider.prototype, "onPageSlided", void 0);
__decorate$6([
Property,
__metadata$6("design:type", Boolean)
], Slider.prototype, "loop", void 0);
function slider(config) {
const ret = new Slider;
for (let key in config) {

View File

@ -2916,12 +2916,9 @@ class Slider extends Superview {
return this.cachedViews.values();
}
getItem(itemIdx) {
let view = this.cachedViews.get(`${itemIdx}`);
if (view === undefined) {
view = this.renderPage(itemIdx);
let view = this.renderPage(itemIdx);
view.superview = this;
this.cachedViews.set(`${itemIdx}`, view);
}
return view;
}
isDirty() {
@ -2962,6 +2959,10 @@ __decorate$6([
Property,
__metadata$6("design:type", Function)
], Slider.prototype, "onPageSlided", void 0);
__decorate$6([
Property,
__metadata$6("design:type", Boolean)
], Slider.prototype, "loop", void 0);
function slider(config) {
const ret = new Slider;
for (let key in config) {

2
doric-js/index.d.ts vendored
View File

@ -632,6 +632,7 @@ declare module 'doric/lib/src/widget/slider' {
itemCount: number;
batchCount?: number;
onPageSlided?: (index: number) => void;
loop?: boolean;
}
export class Slider extends Superview implements ISlider {
allSubviews(): IterableIterator<SlideItem>;
@ -639,6 +640,7 @@ declare module 'doric/lib/src/widget/slider' {
renderPage: (index: number) => SlideItem;
batchCount: number;
onPageSlided?: (index: number) => void;
loop?: boolean;
isDirty(): boolean;
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
getSlidedPage(context: BridgeContext): Promise<number>;

View File

@ -15,6 +15,7 @@ export interface ISlider extends IView {
itemCount: number;
batchCount?: number;
onPageSlided?: (index: number) => void;
loop?: boolean;
}
export declare class Slider extends Superview implements ISlider {
private cachedViews;
@ -24,6 +25,7 @@ export declare class Slider extends Superview implements ISlider {
renderPage: (index: number) => SlideItem;
batchCount: number;
onPageSlided?: (index: number) => void;
loop?: boolean;
private getItem;
isDirty(): boolean;
private renderBunchedItems;

View File

@ -43,12 +43,9 @@ export class Slider extends Superview {
return this.cachedViews.values();
}
getItem(itemIdx) {
let view = this.cachedViews.get(`${itemIdx}`);
if (view === undefined) {
view = this.renderPage(itemIdx);
let view = this.renderPage(itemIdx);
view.superview = this;
this.cachedViews.set(`${itemIdx}`, view);
}
return view;
}
isDirty() {
@ -89,6 +86,10 @@ __decorate([
Property,
__metadata("design:type", Function)
], Slider.prototype, "onPageSlided", void 0);
__decorate([
Property,
__metadata("design:type", Boolean)
], Slider.prototype, "loop", void 0);
export function slider(config) {
const ret = new Slider;
for (let key in config) {

View File

@ -36,6 +36,7 @@ export interface ISlider extends IView {
itemCount: number
batchCount?: number
onPageSlided?: (index: number) => void
loop?: boolean
}
export class Slider extends Superview implements ISlider {
@ -58,13 +59,13 @@ export class Slider extends Superview implements ISlider {
@Property
onPageSlided?: (index: number) => void
@Property
loop?: boolean
private getItem(itemIdx: number) {
let view = this.cachedViews.get(`${itemIdx}`)
if (view === undefined) {
view = this.renderPage(itemIdx)
let view = this.renderPage(itemIdx)
view.superview = this
this.cachedViews.set(`${itemIdx}`, view)
}
return view
}

View File

@ -2974,12 +2974,9 @@ class Slider extends Superview {
return this.cachedViews.values();
}
getItem(itemIdx) {
let view = this.cachedViews.get(`${itemIdx}`);
if (view === undefined) {
view = this.renderPage(itemIdx);
let view = this.renderPage(itemIdx);
view.superview = this;
this.cachedViews.set(`${itemIdx}`, view);
}
return view;
}
isDirty() {
@ -3020,6 +3017,10 @@ __decorate$6([
Property,
__metadata$6("design:type", Function)
], Slider.prototype, "onPageSlided", void 0);
__decorate$6([
Property,
__metadata$6("design:type", Boolean)
], Slider.prototype, "loop", void 0);
function slider(config) {
const ret = new Slider;
for (let key in config) {

File diff suppressed because one or more lines are too long