js: declare scroll to item with top offset api

This commit is contained in:
王劲鹏 2023-08-03 18:58:28 +08:00 committed by osborn
parent e3ca9ae5d4
commit c4eee8ad4a
11 changed files with 990 additions and 574 deletions

File diff suppressed because one or more lines are too long

View File

@ -1132,6 +1132,7 @@ var Panel = /** @class */ (function () {
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
this.__rendering__ = false; this.__rendering__ = false;
this.callingRenderFinishedCallback = false;
this.snapshotEnabled = false; this.snapshotEnabled = false;
this.renderSnapshots = []; this.renderSnapshots = [];
} }
@ -1370,12 +1371,17 @@ var Panel = /** @class */ (function () {
return diryData; return diryData;
}; };
Panel.prototype.onRenderFinished = function () { Panel.prototype.onRenderFinished = function () {
this.callingRenderFinishedCallback = false;
this.onRenderFinishedCallback.forEach(function (e) { this.onRenderFinishedCallback.forEach(function (e) {
e(); e();
}); });
this.onRenderFinishedCallback.length = 0; this.onRenderFinishedCallback.length = 0;
this.callingRenderFinishedCallback = true;
}; };
Panel.prototype.addOnRenderFinishedCallback = function (cb) { Panel.prototype.addOnRenderFinishedCallback = function (cb) {
if (this.callingRenderFinishedCallback) {
loge("Do not call addOnRenderFinishedCallback recursively");
}
this.onRenderFinishedCallback.push(cb); this.onRenderFinishedCallback.push(cb);
}; };
__decorate$e([ __decorate$e([
@ -2558,9 +2564,13 @@ var List = /** @class */ (function (_super) {
} }
return ret; return ret;
}; };
/**
* @param {number} config.topOffset - 目标位置cell的顶部偏移量
*/
List.prototype.scrollToItem = function (context, index, config) { List.prototype.scrollToItem = function (context, index, config) {
var animated = config === null || config === void 0 ? void 0 : config.animated; var animated = config === null || config === void 0 ? void 0 : config.animated;
return this.nativeChannel(context, 'scrollToItem')({ index: index, animated: animated, }); var topOffset = config === null || config === void 0 ? void 0 : config.topOffset;
return this.nativeChannel(context, 'scrollToItem')({ index: index, animated: animated, topOffset: topOffset });
}; };
/** /**
* @param context * @param context

View File

@ -867,6 +867,7 @@ class Panel {
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
this.__rendering__ = false; this.__rendering__ = false;
this.callingRenderFinishedCallback = false;
this.snapshotEnabled = false; this.snapshotEnabled = false;
this.renderSnapshots = []; this.renderSnapshots = [];
} }
@ -1048,12 +1049,17 @@ class Panel {
return diryData; return diryData;
} }
onRenderFinished() { onRenderFinished() {
this.callingRenderFinishedCallback = false;
this.onRenderFinishedCallback.forEach(e => { this.onRenderFinishedCallback.forEach(e => {
e(); e();
}); });
this.onRenderFinishedCallback.length = 0; this.onRenderFinishedCallback.length = 0;
this.callingRenderFinishedCallback = true;
} }
addOnRenderFinishedCallback(cb) { addOnRenderFinishedCallback(cb) {
if (this.callingRenderFinishedCallback) {
loge("Do not call addOnRenderFinishedCallback recursively");
}
this.onRenderFinishedCallback.push(cb); this.onRenderFinishedCallback.push(cb);
} }
} }
@ -1910,9 +1916,13 @@ class List extends Superview {
} }
return ret; return ret;
} }
/**
* @param {number} config.topOffset - 目标位置cell的顶部偏移量
*/
scrollToItem(context, index, config) { scrollToItem(context, index, config) {
const animated = config === null || config === void 0 ? void 0 : config.animated; const animated = config === null || config === void 0 ? void 0 : config.animated;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, }); const topOffset = config === null || config === void 0 ? void 0 : config.topOffset;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, topOffset });
} }
/** /**
* @param context * @param context

File diff suppressed because it is too large Load Diff

View File

@ -2407,6 +2407,7 @@ class Panel {
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
this.__rendering__ = false; this.__rendering__ = false;
this.callingRenderFinishedCallback = false;
this.snapshotEnabled = false; this.snapshotEnabled = false;
this.renderSnapshots = []; this.renderSnapshots = [];
} }
@ -2588,12 +2589,17 @@ class Panel {
return diryData; return diryData;
} }
onRenderFinished() { onRenderFinished() {
this.callingRenderFinishedCallback = false;
this.onRenderFinishedCallback.forEach(e => { this.onRenderFinishedCallback.forEach(e => {
e(); e();
}); });
this.onRenderFinishedCallback.length = 0; this.onRenderFinishedCallback.length = 0;
this.callingRenderFinishedCallback = true;
} }
addOnRenderFinishedCallback(cb) { addOnRenderFinishedCallback(cb) {
if (this.callingRenderFinishedCallback) {
loge("Do not call addOnRenderFinishedCallback recursively");
}
this.onRenderFinishedCallback.push(cb); this.onRenderFinishedCallback.push(cb);
} }
} }
@ -3450,9 +3456,13 @@ class List extends Superview {
} }
return ret; return ret;
} }
/**
* @param {number} config.topOffset - 目标位置cell的顶部偏移量
*/
scrollToItem(context, index, config) { scrollToItem(context, index, config) {
const animated = config === null || config === void 0 ? void 0 : config.animated; const animated = config === null || config === void 0 ? void 0 : config.animated;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, }); const topOffset = config === null || config === void 0 ? void 0 : config.topOffset;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, topOffset });
} }
/** /**
* @param context * @param context

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

@ -718,6 +718,7 @@ declare module "doric" {
private headviews; private headviews;
private onRenderFinishedCallback; private onRenderFinishedCallback;
private __rendering__; private __rendering__;
private callingRenderFinishedCallback;
addHeadView(type: string, v: View): void; addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<Map<string, View>>; allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(type: string, v: View | string): void; removeHeadView(type: string, v: View | string): void;
@ -1048,8 +1049,12 @@ declare module "doric" {
onDragging?: (from: number, to: number) => void; onDragging?: (from: number, to: number) => void;
onDragged?: (from: number, to: number) => void; onDragged?: (from: number, to: number) => void;
preloadItemCount?: number; preloadItemCount?: number;
/**
* @param {number} config.topOffset - cell的顶部偏移量
*/
scrollToItem(context: BridgeContext, index: number, config?: { scrollToItem(context: BridgeContext, index: number, config?: {
animated?: boolean; animated?: boolean;
topOffset?: number;
}): Promise<any>; }): Promise<any>;
/** /**
* @param context * @param context

View File

@ -21,6 +21,7 @@ export declare abstract class Panel {
private headviews; private headviews;
private onRenderFinishedCallback; private onRenderFinishedCallback;
private __rendering__; private __rendering__;
private callingRenderFinishedCallback;
addHeadView(type: string, v: View): void; addHeadView(type: string, v: View): void;
allHeadViews(): IterableIterator<Map<string, View>>; allHeadViews(): IterableIterator<Map<string, View>>;
removeHeadView(type: string, v: View | string): void; removeHeadView(type: string, v: View | string): void;

View File

@ -40,6 +40,7 @@ export class Panel {
this.headviews = new Map; this.headviews = new Map;
this.onRenderFinishedCallback = []; this.onRenderFinishedCallback = [];
this.__rendering__ = false; this.__rendering__ = false;
this.callingRenderFinishedCallback = false;
this.snapshotEnabled = false; this.snapshotEnabled = false;
this.renderSnapshots = []; this.renderSnapshots = [];
} }
@ -221,12 +222,17 @@ export class Panel {
return diryData; return diryData;
} }
onRenderFinished() { onRenderFinished() {
this.callingRenderFinishedCallback = false;
this.onRenderFinishedCallback.forEach(e => { this.onRenderFinishedCallback.forEach(e => {
e(); e();
}); });
this.onRenderFinishedCallback.length = 0; this.onRenderFinishedCallback.length = 0;
this.callingRenderFinishedCallback = true;
} }
addOnRenderFinishedCallback(cb) { addOnRenderFinishedCallback(cb) {
if (this.callingRenderFinishedCallback) {
loge("Do not call addOnRenderFinishedCallback recursively");
}
this.onRenderFinishedCallback.push(cb); this.onRenderFinishedCallback.push(cb);
} }
} }

View File

@ -54,8 +54,12 @@ export declare class List extends Superview {
onDragging?: (from: number, to: number) => void; onDragging?: (from: number, to: number) => void;
onDragged?: (from: number, to: number) => void; onDragged?: (from: number, to: number) => void;
preloadItemCount?: number; preloadItemCount?: number;
/**
* @param {number} config.topOffset - cell的顶部偏移量
*/
scrollToItem(context: BridgeContext, index: number, config?: { scrollToItem(context: BridgeContext, index: number, config?: {
animated?: boolean; animated?: boolean;
topOffset?: number;
}): Promise<any>; }): Promise<any>;
/** /**
* @param context * @param context

View File

@ -50,9 +50,13 @@ export class List extends Superview {
} }
return ret; return ret;
} }
/**
* @param {number} config.topOffset - 目标位置cell的顶部偏移量
*/
scrollToItem(context, index, config) { scrollToItem(context, index, config) {
const animated = config === null || config === void 0 ? void 0 : config.animated; const animated = config === null || config === void 0 ? void 0 : config.animated;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, }); const topOffset = config === null || config === void 0 ? void 0 : config.topOffset;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, topOffset });
} }
/** /**
* @param context * @param context

View File

@ -114,9 +114,19 @@ export class List extends Superview {
@Property @Property
preloadItemCount?: number preloadItemCount?: number
scrollToItem(context: BridgeContext, index: number, config?: { animated?: boolean, }) { /**
* @param {number} config.topOffset - cell的顶部偏移量
*/
scrollToItem(context: BridgeContext,
index: number,
config?: {
animated?: boolean,
topOffset?: number
}) {
const animated = config?.animated const animated = config?.animated
return this.nativeChannel(context, 'scrollToItem')({ index, animated, }) as Promise<any> const topOffset = config?.topOffset;
return this.nativeChannel(context, 'scrollToItem')({ index, animated, topOffset }) as Promise<any>
} }
/** /**
* @param context * @param context