@pixui-dev/pxw 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pxw.js +199 -199
- package/bin/wpbuild.js +10 -10
- package/config/default.conf +20 -20
- package/config/devops.js +372 -361
- package/config/h5es.js +10 -10
- package/config/index.html +183 -181
- package/config/pfbs.js +245 -245
- package/config/util.js +140 -140
- package/config/webpack.js +325 -309
- package/lib/assets/check.html +62 -62
- package/lib/assets/preact.js +4354 -4354
- package/lib/check/main.less +62 -62
- package/lib/check/main.tsx +41 -41
- package/lib/check/tool.js +3 -3
- package/lib/check/util.tsx +110 -110
- package/lib/grpc-web/dist/ChunkParser.js +117 -117
- package/lib/grpc-web/dist/Code.js +58 -58
- package/lib/grpc-web/dist/client.js +299 -299
- package/lib/grpc-web/dist/debug.js +16 -16
- package/lib/grpc-web/dist/detach.js +7 -7
- package/lib/grpc-web/dist/index.js +29 -29
- package/lib/grpc-web/dist/invoke.js +32 -32
- package/lib/grpc-web/dist/message.js +3 -3
- package/lib/grpc-web/dist/metadata.js +5 -5
- package/lib/grpc-web/dist/service.js +3 -3
- package/lib/grpc-web/dist/transports/Transport.js +15 -15
- package/lib/grpc-web/dist/transports/http/fetch.js +117 -117
- package/lib/grpc-web/dist/transports/http/http.js +15 -15
- package/lib/grpc-web/dist/transports/http/xhr.js +136 -136
- package/lib/grpc-web/dist/transports/http/xhrUtil.js +36 -36
- package/lib/grpc-web/dist/transports/websocket/websocket.js +95 -95
- package/lib/grpc-web/dist/typings/ChunkParser.d.ts +17 -17
- package/lib/grpc-web/dist/typings/Code.d.ts +20 -20
- package/lib/grpc-web/dist/typings/client.d.ts +25 -25
- package/lib/grpc-web/dist/typings/debug.d.ts +1 -1
- package/lib/grpc-web/dist/typings/detach.d.ts +1 -1
- package/lib/grpc-web/dist/typings/index.d.ts +45 -45
- package/lib/grpc-web/dist/typings/invoke.d.ts +20 -20
- package/lib/grpc-web/dist/typings/message.d.ts +8 -8
- package/lib/grpc-web/dist/typings/metadata.d.ts +2 -2
- package/lib/grpc-web/dist/typings/service.d.ts +16 -16
- package/lib/grpc-web/dist/typings/transports/Transport.d.ts +22 -22
- package/lib/grpc-web/dist/typings/transports/http/fetch.d.ts +6 -6
- package/lib/grpc-web/dist/typings/transports/http/http.d.ts +5 -5
- package/lib/grpc-web/dist/typings/transports/http/xhr.d.ts +27 -27
- package/lib/grpc-web/dist/typings/transports/http/xhrUtil.d.ts +3 -3
- package/lib/grpc-web/dist/typings/transports/websocket/websocket.d.ts +2 -2
- package/lib/grpc-web/dist/typings/unary.d.ts +23 -23
- package/lib/grpc-web/dist/typings/util.d.ts +2 -2
- package/lib/grpc-web/dist/unary.js +44 -44
- package/lib/grpc-web/dist/util.js +11 -11
- package/lib/grpcTransport/PixHttp2Transport.ts +107 -107
- package/lib/grpcTransport/PixLuaTransport.ts +82 -82
- package/lib/h5es-types/v1.9.2/h5es.d.ts +1698 -1698
- package/lib/h5es-types/v3.5.0/h5es.d.ts +1788 -1788
- package/lib/pi_component/tinyList/tinyList.js +483 -483
- package/lib/pi_component/tinyList/tinyList.tsx +517 -517
- package/lib/preact-router.js +395 -395
- package/lib/preact.js +4355 -4355
- package/lib/preact.tq.js +4385 -4385
- package/lib/react-window/src/FixedSizeGrid.js +172 -172
- package/lib/react-window/src/FixedSizeList.js +91 -91
- package/lib/react-window/src/VariableSizeGrid.js +329 -329
- package/lib/react-window/src/VariableSizeList.js +231 -231
- package/lib/react-window/src/__tests__/FixedSizeGrid.js +942 -942
- package/lib/react-window/src/__tests__/FixedSizeList.js +749 -749
- package/lib/react-window/src/__tests__/VariableSizeGrid.js +598 -598
- package/lib/react-window/src/__tests__/VariableSizeList.js +345 -345
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeGrid.js.snap +912 -912
- package/lib/react-window/src/__tests__/__snapshots__/FixedSizeList.js.snap +568 -568
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeGrid.js.snap +542 -542
- package/lib/react-window/src/__tests__/__snapshots__/VariableSizeList.js.snap +331 -331
- package/lib/react-window/src/__tests__/areEqual.js +28 -28
- package/lib/react-window/src/__tests__/shouldComponentUpdate.js +32 -32
- package/lib/react-window/src/areEqual.js +13 -13
- package/lib/react-window/src/createGridComponent.js +657 -657
- package/lib/react-window/src/createListComponent.js +574 -574
- package/lib/react-window/src/domHelpers.js +69 -69
- package/lib/react-window/src/index.js +9 -9
- package/lib/react-window/src/shallowDiffers.js +17 -17
- package/lib/react-window/src/shouldComponentUpdate.js +11 -11
- package/lib/react-window/src/test.js.flow +382 -382
- package/lib/react-window/src/timer.js +36 -36
- package/lib/types/dom.ts +17 -17
- package/lib/types/ext.d.ts +81 -81
- package/lib/types/preact/css.d.ts +7476 -7476
- package/lib/types/preact/index.d.ts +340 -340
- package/lib/types/preact/internal.d.ts +94 -94
- package/lib/types/preact/jsx.d.ts +309 -309
- package/lib/types/preact-router/index.d.ts +84 -84
- package/package.json +113 -113
- package/scripts/pack.js +40 -40
- package/scripts/postinstall.js +11 -11
- package/scripts/run-pxw.js +12 -12
- package/tsconfig.json +30 -30
|
@@ -1,517 +1,517 @@
|
|
|
1
|
-
export const Direction = {
|
|
2
|
-
Horizontal: 0,
|
|
3
|
-
Vertical: 1,
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
Object.freeze(Direction);
|
|
7
|
-
|
|
8
|
-
export class TinyList {
|
|
9
|
-
private startIndex = 0;
|
|
10
|
-
private endIndex = -1;
|
|
11
|
-
private startBoundary = 0;
|
|
12
|
-
private endBoundary = 0;
|
|
13
|
-
private containerWidth = 0;
|
|
14
|
-
private viewHeight = 0;
|
|
15
|
-
private viewWidth = 0;
|
|
16
|
-
private containerHeight = 0;
|
|
17
|
-
private scorllDirection = Direction.Vertical;
|
|
18
|
-
|
|
19
|
-
private itemSize = 0;
|
|
20
|
-
private defaultItemSize = 200;
|
|
21
|
-
|
|
22
|
-
private viewDiv;
|
|
23
|
-
private contentDiv;
|
|
24
|
-
|
|
25
|
-
private itemCount = 0;
|
|
26
|
-
private itemPool: any[] = [];
|
|
27
|
-
private itemMap = {};
|
|
28
|
-
private itemSizeList: any[] = [];
|
|
29
|
-
private MOVE_DELTA = 5;
|
|
30
|
-
private curScrollOffset = 0;
|
|
31
|
-
private fillItemFunc;
|
|
32
|
-
private onStartFunc;
|
|
33
|
-
private onEndFunc;
|
|
34
|
-
private CalculateItemSizeFunc;
|
|
35
|
-
|
|
36
|
-
private cacheNumber = 0;//多缓存几个数量
|
|
37
|
-
|
|
38
|
-
//root:该瀑布流组件根节点
|
|
39
|
-
//count:当前列表的数量
|
|
40
|
-
//viewSize:瀑布流组件viewSize,高或宽超出部分不显示
|
|
41
|
-
//direction:方向,暂时仅支持垂直
|
|
42
|
-
//calculatedSize:单元格固定尺寸,可设置为一个计算单元格高度的函数。
|
|
43
|
-
//cacheNum:滑动过快的话,可稍微增加几个缓存,设置缓存数量。
|
|
44
|
-
//fillFunc:填充具体对应的Item函数委托
|
|
45
|
-
public CreateList = (root, count, viewSize, direction, calculatedSize, cacheNum, fillFunc)=> {
|
|
46
|
-
if(root != undefined) {
|
|
47
|
-
this.itemCount = count;
|
|
48
|
-
this.scorllDirection = direction;
|
|
49
|
-
this.cacheNumber = cacheNum;
|
|
50
|
-
if (typeof calculatedSize == 'function') {
|
|
51
|
-
// console.log('--------------- this.itemSize is Funtion -------------------')
|
|
52
|
-
this.CalculateItemSizeFunc = calculatedSize;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// console.log('--------------- this.itemSize is size Num -------------------')
|
|
56
|
-
this.itemSize = calculatedSize;
|
|
57
|
-
}
|
|
58
|
-
this.viewDiv = document.createElement('div');
|
|
59
|
-
this.viewDiv.style.position = 'relative';
|
|
60
|
-
this.viewDiv.style.overflow = 'scroll';
|
|
61
|
-
this.viewDiv.style.willChange = 'transform';
|
|
62
|
-
this.viewDiv.style.left = '0px';
|
|
63
|
-
this.viewDiv.style.top = '0px';
|
|
64
|
-
|
|
65
|
-
this.viewDiv.addEventListener('scroll', this.onScroll);
|
|
66
|
-
root.appendChild(this.viewDiv);
|
|
67
|
-
//创建一个contener
|
|
68
|
-
this.contentDiv = document.createElement('div');
|
|
69
|
-
|
|
70
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
71
|
-
this.viewWidth = viewSize ;
|
|
72
|
-
this.viewDiv.style.flexDirection = 'row';
|
|
73
|
-
// this.viewDiv.style.height = `100%`;
|
|
74
|
-
this.viewDiv.style.height = '400px';
|
|
75
|
-
this.viewDiv.style.width = `${viewSize}px`;
|
|
76
|
-
this.viewWidth = viewSize ;
|
|
77
|
-
this.contentDiv.style.height = '100%';
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.viewDiv.style.flexDirection = 'column';
|
|
81
|
-
this.viewDiv.style.height = `${viewSize}px`;
|
|
82
|
-
this.viewDiv.style.width = '100%';
|
|
83
|
-
this.viewHeight = viewSize ;
|
|
84
|
-
this.contentDiv.style.width = '100%';
|
|
85
|
-
}
|
|
86
|
-
this.viewDiv.appendChild(this.contentDiv);
|
|
87
|
-
this.InitItemsSize(0, this.itemCount);
|
|
88
|
-
this.fillItemFunc = fillFunc;
|
|
89
|
-
this.itemMap = {};
|
|
90
|
-
this.fill();
|
|
91
|
-
}
|
|
92
|
-
else
|
|
93
|
-
console.log('---------- 未能找到瀑布流组件根节点!!!! ------------');
|
|
94
|
-
return this.viewDiv;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
private InitItemsSize = (begin, end)=> {
|
|
98
|
-
for(let i = begin; i < end; i++) {
|
|
99
|
-
this.itemSizeList[i] = -1;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
private GetItemSize = (index)=> {
|
|
104
|
-
let curSize = 0;
|
|
105
|
-
if(this.CalculateItemSizeFunc != undefined) {
|
|
106
|
-
if(this.itemSizeList[index] != undefined && this.itemSizeList[index] != -1) {
|
|
107
|
-
curSize = this.itemSizeList[index];
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
curSize = this.CalculateItemSizeFunc(index);
|
|
111
|
-
this.itemSizeList[index] = curSize;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else
|
|
115
|
-
curSize = this.itemSize;
|
|
116
|
-
return curSize;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
public SetOnStartFunc = (onStart)=> {
|
|
120
|
-
this.onStartFunc = onStart;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
public SetOnEndFunc = (onEnd)=> {
|
|
124
|
-
this.onEndFunc = onEnd;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
private onScroll = ( event ) => {
|
|
128
|
-
// const { clientHeight, scrollHeight, scrollTop } = event.currentTarget;
|
|
129
|
-
const {scrollLeft, scrollTop } = event.currentTarget;
|
|
130
|
-
// console.log('================== scrollLeft: ', scrollLeft);
|
|
131
|
-
// console.log('================== scrollTop ', scrollTop);
|
|
132
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
133
|
-
if(scrollLeft == 0 ) {
|
|
134
|
-
if(this.onStartFunc != undefined) {
|
|
135
|
-
this.onStartFunc();
|
|
136
|
-
this.Leftward();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else if(scrollLeft > 0 && (scrollLeft + this.viewWidth) >= this.endBoundary ) {
|
|
141
|
-
if(this.onEndFunc != undefined) {
|
|
142
|
-
// console.log("----------this.onEndFunc this.viewDiv scrollLeft:", scrollLeft, "------------");
|
|
143
|
-
// console.log("----------this.onEndFunc this.endBoundary:", this.endBoundary, "------------");
|
|
144
|
-
|
|
145
|
-
// console.log("---------- this.onEndFunc this.viewDiv top:", this.viewDiv.scrollTop, "------------");
|
|
146
|
-
this.onEndFunc();
|
|
147
|
-
// Rightward();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const distance = scrollLeft - this.curScrollOffset;
|
|
152
|
-
this.curScrollOffset = scrollLeft;
|
|
153
|
-
if(distance >= this.MOVE_DELTA) {
|
|
154
|
-
this.Leftward();
|
|
155
|
-
}
|
|
156
|
-
else if(distance < -this.MOVE_DELTA) {
|
|
157
|
-
this.Rightward();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
if(scrollTop == 0 ) {
|
|
162
|
-
if(this.onStartFunc != undefined) {
|
|
163
|
-
this.onStartFunc();
|
|
164
|
-
this.Forward();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else if(scrollTop > 0 && (scrollTop + this.viewHeight) >= this.endBoundary) {
|
|
169
|
-
if(this.onEndFunc != undefined) {
|
|
170
|
-
this.onEndFunc();
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const distance = scrollTop - this.curScrollOffset;
|
|
175
|
-
this.curScrollOffset = scrollTop;
|
|
176
|
-
if(distance >= this.MOVE_DELTA) {
|
|
177
|
-
this.Forward();
|
|
178
|
-
}
|
|
179
|
-
else if(distance < -this.MOVE_DELTA) {
|
|
180
|
-
this.BackWard();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
public AppendList = (count)=> {
|
|
186
|
-
const curIndex = this.itemCount;
|
|
187
|
-
this.itemCount = this.itemCount + count;
|
|
188
|
-
this.InitItemsSize( curIndex, this.itemCount);
|
|
189
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
190
|
-
this.Leftward();
|
|
191
|
-
else
|
|
192
|
-
this.Forward();
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
private resetContentPosision = ()=> {
|
|
196
|
-
// this.viewDiv.scrollTop = 0;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
public Refresh = (count)=> {
|
|
200
|
-
this.RecycleAll();
|
|
201
|
-
this.itemCount = count;
|
|
202
|
-
this.itemSizeList = [];
|
|
203
|
-
this.InitItemsSize(0, this.itemCount);
|
|
204
|
-
this.curScrollOffset = 0;
|
|
205
|
-
this.viewDiv.scrollTop = 0;
|
|
206
|
-
this.fill();
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
private fill = () => {
|
|
210
|
-
// console.log("---------- fillItem ------------")
|
|
211
|
-
this.startIndex = 0;
|
|
212
|
-
this.endIndex = -1;
|
|
213
|
-
this.startBoundary = 0;
|
|
214
|
-
this.endBoundary = 0;
|
|
215
|
-
this.containerHeight = 0;
|
|
216
|
-
this.containerWidth = 0;
|
|
217
|
-
this.curScrollOffset = 0;
|
|
218
|
-
|
|
219
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
220
|
-
this.Leftward();
|
|
221
|
-
else
|
|
222
|
-
this.Forward();
|
|
223
|
-
|
|
224
|
-
// console.log("---------- this.viewDiv left:", this.viewDiv.scrollLeft, "------------");
|
|
225
|
-
// console.log("---------- this.viewDiv top:", this.viewDiv.scrollTop, "------------");
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
private CreateItem = ( index ) => {
|
|
229
|
-
let item;
|
|
230
|
-
// console.log('CreateItem pool size:', this.itemPool.length)
|
|
231
|
-
//console.log('----------@@@@@ CreateItem:', index)
|
|
232
|
-
if(this.itemPool.length > 0) {
|
|
233
|
-
// console.log("---------- useItemPool ------------")
|
|
234
|
-
item = this.itemPool.pop();//this.itemPool[0];
|
|
235
|
-
item.style.display = 'flex';
|
|
236
|
-
item.id = 'item_' + index;
|
|
237
|
-
this.fillItemFunc(item, index);
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// console.log("---------- this.itemPool is null!!! ------------")
|
|
241
|
-
if(this.fillItemFunc != undefined) {
|
|
242
|
-
item = document.createElement('div');
|
|
243
|
-
item.id = 'item_' + index;
|
|
244
|
-
this.fillItemFunc(item, index);
|
|
245
|
-
this.contentDiv.appendChild(item);
|
|
246
|
-
}
|
|
247
|
-
const curSize = this.GetItemSize(index);
|
|
248
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
249
|
-
item.style.width = `${curSize}`;
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
// console.log("---------- curSize:",curSize," ------------")
|
|
253
|
-
item.style.height = `${curSize}`;
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return item;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
private Forward = () => {
|
|
261
|
-
// console.log("---------- Forward ------------")
|
|
262
|
-
// console.log("---------- this.endBoundary:",this.endBoundary, this.curScrollOffset, this.endIndex, " ------------")
|
|
263
|
-
// console.log("---------- this.itemCount:",this.itemCount, " ------------")
|
|
264
|
-
// console.log("---------- boundary:",this.curScrollOffset + this.viewHeight + this.cacheNumber*this.defaultItemSize , " ------------")
|
|
265
|
-
while ((this.endIndex < this.itemCount - 1) && this.endBoundary < (this.curScrollOffset + this.viewHeight + this.cacheNumber * this.defaultItemSize ))//this.itemSize
|
|
266
|
-
{
|
|
267
|
-
this.endIndex++;
|
|
268
|
-
let item = this.CreateItem(this.endIndex);
|
|
269
|
-
this.itemMap[`${this.endIndex}`] = item;
|
|
270
|
-
this.SetItemPosition(item, this.endBoundary);
|
|
271
|
-
this.RefreshEndBundary();
|
|
272
|
-
this.CalculateContentSize();
|
|
273
|
-
}
|
|
274
|
-
this.RecycleBegin();
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
private BackWard = () => {
|
|
278
|
-
// console.log("---------- BackWard ------------")
|
|
279
|
-
// console.log("---------- this.startBoundary:",this.startBoundary, this.curScrollOffset, this.startIndex, " ------------")
|
|
280
|
-
while (this.startIndex > 0 && this.curScrollOffset <= this.startBoundary) {
|
|
281
|
-
this.startIndex--;
|
|
282
|
-
let item = this.CreateItem(this.startIndex);
|
|
283
|
-
this.itemMap[`${this.startIndex}`] = item;
|
|
284
|
-
let height = 0;
|
|
285
|
-
height = this.GetItemSize(this.startIndex);
|
|
286
|
-
this.SetItemPosition(item, this.startBoundary - height);
|
|
287
|
-
this.RefreshBeginBundary();
|
|
288
|
-
}
|
|
289
|
-
this.RecycleEnd();
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
private Leftward = () => {
|
|
293
|
-
// console.log("---------- Leftward ------------")
|
|
294
|
-
// console.log("---------- this.endBoundary:",this.endBoundary, this.curScrollOffset, this.endIndex, " ------------")
|
|
295
|
-
while ((this.endIndex < this.itemCount - 1) && this.endBoundary < (this.curScrollOffset + this.viewWidth + this.cacheNumber * this.defaultItemSize ))//
|
|
296
|
-
{
|
|
297
|
-
this.endIndex++;
|
|
298
|
-
// console.log("---------- this.endIndex:", this.endIndex," ------------")
|
|
299
|
-
let item = this.CreateItem(this.endIndex);
|
|
300
|
-
this.itemMap[`${this.endIndex}`] = item;
|
|
301
|
-
this.SetItemPosition(item, this.endBoundary);
|
|
302
|
-
this.RefreshEndBundary();
|
|
303
|
-
this.CalculateContentSize();
|
|
304
|
-
}
|
|
305
|
-
this.RecycleBegin();
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
private Rightward = () => {
|
|
309
|
-
// console.log("---------- Rightward ------------")
|
|
310
|
-
// console.log("---------- this.startBoundary:",this.startBoundary, this.curScrollOffset, this.startIndex, " ------------")
|
|
311
|
-
while (this.startIndex > 0 && this.curScrollOffset <= this.startBoundary) {
|
|
312
|
-
this.startIndex--;
|
|
313
|
-
let item = this.CreateItem(this.startIndex);
|
|
314
|
-
this.itemMap[`${this.startIndex}`] = item;
|
|
315
|
-
let width = 0;
|
|
316
|
-
width = this.GetItemSize(this.startIndex);
|
|
317
|
-
this.SetItemPosition(item, this.startBoundary - width);
|
|
318
|
-
this.RefreshBeginBundary();
|
|
319
|
-
}
|
|
320
|
-
this.RecycleEnd();
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
private SetItemPosition = (item, itemPos) => {
|
|
324
|
-
// console.log("---------- SetItemPosition itemPos:",itemPos," ------------")
|
|
325
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
326
|
-
// console.log("---------- this.scorllDirection == Direction.Horizontal ------------")
|
|
327
|
-
item.style.left = `${itemPos}`;
|
|
328
|
-
}
|
|
329
|
-
else
|
|
330
|
-
item.style.top = `${itemPos}`;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
private RefreshEndBundary = () => {
|
|
334
|
-
// console.log("----------@@@ this.endIndex :",this.endIndex," ------------")
|
|
335
|
-
// console.log("----------@@@ RefreshEndBundary:",this.endBoundary," ------------")
|
|
336
|
-
let item = this.itemMap[`${this.endIndex}`];
|
|
337
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
338
|
-
let curLeft = parseInt(item.style.left);
|
|
339
|
-
let width = 0;
|
|
340
|
-
width = this.GetItemSize(this.endIndex);
|
|
341
|
-
this.endBoundary = curLeft + width;
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
let curTop = parseInt(item.style.top);
|
|
345
|
-
let height = 0;
|
|
346
|
-
height = this.GetItemSize(this.endIndex);
|
|
347
|
-
this.endBoundary = curTop + height;
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
private RefreshBeginBundary = () => {
|
|
352
|
-
if(this.CalculateItemSizeFunc != undefined) {
|
|
353
|
-
this.startBoundary = this.GetItemsRange(0, this.startIndex - 1) ;
|
|
354
|
-
}
|
|
355
|
-
else
|
|
356
|
-
this.startBoundary = this.itemSize * this.startIndex;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
private CalculateContentSize = () => {
|
|
360
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
361
|
-
this.containerWidth = this.endBoundary ;
|
|
362
|
-
this.contentDiv.style.width = `${this.containerWidth}`;
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
this.containerHeight = this.endBoundary ;
|
|
366
|
-
this.contentDiv.style.height = `${this.containerHeight}`;
|
|
367
|
-
}
|
|
368
|
-
// console.log("----------CalculateContentSize height:",height,"------------")
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
private IsItemUpOfViewport = (index, item) => {
|
|
372
|
-
let itemOffset = 0;
|
|
373
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
374
|
-
itemOffset = parseInt(item.style.left);
|
|
375
|
-
else
|
|
376
|
-
itemOffset = parseInt(item.style.top);
|
|
377
|
-
|
|
378
|
-
let curSize = 0;
|
|
379
|
-
if(this.CalculateItemSizeFunc != undefined) {
|
|
380
|
-
curSize = this.CalculateItemSizeFunc(index);
|
|
381
|
-
}
|
|
382
|
-
else
|
|
383
|
-
curSize = this.itemSize;
|
|
384
|
-
if((itemOffset + curSize) < this.curScrollOffset) {
|
|
385
|
-
// console.log("----------IsItemUpOfViewport true------------")
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
// console.log("----------IsItemUpOfViewport false------------")
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
private IsItemBottomOfViewport = (item) => {
|
|
395
|
-
let itemOffset = 0;
|
|
396
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
397
|
-
itemOffset = parseInt(item.style.left);
|
|
398
|
-
if(itemOffset > this.curScrollOffset + this.viewWidth ) {
|
|
399
|
-
return true;
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
// console.log("----------IsItemBottomOfViewport false------------")
|
|
403
|
-
return false;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
itemOffset = parseInt(item.style.top);
|
|
408
|
-
if(itemOffset > this.curScrollOffset + this.viewHeight ) {
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
// console.log("----------IsItemBottomOfViewport false------------")
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
private RecycleBegin = () => {
|
|
419
|
-
// if(IsInRange())
|
|
420
|
-
// {
|
|
421
|
-
// return;
|
|
422
|
-
// }
|
|
423
|
-
let i = this.startIndex;
|
|
424
|
-
while(i <= this.endIndex) {
|
|
425
|
-
let item = this.itemMap[`${i}`];
|
|
426
|
-
if(item != undefined ) {
|
|
427
|
-
if(this.IsItemUpOfViewport(i, item)) {
|
|
428
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
429
|
-
item.style.left = `${-(this.viewWidth)}`;
|
|
430
|
-
else
|
|
431
|
-
item.style.top = `${-(this.viewHeight)}`;
|
|
432
|
-
// console.log('push item');
|
|
433
|
-
item.style.display = 'none';
|
|
434
|
-
this.itemPool.push(item);
|
|
435
|
-
this.startIndex++;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
i++;
|
|
442
|
-
}
|
|
443
|
-
this.RefreshBeginBundary();
|
|
444
|
-
// console.log("----------RecycleBegin startIndex:",this.startIndex,"------------")
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
private RecycleEnd = () => {
|
|
448
|
-
|
|
449
|
-
// if(IsInRange())
|
|
450
|
-
// {
|
|
451
|
-
// return;
|
|
452
|
-
// }
|
|
453
|
-
|
|
454
|
-
let i = this.endIndex;
|
|
455
|
-
while(i >= this.startIndex) {
|
|
456
|
-
let item = this.itemMap[`${i}`];
|
|
457
|
-
if(item != undefined ) {
|
|
458
|
-
if(this.IsItemBottomOfViewport(item)) {
|
|
459
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
460
|
-
item.style.left = `${-(this.viewWidth)}`;
|
|
461
|
-
else
|
|
462
|
-
item.style.top = `${-(this.viewHeight)}`;
|
|
463
|
-
item.style.display = 'none';
|
|
464
|
-
this.itemPool.push(item);
|
|
465
|
-
this.endIndex--;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
i--;
|
|
472
|
-
}
|
|
473
|
-
this.RefreshEndBundary();
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
private IsInRange = () => {
|
|
477
|
-
let isInRange = true;
|
|
478
|
-
const range = this.GetItemsRange(this.startIndex, this.endIndex - 1);
|
|
479
|
-
if(this.scorllDirection == Direction.Horizontal) {
|
|
480
|
-
if(range < this.viewWidth)
|
|
481
|
-
isInRange = false;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
if(range < this.viewHeight)
|
|
485
|
-
isInRange = false;
|
|
486
|
-
}
|
|
487
|
-
return isInRange;
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
private GetItemsRange = (start, end) => {
|
|
491
|
-
let range = 0;
|
|
492
|
-
for(let begin = start; begin <= end; begin++) {
|
|
493
|
-
if(this.itemMap[`${begin}`] != undefined) {
|
|
494
|
-
|
|
495
|
-
range = range + this.GetItemSize(begin);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return range;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
private RecycleAll = () => {
|
|
502
|
-
// console.log("----------------- RecycleAll ---------------- ")
|
|
503
|
-
for(let i = this.startIndex; i < this.endIndex; i++) {
|
|
504
|
-
let item = this.itemMap[`${i}`];
|
|
505
|
-
if(item != undefined ) {
|
|
506
|
-
if(this.scorllDirection == Direction.Horizontal)
|
|
507
|
-
item.style.left = `${-(this.viewWidth)}`;
|
|
508
|
-
else
|
|
509
|
-
item.style.top = `${-(this.viewHeight)}`;
|
|
510
|
-
// console.log('push item');
|
|
511
|
-
item.style.display = 'none';
|
|
512
|
-
this.itemPool.push(item);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
}
|
|
1
|
+
export const Direction = {
|
|
2
|
+
Horizontal: 0,
|
|
3
|
+
Vertical: 1,
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
Object.freeze(Direction);
|
|
7
|
+
|
|
8
|
+
export class TinyList {
|
|
9
|
+
private startIndex = 0;
|
|
10
|
+
private endIndex = -1;
|
|
11
|
+
private startBoundary = 0;
|
|
12
|
+
private endBoundary = 0;
|
|
13
|
+
private containerWidth = 0;
|
|
14
|
+
private viewHeight = 0;
|
|
15
|
+
private viewWidth = 0;
|
|
16
|
+
private containerHeight = 0;
|
|
17
|
+
private scorllDirection = Direction.Vertical;
|
|
18
|
+
|
|
19
|
+
private itemSize = 0;
|
|
20
|
+
private defaultItemSize = 200;
|
|
21
|
+
|
|
22
|
+
private viewDiv;
|
|
23
|
+
private contentDiv;
|
|
24
|
+
|
|
25
|
+
private itemCount = 0;
|
|
26
|
+
private itemPool: any[] = [];
|
|
27
|
+
private itemMap = {};
|
|
28
|
+
private itemSizeList: any[] = [];
|
|
29
|
+
private MOVE_DELTA = 5;
|
|
30
|
+
private curScrollOffset = 0;
|
|
31
|
+
private fillItemFunc;
|
|
32
|
+
private onStartFunc;
|
|
33
|
+
private onEndFunc;
|
|
34
|
+
private CalculateItemSizeFunc;
|
|
35
|
+
|
|
36
|
+
private cacheNumber = 0;//多缓存几个数量
|
|
37
|
+
|
|
38
|
+
//root:该瀑布流组件根节点
|
|
39
|
+
//count:当前列表的数量
|
|
40
|
+
//viewSize:瀑布流组件viewSize,高或宽超出部分不显示
|
|
41
|
+
//direction:方向,暂时仅支持垂直
|
|
42
|
+
//calculatedSize:单元格固定尺寸,可设置为一个计算单元格高度的函数。
|
|
43
|
+
//cacheNum:滑动过快的话,可稍微增加几个缓存,设置缓存数量。
|
|
44
|
+
//fillFunc:填充具体对应的Item函数委托
|
|
45
|
+
public CreateList = (root, count, viewSize, direction, calculatedSize, cacheNum, fillFunc)=> {
|
|
46
|
+
if(root != undefined) {
|
|
47
|
+
this.itemCount = count;
|
|
48
|
+
this.scorllDirection = direction;
|
|
49
|
+
this.cacheNumber = cacheNum;
|
|
50
|
+
if (typeof calculatedSize == 'function') {
|
|
51
|
+
// console.log('--------------- this.itemSize is Funtion -------------------')
|
|
52
|
+
this.CalculateItemSizeFunc = calculatedSize;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// console.log('--------------- this.itemSize is size Num -------------------')
|
|
56
|
+
this.itemSize = calculatedSize;
|
|
57
|
+
}
|
|
58
|
+
this.viewDiv = document.createElement('div');
|
|
59
|
+
this.viewDiv.style.position = 'relative';
|
|
60
|
+
this.viewDiv.style.overflow = 'scroll';
|
|
61
|
+
this.viewDiv.style.willChange = 'transform';
|
|
62
|
+
this.viewDiv.style.left = '0px';
|
|
63
|
+
this.viewDiv.style.top = '0px';
|
|
64
|
+
|
|
65
|
+
this.viewDiv.addEventListener('scroll', this.onScroll);
|
|
66
|
+
root.appendChild(this.viewDiv);
|
|
67
|
+
//创建一个contener
|
|
68
|
+
this.contentDiv = document.createElement('div');
|
|
69
|
+
|
|
70
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
71
|
+
this.viewWidth = viewSize ;
|
|
72
|
+
this.viewDiv.style.flexDirection = 'row';
|
|
73
|
+
// this.viewDiv.style.height = `100%`;
|
|
74
|
+
this.viewDiv.style.height = '400px';
|
|
75
|
+
this.viewDiv.style.width = `${viewSize}px`;
|
|
76
|
+
this.viewWidth = viewSize ;
|
|
77
|
+
this.contentDiv.style.height = '100%';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.viewDiv.style.flexDirection = 'column';
|
|
81
|
+
this.viewDiv.style.height = `${viewSize}px`;
|
|
82
|
+
this.viewDiv.style.width = '100%';
|
|
83
|
+
this.viewHeight = viewSize ;
|
|
84
|
+
this.contentDiv.style.width = '100%';
|
|
85
|
+
}
|
|
86
|
+
this.viewDiv.appendChild(this.contentDiv);
|
|
87
|
+
this.InitItemsSize(0, this.itemCount);
|
|
88
|
+
this.fillItemFunc = fillFunc;
|
|
89
|
+
this.itemMap = {};
|
|
90
|
+
this.fill();
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
console.log('---------- 未能找到瀑布流组件根节点!!!! ------------');
|
|
94
|
+
return this.viewDiv;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
private InitItemsSize = (begin, end)=> {
|
|
98
|
+
for(let i = begin; i < end; i++) {
|
|
99
|
+
this.itemSizeList[i] = -1;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
private GetItemSize = (index)=> {
|
|
104
|
+
let curSize = 0;
|
|
105
|
+
if(this.CalculateItemSizeFunc != undefined) {
|
|
106
|
+
if(this.itemSizeList[index] != undefined && this.itemSizeList[index] != -1) {
|
|
107
|
+
curSize = this.itemSizeList[index];
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
curSize = this.CalculateItemSizeFunc(index);
|
|
111
|
+
this.itemSizeList[index] = curSize;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
curSize = this.itemSize;
|
|
116
|
+
return curSize;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
public SetOnStartFunc = (onStart)=> {
|
|
120
|
+
this.onStartFunc = onStart;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
public SetOnEndFunc = (onEnd)=> {
|
|
124
|
+
this.onEndFunc = onEnd;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
private onScroll = ( event ) => {
|
|
128
|
+
// const { clientHeight, scrollHeight, scrollTop } = event.currentTarget;
|
|
129
|
+
const {scrollLeft, scrollTop } = event.currentTarget;
|
|
130
|
+
// console.log('================== scrollLeft: ', scrollLeft);
|
|
131
|
+
// console.log('================== scrollTop ', scrollTop);
|
|
132
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
133
|
+
if(scrollLeft == 0 ) {
|
|
134
|
+
if(this.onStartFunc != undefined) {
|
|
135
|
+
this.onStartFunc();
|
|
136
|
+
this.Leftward();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if(scrollLeft > 0 && (scrollLeft + this.viewWidth) >= this.endBoundary ) {
|
|
141
|
+
if(this.onEndFunc != undefined) {
|
|
142
|
+
// console.log("----------this.onEndFunc this.viewDiv scrollLeft:", scrollLeft, "------------");
|
|
143
|
+
// console.log("----------this.onEndFunc this.endBoundary:", this.endBoundary, "------------");
|
|
144
|
+
|
|
145
|
+
// console.log("---------- this.onEndFunc this.viewDiv top:", this.viewDiv.scrollTop, "------------");
|
|
146
|
+
this.onEndFunc();
|
|
147
|
+
// Rightward();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const distance = scrollLeft - this.curScrollOffset;
|
|
152
|
+
this.curScrollOffset = scrollLeft;
|
|
153
|
+
if(distance >= this.MOVE_DELTA) {
|
|
154
|
+
this.Leftward();
|
|
155
|
+
}
|
|
156
|
+
else if(distance < -this.MOVE_DELTA) {
|
|
157
|
+
this.Rightward();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if(scrollTop == 0 ) {
|
|
162
|
+
if(this.onStartFunc != undefined) {
|
|
163
|
+
this.onStartFunc();
|
|
164
|
+
this.Forward();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if(scrollTop > 0 && (scrollTop + this.viewHeight) >= this.endBoundary) {
|
|
169
|
+
if(this.onEndFunc != undefined) {
|
|
170
|
+
this.onEndFunc();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const distance = scrollTop - this.curScrollOffset;
|
|
175
|
+
this.curScrollOffset = scrollTop;
|
|
176
|
+
if(distance >= this.MOVE_DELTA) {
|
|
177
|
+
this.Forward();
|
|
178
|
+
}
|
|
179
|
+
else if(distance < -this.MOVE_DELTA) {
|
|
180
|
+
this.BackWard();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
public AppendList = (count)=> {
|
|
186
|
+
const curIndex = this.itemCount;
|
|
187
|
+
this.itemCount = this.itemCount + count;
|
|
188
|
+
this.InitItemsSize( curIndex, this.itemCount);
|
|
189
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
190
|
+
this.Leftward();
|
|
191
|
+
else
|
|
192
|
+
this.Forward();
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
private resetContentPosision = ()=> {
|
|
196
|
+
// this.viewDiv.scrollTop = 0;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
public Refresh = (count)=> {
|
|
200
|
+
this.RecycleAll();
|
|
201
|
+
this.itemCount = count;
|
|
202
|
+
this.itemSizeList = [];
|
|
203
|
+
this.InitItemsSize(0, this.itemCount);
|
|
204
|
+
this.curScrollOffset = 0;
|
|
205
|
+
this.viewDiv.scrollTop = 0;
|
|
206
|
+
this.fill();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
private fill = () => {
|
|
210
|
+
// console.log("---------- fillItem ------------")
|
|
211
|
+
this.startIndex = 0;
|
|
212
|
+
this.endIndex = -1;
|
|
213
|
+
this.startBoundary = 0;
|
|
214
|
+
this.endBoundary = 0;
|
|
215
|
+
this.containerHeight = 0;
|
|
216
|
+
this.containerWidth = 0;
|
|
217
|
+
this.curScrollOffset = 0;
|
|
218
|
+
|
|
219
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
220
|
+
this.Leftward();
|
|
221
|
+
else
|
|
222
|
+
this.Forward();
|
|
223
|
+
|
|
224
|
+
// console.log("---------- this.viewDiv left:", this.viewDiv.scrollLeft, "------------");
|
|
225
|
+
// console.log("---------- this.viewDiv top:", this.viewDiv.scrollTop, "------------");
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
private CreateItem = ( index ) => {
|
|
229
|
+
let item;
|
|
230
|
+
// console.log('CreateItem pool size:', this.itemPool.length)
|
|
231
|
+
//console.log('----------@@@@@ CreateItem:', index)
|
|
232
|
+
if(this.itemPool.length > 0) {
|
|
233
|
+
// console.log("---------- useItemPool ------------")
|
|
234
|
+
item = this.itemPool.pop();//this.itemPool[0];
|
|
235
|
+
item.style.display = 'flex';
|
|
236
|
+
item.id = 'item_' + index;
|
|
237
|
+
this.fillItemFunc(item, index);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// console.log("---------- this.itemPool is null!!! ------------")
|
|
241
|
+
if(this.fillItemFunc != undefined) {
|
|
242
|
+
item = document.createElement('div');
|
|
243
|
+
item.id = 'item_' + index;
|
|
244
|
+
this.fillItemFunc(item, index);
|
|
245
|
+
this.contentDiv.appendChild(item);
|
|
246
|
+
}
|
|
247
|
+
const curSize = this.GetItemSize(index);
|
|
248
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
249
|
+
item.style.width = `${curSize}`;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
// console.log("---------- curSize:",curSize," ------------")
|
|
253
|
+
item.style.height = `${curSize}`;
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return item;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
private Forward = () => {
|
|
261
|
+
// console.log("---------- Forward ------------")
|
|
262
|
+
// console.log("---------- this.endBoundary:",this.endBoundary, this.curScrollOffset, this.endIndex, " ------------")
|
|
263
|
+
// console.log("---------- this.itemCount:",this.itemCount, " ------------")
|
|
264
|
+
// console.log("---------- boundary:",this.curScrollOffset + this.viewHeight + this.cacheNumber*this.defaultItemSize , " ------------")
|
|
265
|
+
while ((this.endIndex < this.itemCount - 1) && this.endBoundary < (this.curScrollOffset + this.viewHeight + this.cacheNumber * this.defaultItemSize ))//this.itemSize
|
|
266
|
+
{
|
|
267
|
+
this.endIndex++;
|
|
268
|
+
let item = this.CreateItem(this.endIndex);
|
|
269
|
+
this.itemMap[`${this.endIndex}`] = item;
|
|
270
|
+
this.SetItemPosition(item, this.endBoundary);
|
|
271
|
+
this.RefreshEndBundary();
|
|
272
|
+
this.CalculateContentSize();
|
|
273
|
+
}
|
|
274
|
+
this.RecycleBegin();
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
private BackWard = () => {
|
|
278
|
+
// console.log("---------- BackWard ------------")
|
|
279
|
+
// console.log("---------- this.startBoundary:",this.startBoundary, this.curScrollOffset, this.startIndex, " ------------")
|
|
280
|
+
while (this.startIndex > 0 && this.curScrollOffset <= this.startBoundary) {
|
|
281
|
+
this.startIndex--;
|
|
282
|
+
let item = this.CreateItem(this.startIndex);
|
|
283
|
+
this.itemMap[`${this.startIndex}`] = item;
|
|
284
|
+
let height = 0;
|
|
285
|
+
height = this.GetItemSize(this.startIndex);
|
|
286
|
+
this.SetItemPosition(item, this.startBoundary - height);
|
|
287
|
+
this.RefreshBeginBundary();
|
|
288
|
+
}
|
|
289
|
+
this.RecycleEnd();
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
private Leftward = () => {
|
|
293
|
+
// console.log("---------- Leftward ------------")
|
|
294
|
+
// console.log("---------- this.endBoundary:",this.endBoundary, this.curScrollOffset, this.endIndex, " ------------")
|
|
295
|
+
while ((this.endIndex < this.itemCount - 1) && this.endBoundary < (this.curScrollOffset + this.viewWidth + this.cacheNumber * this.defaultItemSize ))//
|
|
296
|
+
{
|
|
297
|
+
this.endIndex++;
|
|
298
|
+
// console.log("---------- this.endIndex:", this.endIndex," ------------")
|
|
299
|
+
let item = this.CreateItem(this.endIndex);
|
|
300
|
+
this.itemMap[`${this.endIndex}`] = item;
|
|
301
|
+
this.SetItemPosition(item, this.endBoundary);
|
|
302
|
+
this.RefreshEndBundary();
|
|
303
|
+
this.CalculateContentSize();
|
|
304
|
+
}
|
|
305
|
+
this.RecycleBegin();
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
private Rightward = () => {
|
|
309
|
+
// console.log("---------- Rightward ------------")
|
|
310
|
+
// console.log("---------- this.startBoundary:",this.startBoundary, this.curScrollOffset, this.startIndex, " ------------")
|
|
311
|
+
while (this.startIndex > 0 && this.curScrollOffset <= this.startBoundary) {
|
|
312
|
+
this.startIndex--;
|
|
313
|
+
let item = this.CreateItem(this.startIndex);
|
|
314
|
+
this.itemMap[`${this.startIndex}`] = item;
|
|
315
|
+
let width = 0;
|
|
316
|
+
width = this.GetItemSize(this.startIndex);
|
|
317
|
+
this.SetItemPosition(item, this.startBoundary - width);
|
|
318
|
+
this.RefreshBeginBundary();
|
|
319
|
+
}
|
|
320
|
+
this.RecycleEnd();
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
private SetItemPosition = (item, itemPos) => {
|
|
324
|
+
// console.log("---------- SetItemPosition itemPos:",itemPos," ------------")
|
|
325
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
326
|
+
// console.log("---------- this.scorllDirection == Direction.Horizontal ------------")
|
|
327
|
+
item.style.left = `${itemPos}`;
|
|
328
|
+
}
|
|
329
|
+
else
|
|
330
|
+
item.style.top = `${itemPos}`;
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
private RefreshEndBundary = () => {
|
|
334
|
+
// console.log("----------@@@ this.endIndex :",this.endIndex," ------------")
|
|
335
|
+
// console.log("----------@@@ RefreshEndBundary:",this.endBoundary," ------------")
|
|
336
|
+
let item = this.itemMap[`${this.endIndex}`];
|
|
337
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
338
|
+
let curLeft = parseInt(item.style.left);
|
|
339
|
+
let width = 0;
|
|
340
|
+
width = this.GetItemSize(this.endIndex);
|
|
341
|
+
this.endBoundary = curLeft + width;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
let curTop = parseInt(item.style.top);
|
|
345
|
+
let height = 0;
|
|
346
|
+
height = this.GetItemSize(this.endIndex);
|
|
347
|
+
this.endBoundary = curTop + height;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
private RefreshBeginBundary = () => {
|
|
352
|
+
if(this.CalculateItemSizeFunc != undefined) {
|
|
353
|
+
this.startBoundary = this.GetItemsRange(0, this.startIndex - 1) ;
|
|
354
|
+
}
|
|
355
|
+
else
|
|
356
|
+
this.startBoundary = this.itemSize * this.startIndex;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
private CalculateContentSize = () => {
|
|
360
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
361
|
+
this.containerWidth = this.endBoundary ;
|
|
362
|
+
this.contentDiv.style.width = `${this.containerWidth}`;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
this.containerHeight = this.endBoundary ;
|
|
366
|
+
this.contentDiv.style.height = `${this.containerHeight}`;
|
|
367
|
+
}
|
|
368
|
+
// console.log("----------CalculateContentSize height:",height,"------------")
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
private IsItemUpOfViewport = (index, item) => {
|
|
372
|
+
let itemOffset = 0;
|
|
373
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
374
|
+
itemOffset = parseInt(item.style.left);
|
|
375
|
+
else
|
|
376
|
+
itemOffset = parseInt(item.style.top);
|
|
377
|
+
|
|
378
|
+
let curSize = 0;
|
|
379
|
+
if(this.CalculateItemSizeFunc != undefined) {
|
|
380
|
+
curSize = this.CalculateItemSizeFunc(index);
|
|
381
|
+
}
|
|
382
|
+
else
|
|
383
|
+
curSize = this.itemSize;
|
|
384
|
+
if((itemOffset + curSize) < this.curScrollOffset) {
|
|
385
|
+
// console.log("----------IsItemUpOfViewport true------------")
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// console.log("----------IsItemUpOfViewport false------------")
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
private IsItemBottomOfViewport = (item) => {
|
|
395
|
+
let itemOffset = 0;
|
|
396
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
397
|
+
itemOffset = parseInt(item.style.left);
|
|
398
|
+
if(itemOffset > this.curScrollOffset + this.viewWidth ) {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
// console.log("----------IsItemBottomOfViewport false------------")
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
itemOffset = parseInt(item.style.top);
|
|
408
|
+
if(itemOffset > this.curScrollOffset + this.viewHeight ) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
// console.log("----------IsItemBottomOfViewport false------------")
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
private RecycleBegin = () => {
|
|
419
|
+
// if(IsInRange())
|
|
420
|
+
// {
|
|
421
|
+
// return;
|
|
422
|
+
// }
|
|
423
|
+
let i = this.startIndex;
|
|
424
|
+
while(i <= this.endIndex) {
|
|
425
|
+
let item = this.itemMap[`${i}`];
|
|
426
|
+
if(item != undefined ) {
|
|
427
|
+
if(this.IsItemUpOfViewport(i, item)) {
|
|
428
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
429
|
+
item.style.left = `${-(this.viewWidth)}`;
|
|
430
|
+
else
|
|
431
|
+
item.style.top = `${-(this.viewHeight)}`;
|
|
432
|
+
// console.log('push item');
|
|
433
|
+
item.style.display = 'none';
|
|
434
|
+
this.itemPool.push(item);
|
|
435
|
+
this.startIndex++;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
i++;
|
|
442
|
+
}
|
|
443
|
+
this.RefreshBeginBundary();
|
|
444
|
+
// console.log("----------RecycleBegin startIndex:",this.startIndex,"------------")
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
private RecycleEnd = () => {
|
|
448
|
+
|
|
449
|
+
// if(IsInRange())
|
|
450
|
+
// {
|
|
451
|
+
// return;
|
|
452
|
+
// }
|
|
453
|
+
|
|
454
|
+
let i = this.endIndex;
|
|
455
|
+
while(i >= this.startIndex) {
|
|
456
|
+
let item = this.itemMap[`${i}`];
|
|
457
|
+
if(item != undefined ) {
|
|
458
|
+
if(this.IsItemBottomOfViewport(item)) {
|
|
459
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
460
|
+
item.style.left = `${-(this.viewWidth)}`;
|
|
461
|
+
else
|
|
462
|
+
item.style.top = `${-(this.viewHeight)}`;
|
|
463
|
+
item.style.display = 'none';
|
|
464
|
+
this.itemPool.push(item);
|
|
465
|
+
this.endIndex--;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
i--;
|
|
472
|
+
}
|
|
473
|
+
this.RefreshEndBundary();
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
private IsInRange = () => {
|
|
477
|
+
let isInRange = true;
|
|
478
|
+
const range = this.GetItemsRange(this.startIndex, this.endIndex - 1);
|
|
479
|
+
if(this.scorllDirection == Direction.Horizontal) {
|
|
480
|
+
if(range < this.viewWidth)
|
|
481
|
+
isInRange = false;
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
if(range < this.viewHeight)
|
|
485
|
+
isInRange = false;
|
|
486
|
+
}
|
|
487
|
+
return isInRange;
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
private GetItemsRange = (start, end) => {
|
|
491
|
+
let range = 0;
|
|
492
|
+
for(let begin = start; begin <= end; begin++) {
|
|
493
|
+
if(this.itemMap[`${begin}`] != undefined) {
|
|
494
|
+
|
|
495
|
+
range = range + this.GetItemSize(begin);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return range;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
private RecycleAll = () => {
|
|
502
|
+
// console.log("----------------- RecycleAll ---------------- ")
|
|
503
|
+
for(let i = this.startIndex; i < this.endIndex; i++) {
|
|
504
|
+
let item = this.itemMap[`${i}`];
|
|
505
|
+
if(item != undefined ) {
|
|
506
|
+
if(this.scorllDirection == Direction.Horizontal)
|
|
507
|
+
item.style.left = `${-(this.viewWidth)}`;
|
|
508
|
+
else
|
|
509
|
+
item.style.top = `${-(this.viewHeight)}`;
|
|
510
|
+
// console.log('push item');
|
|
511
|
+
item.style.display = 'none';
|
|
512
|
+
this.itemPool.push(item);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
}
|