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

View File

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

View File

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

View File

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

View File

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

View File

@ -2916,12 +2916,9 @@ class Slider extends Superview {
return this.cachedViews.values(); return this.cachedViews.values();
} }
getItem(itemIdx) { getItem(itemIdx) {
let view = this.cachedViews.get(`${itemIdx}`); let view = this.renderPage(itemIdx);
if (view === undefined) { view.superview = this;
view = this.renderPage(itemIdx); this.cachedViews.set(`${itemIdx}`, view);
view.superview = this;
this.cachedViews.set(`${itemIdx}`, view);
}
return view; return view;
} }
isDirty() { isDirty() {
@ -2962,6 +2959,10 @@ __decorate$6([
Property, Property,
__metadata$6("design:type", Function) __metadata$6("design:type", Function)
], Slider.prototype, "onPageSlided", void 0); ], Slider.prototype, "onPageSlided", void 0);
__decorate$6([
Property,
__metadata$6("design:type", Boolean)
], Slider.prototype, "loop", void 0);
function slider(config) { function slider(config) {
const ret = new Slider; const ret = new Slider;
for (let key in config) { 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; itemCount: number;
batchCount?: number; batchCount?: number;
onPageSlided?: (index: number) => void; onPageSlided?: (index: number) => void;
loop?: boolean;
} }
export class Slider extends Superview implements ISlider { export class Slider extends Superview implements ISlider {
allSubviews(): IterableIterator<SlideItem>; allSubviews(): IterableIterator<SlideItem>;
@ -639,6 +640,7 @@ declare module 'doric/lib/src/widget/slider' {
renderPage: (index: number) => SlideItem; renderPage: (index: number) => SlideItem;
batchCount: number; batchCount: number;
onPageSlided?: (index: number) => void; onPageSlided?: (index: number) => void;
loop?: boolean;
isDirty(): boolean; isDirty(): boolean;
slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>; slidePage(context: BridgeContext, page: number, smooth?: boolean): Promise<any>;
getSlidedPage(context: BridgeContext): Promise<number>; getSlidedPage(context: BridgeContext): Promise<number>;

View File

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

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long