Commit fc82b76e authored by rockyl's avatar rockyl

修复滚动列表多行列的问题

parent 4b4104a8
{"id":"engine","url":"engine.53262d62b13fbd758c11074e8875d82b17828de5.js"}
\ No newline at end of file
{"id":"engine","url":"engine.50cdcef6ebe4e8c0fbc624f9d4fbf225102c5750.js"}
\ No newline at end of file
......@@ -40,11 +40,11 @@ export abstract class ScrollListItemBase extends Container {
export class ScrollListBase extends ScrollViewBase {
private _items: Array<ScrollListItemBase> = null;
private _itemRow: number;
private _itemCol: number;
private _itemCount: number;
private _isInit: number = 0;
public data: Array<any> = [];
private downL: DisplayObject = null;
private _cols: number = 1;
private _disParam: string;
private _lastFirstId: number = -1;
private _updateId: number = -1;
......@@ -54,7 +54,7 @@ export class ScrollListBase extends ScrollViewBase {
@dirtyFieldTrigger
public itemHeight: number = 0;
@dirtyFieldTrigger
public itemCol: number;
public cols: number = 1;
@dirtyFieldTrigger
public itemClass: any;
......@@ -84,7 +84,7 @@ export class ScrollListBase extends ScrollViewBase {
}
protected onNextFrame(event) {
this._updateViewRect();
this.updateViewRect();
}
onModify(value, key) {
......@@ -95,7 +95,7 @@ export class ScrollListBase extends ScrollViewBase {
case 'itemH':
break;
case 'itemCol':
case '_itemCol':
break;
case 'itemClass':
......@@ -106,7 +106,7 @@ export class ScrollListBase extends ScrollViewBase {
protected calMaxDistance(): any {
let key = 'item' + this.paramSize.substr(0, 1).toUpperCase() + this.paramSize.substr(1);
return this[key] * this.data.length;
return this[key] * Math.ceil(this.data.length / this.cols);
}
/**
......@@ -125,7 +125,7 @@ export class ScrollListBase extends ScrollViewBase {
}
s._isInit = 1;
s._lastFirstId = -1;
/*s.maxDistance = Math.ceil(s.data.length / s._cols) * s._itemRow;
/*s.maxDistance = Math.ceil(s.data.length / s.cols) * s._itemRow;
if (s.downL) {
s.downL[s.paramXY] = Math.max(s.distance, s.maxDistance);
var wh = s.downL.getWH();
......@@ -135,15 +135,18 @@ export class ScrollListBase extends ScrollViewBase {
private flushData() {
let s: ScrollListBase = this;
const items = s._items;
if(items.length <= 0){
return;
}
if (s._isInit > 0) {
if (s._updateId != s.viewPort.transform._localID) {
const items = s._items;
let id: number = s.viewPort[s.paramXY] > 0 ? 0 : (Math.abs(Math.floor(s.viewPort[s.paramXY] / s._itemRow)) - 1) * s._cols;
let id: number = s.viewPort[s.paramXY] > 0 ? 0 : (Math.abs(Math.floor(s.viewPort[s.paramXY] / s._itemRow)) - 1) * s.cols;
id = id < 0 ? 0 : id;
if (id != s._lastFirstId) {
s._lastFirstId = id;
if (id != items[0].id) {
for (let r = 0; r < s._cols; r++) {
for (let r = 0; r < s.cols; r++) {
if (s.speed > 0) {
items.unshift(items.pop());
} else {
......@@ -161,8 +164,8 @@ export class ScrollListBase extends ScrollViewBase {
if(s.data[id]){
item._initData(s.data[id] ? id : -1, s.data[id]);
}
item[s.paramXY] = Math.floor(id / s._cols) * s._itemRow;
item[s._disParam] = (id % s._cols) * s.itemCol;
item[s.paramXY] = Math.floor(id / s.cols) * s._itemRow;
item[s._disParam] = (id % s.cols) * s._itemCol;
//如果没有数据则隐藏
if (s.data[id]) {
item.sli_id = id;
......@@ -188,7 +191,7 @@ export class ScrollListBase extends ScrollViewBase {
public updateViewRect(): void {
super.updateViewRect();
let s = this;
if (s._itemRow && s.itemCol) {
if (s.itemWidth && s.itemHeight) {
s._updateViewRect();
}
}
......@@ -196,15 +199,21 @@ export class ScrollListBase extends ScrollViewBase {
protected _updateViewRect() {
let s: ScrollListBase = this;
if (s._direction === SCROLL_DIRECTION.VERTICAL) {
if(s.itemHeight <= 0){
return;
}
s._disParam = "x";
s._itemRow = s.itemHeight;
s.itemCol = s.itemWidth;
s._itemCol = s.itemWidth;
} else {
if(s.itemWidth <= 0){
return;
}
s._disParam = "y";
s._itemRow = s.itemWidth;
s.itemCol = s.itemHeight;
s._itemCol = s.itemHeight;
}
let newCount: number = (Math.ceil(s.distance / s._itemRow) + 1) * s._cols;
let newCount: number = (Math.ceil(s.distance / s._itemRow) + 1) * s.cols;
if (newCount != s._itemCount) {
if (newCount > s._itemCount) {
for (let i = s._itemCount; i < newCount; i++) {
......
......@@ -3,8 +3,8 @@
*
* 数据中心
*/
import {EventDispatcher} from "../../2d/events";
import {arrayFind, getDataByPath} from "../utils";
import {EventDispatcher} from "../../2d/events/index";
import {arrayFind, getDataByPath} from "../utils/index";
import {DATA_CENTER_EVENT, globalEvent} from "../decorators/events";
/**
......@@ -12,7 +12,7 @@ import {DATA_CENTER_EVENT, globalEvent} from "../decorators/events";
*/
export class DataCenter extends EventDispatcher {
store = {};
watchers = [];
dataMappings = [];
constructor() {
super();
......@@ -66,9 +66,9 @@ export class DataCenter extends EventDispatcher {
* @param throwException
*/
getDataByName(name, throwException?) {
let watcher = this.getWatcher(name);
if (watcher) {
return getDataByPath(this.store, watcher.path, throwException);
let dataMapping = this.getDataMapping(name);
if (dataMapping) {
return getDataByPath(this.store, dataMapping.path, throwException);
}
}
......@@ -82,9 +82,9 @@ export class DataCenter extends EventDispatcher {
for (let escape of escapes) {
let args = escape.split('|');
let name = args[0];
let watcher = this.getWatcher(name);
let dataMapping = this.getDataMapping(name);
try {
let data: any = this.getDataByPath(watcher.path, undefined, true);
let data: any = this.getDataByPath(dataMapping.path, undefined, true);
if (args[1] !== undefined) {
data = data[args[1]];
}
......@@ -150,12 +150,12 @@ export class DataCenter extends EventDispatcher {
}
if (dispatch) {
for (let watcher of this.watchers) {
if (watcher.path.indexOf(groupName) === 0) {
this.dispatchEvent(watcher.name, {
name: watcher.name,
path: watcher.path,
data: this.getDataByPath(watcher.path),
for (let dataMapping of this.dataMappings) {
if (dataMapping.path.indexOf(groupName) === 0) {
this.dispatchEvent(dataMapping.name, {
name: dataMapping.name,
path: dataMapping.path,
data: this.getDataByPath(dataMapping.path),
});
}
}
......@@ -169,21 +169,21 @@ export class DataCenter extends EventDispatcher {
}
/**
* 添加数据侦听
* 添加数据映射
* @param name
* @param path
*/
watch(name, path) {
let watcher = {name, path};
this.watchers.push(watcher);
dataMapping(name, path) {
let dataMapping = {name, path};
this.dataMappings.push(dataMapping);
}
/**
* 根据名字获取侦听者
* 根据名字获取映射
* @param name
*/
getWatcher(name) {
return arrayFind(this.watchers, watcher => watcher.name === name);
getDataMapping(name) {
return arrayFind(this.dataMappings, dataMapping => dataMapping.name === name);
}
/**
......@@ -192,7 +192,7 @@ export class DataCenter extends EventDispatcher {
*/
registerDataMapping(dataMapping) {
for (let item of dataMapping) {
this.watch(item.name, item.path);
this.dataMapping(item.name, item.path);
}
}
......
......@@ -3,7 +3,7 @@
*/
import {TextField} from "../../../2d/text/index";
import {dataCenter} from "../data-center";
import {ESCAPE_REG_EXP, htmlToPureText} from "../../utils";
import {ESCAPE_REG_EXP, htmlToPureText} from "../../utils/index";
/**
* 文本
......
......@@ -38,7 +38,7 @@ export class ScrollList extends ScrollListBase {
protected onNextFrame(event) {
this.firstItem = <Container>this.removeChildAt(0);
this._updateViewRect();
this.updateViewRect();
}
protected createItem(): any {
......
......@@ -3,7 +3,7 @@
*/
import {Container} from "../../2d/display/index";
import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText, HtmlView} from "./nodes";
import {Rect, Image, Label, Circle, ScrollView, TextInput, ScrollList, BitmapText, HtmlView} from "./nodes/index";
import {injectProperties, instantiateScript,} from "../utils/index";
const nodeTypeMapping = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment