pixuireactcomponents 1.2.2 → 1.2.31
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/index.d.ts +15 -0
- package/index.js +16 -20
- package/package.json +9 -9
- package/tools/EventDispatcherJs.d.ts +10 -0
- package/tools/EventDispatcherJs.js +71 -0
- package/tools/Logger.d.ts +6 -0
- package/tools/Logger.js +138 -0
- package/ui/components/button/Button.d.ts +5 -0
- package/ui/components/button/Button.js +37 -0
- package/ui/components/carousel/Carousel.d.ts +5 -0
- package/ui/components/carousel/Carousel.js +219 -0
- package/ui/components/dropdown/Dropdown.d.ts +30 -0
- package/ui/components/dropdown/Dropdown.js +92 -0
- package/ui/components/dropdown/DropdownOptionUI.d.ts +11 -0
- package/ui/components/dropdown/DropdownOptionUI.js +28 -0
- package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +9 -0
- package/ui/components/dropdown/DropdownSpreadMainUI.js +27 -0
- package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +9 -0
- package/ui/components/dropdown/DropdownUnspreadMainUI.js +27 -0
- package/ui/components/gradient/GradientText.d.ts +63 -0
- package/ui/components/gradient/{GradientText.tsx → GradientText.js} +174 -183
- package/ui/components/outlinetext/OutlineText.d.ts +94 -0
- package/ui/components/outlinetext/OutlineText.js +168 -0
- package/ui/components/progress/Progress.d.ts +34 -0
- package/ui/components/progress/Progress.js +142 -0
- package/ui/components/slapface/Slapface.d.ts +12 -0
- package/ui/components/slapface/Slapface.js +235 -0
- package/ui/components/slider/Slider.d.ts +57 -0
- package/ui/components/slider/Slider.js +289 -0
- package/ui/components/tab/Tab.d.ts +6 -0
- package/ui/components/tab/Tab.js +27 -0
- package/ui/components/tab/Tabs.d.ts +12 -0
- package/ui/components/tab/Tabs.js +54 -0
- package/cmdAfterTsBuild.js +0 -8
- package/tools/EventDispatcherJs.tsx +0 -74
- package/tools/Logger.tsx +0 -161
- package/tools/img/logger.png +0 -0
- package/tsconfig.json +0 -45
- package/ui/components/bulletscreen/BulletItemAnimation.tsx +0 -117
- package/ui/components/bulletscreen/BulletScreenAnimation.tsx +0 -278
- package/ui/components/bulletscreen/bullet.less +0 -17
- package/ui/components/button/Button.tsx +0 -18
- package/ui/components/carousel/Carousel.tsx +0 -279
- package/ui/components/checkBox/CheckBox.tsx +0 -40
- package/ui/components/dropdown/Dropdown.tsx +0 -126
- package/ui/components/dropdown/DropdownOptionUI.tsx +0 -14
- package/ui/components/dropdown/DropdownSpreadMainUI.tsx +0 -11
- package/ui/components/dropdown/DropdownUnspreadMainUI.tsx +0 -11
- package/ui/components/outlinetext/OutlineText.tsx +0 -184
- package/ui/components/progress/Progress.tsx +0 -174
- package/ui/components/slapface/Slapface.tsx +0 -284
- package/ui/components/slider/Slider.tsx +0 -366
- package/ui/components/tab/Tab.tsx +0 -12
- package/ui/components/tab/Tabs.tsx +0 -56
- package/ui/components/togglegroup/ToggleGroup.tsx +0 -105
- package/ui/components/videoplayer/VideoPlayer.tsx +0 -200
- package/ui/components/waterfallcomponent/WaterfallComponent.jsx +0 -687
- package/ui/components/waterfallcomponent/less/WaterfallComponent.less +0 -13
- package/ui/sample/Images.tsx +0 -60
- package/ui/sample/OutlineText/OutlineDemo.tsx +0 -61
- package/ui/sample/Slapface/SlapfaceDemo.tsx +0 -30
- package/ui/sample/asset/btn_close.png +0 -0
- package/ui/sample/asset/changtai_button.jpg +0 -0
- package/ui/sample/asset/checkbox0.png +0 -0
- package/ui/sample/asset/checkbox1.png +0 -0
- package/ui/sample/asset/data_arrow_down.png +0 -0
- package/ui/sample/asset/data_arrow_up.png +0 -0
- package/ui/sample/asset/dot.png +0 -0
- package/ui/sample/asset/inner.png +0 -0
- package/ui/sample/asset/item_reddot.png +0 -0
- package/ui/sample/asset/loading.png +0 -0
- package/ui/sample/asset/money_dropdown.png +0 -0
- package/ui/sample/asset/money_dropdownall.png +0 -0
- package/ui/sample/asset/outer.png +0 -0
- package/ui/sample/asset/slapface_samplepic1.png +0 -0
- package/ui/sample/asset/slapface_samplepic2.png +0 -0
- package/ui/sample/asset/slapface_samplepic3.png +0 -0
- package/ui/sample/asset/slapface_samplepic4.png +0 -0
- package/ui/sample/asset/slapface_samplepic5.png +0 -0
- package/ui/sample/asset/slapface_samplepic6.png +0 -0
- package/ui/sample/asset/tab_choosed.png +0 -0
- package/ui/sample/asset/tabs_bg.png +0 -0
- package/ui/sample/asset/video_pause.png +0 -0
- package/ui/sample/asset/video_play.png +0 -0
- package/ui/sample/asset/video_reload.png +0 -0
- package/ui/sample/asset/xuanfu_button.jpg +0 -0
- package/ui/sample/asset/yaxia_button.jpg +0 -0
- package/ui/sample/bulletscreen/BulletDemo.tsx +0 -84
- package/ui/sample/button/ButtonDemo.tsx +0 -19
- package/ui/sample/carousel/carouselDemo.tsx +0 -52
- package/ui/sample/checkBox/checkBoxDemo.tsx +0 -7
- package/ui/sample/dropdown/DropdownDemo.tsx +0 -65
- package/ui/sample/dropdown/MoneyDropdownOption.tsx +0 -50
- package/ui/sample/dropdown/MoneyDropdownSpreadMain.tsx +0 -42
- package/ui/sample/dropdown/MoneyDropdownUnspreadMain.tsx +0 -44
- package/ui/sample/gradient/GradientDemo.tsx +0 -51
- package/ui/sample/less/video.less +0 -144
- package/ui/sample/progress/ProgressDemo.tsx +0 -74
- package/ui/sample/slider/SliderDemo.tsx +0 -116
- package/ui/sample/tab/TabDemo.tsx +0 -67
- package/ui/sample/tab/TopTab.tsx +0 -74
- package/ui/sample/togglegroup/ToggleGroupDemo.tsx +0 -35
- package/ui/sample/videoplayer/VideoPlayerDemo.tsx +0 -57
- package/ui/sample/waterfallcomponent/WaterfallComponentDemo.jsx +0 -137
|
@@ -1,687 +0,0 @@
|
|
|
1
|
-
import { Component } from "preact";
|
|
2
|
-
import {WaterfallComponentLess} from "./less/WaterfallComponent.less"
|
|
3
|
-
|
|
4
|
-
const PROPS_KEY_MAP = {
|
|
5
|
-
vertical: {
|
|
6
|
-
size: "clientHeight",
|
|
7
|
-
scrollSize: "scrollHeight",
|
|
8
|
-
fromTop: "scrollTop",
|
|
9
|
-
sizeDir: "height",
|
|
10
|
-
dragDir: "clientY",
|
|
11
|
-
marginTop: "marginTop",
|
|
12
|
-
marginBottom: "marginBottom",
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
horizontal: {
|
|
16
|
-
size: "clientWidth",
|
|
17
|
-
scrollSize: "scrollWidth",
|
|
18
|
-
fromTop: "scrollLeft",
|
|
19
|
-
sizeDir: "width",
|
|
20
|
-
dragDir: "clientX",
|
|
21
|
-
marginTop: "marginLeft",
|
|
22
|
-
marginBottom: "marginRight",
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/*
|
|
27
|
-
瀑布流组件
|
|
28
|
-
example:
|
|
29
|
-
<WaterfallComponent
|
|
30
|
-
itemCount={100}
|
|
31
|
-
onBottom={() => {
|
|
32
|
-
console.log("on bottom")
|
|
33
|
-
}}
|
|
34
|
-
onTop={() => {
|
|
35
|
-
console.log("on top")
|
|
36
|
-
}}
|
|
37
|
-
onFillItem={(index) => {
|
|
38
|
-
console.log(`Item index:${index}`);
|
|
39
|
-
return <div>{index}</div>;
|
|
40
|
-
}}
|
|
41
|
-
refObj={this.listRef}
|
|
42
|
-
>
|
|
43
|
-
</WaterfallComponent>
|
|
44
|
-
|
|
45
|
-
itemCount:item个数
|
|
46
|
-
onTop:碰到顶部触发
|
|
47
|
-
onBottom:碰到底部触发
|
|
48
|
-
onFillItem:当瀑布流需要创建新item时调用,传入当前需要展示第index个元素,需返回要展示的item
|
|
49
|
-
由外部自己填充item的样式和数据
|
|
50
|
-
refObj:可选属性,传入一个object,瀑布流把this赋值给current,方便给外部调用瀑布流的方法
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
export class WaterfallComponent extends Component {
|
|
54
|
-
constructor(props) {
|
|
55
|
-
super(props);
|
|
56
|
-
this.state = {
|
|
57
|
-
refreshTag: false,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 每次生成的item个数
|
|
61
|
-
this.GENERATE_COUNT = props.GENERATE_COUNT ? props.GENERATE_COUNT : 3;
|
|
62
|
-
this.OVERFLOW_THRESHOLD = 100;
|
|
63
|
-
this.SCROLL_TO_BOTTOM_THRESHOLD = 100;
|
|
64
|
-
|
|
65
|
-
this.scroll_type = props.scroll_type == 1? props.scroll_type:0;
|
|
66
|
-
this.scroll_bar_display = this.props.scroll_bar_display? this.props.scroll_bar_display:0
|
|
67
|
-
this.initFillCount = props.initFillCount ? props.initFillCount : 10;
|
|
68
|
-
this.scrollDir = props.scrollDir ? (props.scrollDir == 1 ? true : false) : true;
|
|
69
|
-
this.enableLog = props.enableLog || false;
|
|
70
|
-
this.itemCount = 0;
|
|
71
|
-
this.startIndex = 0;
|
|
72
|
-
this.endIndex = 0;
|
|
73
|
-
this.lastTopSize = 0;
|
|
74
|
-
this.recycleBottomHeight = props.recycleBottomHeight? (props.recycleBottomHeight>200? props.recycleBottomHeight:200):200
|
|
75
|
-
this.recycleTopHeight = props.recycleTopHeight? (props.recycleTopHeight>200? props.recycleTopHeight:200):200
|
|
76
|
-
this.generateBottomHeight = props.generateBottomHeight? (props.generateBottomHeight>200? props.generateBottomHeight:200):200
|
|
77
|
-
this.generateTopHeight = props.generateTopHeight? (props.generateTopHeight>200? props.generateTopHeight:200):200
|
|
78
|
-
this._dragData = {};
|
|
79
|
-
this.items = [];
|
|
80
|
-
this._nextFrameCall = [];
|
|
81
|
-
this._nextFrameCallHandle = undefined;
|
|
82
|
-
this.styleCache = [];
|
|
83
|
-
this.isRecycleBottomLastFrame = false;
|
|
84
|
-
this.isRecycleTopLastFrame = false;
|
|
85
|
-
this.scrollOffset = 0;
|
|
86
|
-
this.re = 1;
|
|
87
|
-
this.onScroll = props.onScroll;
|
|
88
|
-
this.refreshForBackward = false;
|
|
89
|
-
this.refreshForJumpTo = false;
|
|
90
|
-
this.backwardCache = [];
|
|
91
|
-
this.bottomHeight = this.props.bottomHeight? this.props.bottomHeight : 10;
|
|
92
|
-
this.topHeight = this.props.topHeight? this.props.topHeight : 10;
|
|
93
|
-
if (props.refObj) {
|
|
94
|
-
props.refObj.current = this;
|
|
95
|
-
}
|
|
96
|
-
this.idx = 0;
|
|
97
|
-
this.enableScroll = true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// 方便不想要log的时候屏蔽掉
|
|
102
|
-
log(...args) {
|
|
103
|
-
if (this.enableLog) console.log(args);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
refresh(scrollOffset, callback = undefined) {
|
|
108
|
-
this.setState(
|
|
109
|
-
{
|
|
110
|
-
refreshTag: !this.state.refreshTag,
|
|
111
|
-
},
|
|
112
|
-
() => {
|
|
113
|
-
this.overflowDetect();
|
|
114
|
-
if (callback) { callback(); }
|
|
115
|
-
if (scrollOffset) {
|
|
116
|
-
this.enableScroll = false;
|
|
117
|
-
this.scrollView[this.propKeyMap.fromTop] = scrollOffset;
|
|
118
|
-
}
|
|
119
|
-
else if (!this.scrollDir) {
|
|
120
|
-
this.scrollView[this.propKeyMap.fromTop] = 0
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
this.dirty = false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
reduceOnscroll(ev, fn, wait, _this) {
|
|
130
|
-
if (this.re++ > 1) { return; }
|
|
131
|
-
else {
|
|
132
|
-
fn.call(_this, ev);
|
|
133
|
-
setTimeout(() => {
|
|
134
|
-
this.re = 1;
|
|
135
|
-
}, wait);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// 挂载后
|
|
140
|
-
componentDidMount() {
|
|
141
|
-
this.log(`waterfall did mount:${this.itemCount}`);
|
|
142
|
-
this.fill()
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
//计算一个dom的size
|
|
146
|
-
_calcDomSize(dom) {
|
|
147
|
-
let size = dom[this.propKeyMap.size];
|
|
148
|
-
let marginTop = parseInt(dom.style[this.propKeyMap.marginTop]);
|
|
149
|
-
if (marginTop > 0) {
|
|
150
|
-
size += marginTop;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let marginBottom = parseInt(dom.style[this.propKeyMap.marginBottom]);
|
|
154
|
-
if (marginBottom > 0) {
|
|
155
|
-
size += marginBottom;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return size;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
//自己计算size,避免pix获取scrollHeight不正确的问题
|
|
163
|
-
_calcContentSize(includePlaceHolder) {
|
|
164
|
-
let size = 0;
|
|
165
|
-
for (let i = 0; i < this.content.childNodes.length; ++i) {
|
|
166
|
-
const dom = this.content.childNodes[i];
|
|
167
|
-
if (!includePlaceHolder) {
|
|
168
|
-
if (dom && i < this.items.length) {
|
|
169
|
-
size += this._calcDomSize(dom);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
if (dom) {
|
|
174
|
-
size += this._calcDomSize(dom);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return size;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
//计算第index个元素的底部位置
|
|
183
|
-
_calcIBottomAtIndex(index) {
|
|
184
|
-
let size = 0;
|
|
185
|
-
let tmpItems = [];
|
|
186
|
-
for (let i = 0; i < this.items.length; ++i) {
|
|
187
|
-
if (this.items[i]) {
|
|
188
|
-
tmpItems.push(this.items[i]);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
for (let i = 0; i < this.content.childNodes.length; ++i) {
|
|
192
|
-
const dom = this.content.childNodes[i];
|
|
193
|
-
const item = tmpItems[i];
|
|
194
|
-
|
|
195
|
-
if (dom && item && item.__waterfallIndex <= index && i < this.items.length) {
|
|
196
|
-
size += this._calcDomSize(dom);
|
|
197
|
-
let marginTop = parseInt(dom.style[this.propKeyMap.marginTop]);
|
|
198
|
-
if (marginTop > 0) {
|
|
199
|
-
size += marginTop;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
let marginBottom = parseInt(dom.style[this.propKeyMap.marginBottom]);
|
|
203
|
-
if (marginBottom > 0) {
|
|
204
|
-
size += marginBottom;
|
|
205
|
-
}
|
|
206
|
-
// this.log("_calcIBottomAtIndex ", item.__waterfallIndex, dom[this.propKeyMap.size], size);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return size;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
//overflow才能滚动,如果长度不够的话在后面填充一个空白的div
|
|
214
|
-
overflowDetect() {
|
|
215
|
-
|
|
216
|
-
setTimeout(() => {
|
|
217
|
-
const clientSize = this.scrollView[this.propKeyMap.size];
|
|
218
|
-
const scrollSize = this._calcContentSize(true);
|
|
219
|
-
const realScrollSize = this._calcContentSize();
|
|
220
|
-
|
|
221
|
-
if (clientSize >= realScrollSize && realScrollSize >= scrollSize) {
|
|
222
|
-
let sizeDir = (clientSize - scrollSize + 10) + "px";
|
|
223
|
-
let style = { width: "10px", height: "10px" };//, backgroundColor:"white"};
|
|
224
|
-
style[this.propKeyMap.sizeDir] = sizeDir;
|
|
225
|
-
this.log("overflowDetect ", clientSize, scrollSize, sizeDir);
|
|
226
|
-
|
|
227
|
-
this.placeHolderItem = <div id="placeholder" style={style}></div>;
|
|
228
|
-
|
|
229
|
-
this.refresh();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
}, this.OVERFLOW_THRESHOLD);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// 组件即将销毁
|
|
236
|
-
componentWillUnmount() { }
|
|
237
|
-
|
|
238
|
-
componentDidUpdate() {
|
|
239
|
-
if (this.scrollDir) return;
|
|
240
|
-
if (this.refreshForBackward) {
|
|
241
|
-
this.refreshForBackward = false;
|
|
242
|
-
for (let i = 0; i < this.GENERATE_COUNT; i++) {
|
|
243
|
-
this.scrollOffset += this.props.messageMap.get(this.startIndex + i)
|
|
244
|
-
console.log("this length is ", this.props.messageMap.get(this.startIndex + i))
|
|
245
|
-
}
|
|
246
|
-
this.refresh(this.scrollOffset)
|
|
247
|
-
}
|
|
248
|
-
else if (this.refreshForJumpTo) {
|
|
249
|
-
console.log("didupate")
|
|
250
|
-
this.refreshForJumpTo = false;
|
|
251
|
-
this.scrollOffset = Math.max(0, this.scrollView[this.propKeyMap.scrollSize] - this.scrollView[this.propKeyMap.size])
|
|
252
|
-
this.refresh(this.scrollOffset)
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
render(props, state) {
|
|
257
|
-
console.log("type is",this.scroll_type)
|
|
258
|
-
this.itemCount = props.itemCount ? props.itemCount : 0;
|
|
259
|
-
this.scrollTriggerTopButton = props.scrollTriggerTopButton || false;
|
|
260
|
-
this.onFillItem = props.onFillItem;
|
|
261
|
-
this.onMesureItem = props.onMesureItem;
|
|
262
|
-
this.onBottom = props.onBottom;
|
|
263
|
-
this.onTop = props.onTop;
|
|
264
|
-
this.horizontal = props.direction == "horizontal" ? true : false;
|
|
265
|
-
this.scrollbarColor = props.scrollbarColor ? props.scrollbarColor : "#00000000";
|
|
266
|
-
this.propKeyMap = PROPS_KEY_MAP[props.direction];
|
|
267
|
-
let items = this.items;
|
|
268
|
-
if (this.placeHolderItem){
|
|
269
|
-
items = this.items.concat(this.placeHolderItem);
|
|
270
|
-
this.placeHolderItem = undefined;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
<div className = {this.scroll_bar_display == 0? "":WaterfallComponentLess.scrollbar_css}
|
|
275
|
-
id={props.id ? props.id : "waterfall"}
|
|
276
|
-
inertia = "true"
|
|
277
|
-
style={{
|
|
278
|
-
width: "100%",
|
|
279
|
-
height: "100%",
|
|
280
|
-
flexDirection: this.horizontal ? "row" : "column",
|
|
281
|
-
scrollbarColor: this.scrollbarColor,
|
|
282
|
-
overflow: this.scroll_type == 0? "hidden":"scroll",
|
|
283
|
-
}}
|
|
284
|
-
ref={(div) => {
|
|
285
|
-
this.scrollView = div;
|
|
286
|
-
this.content = div;
|
|
287
|
-
}}
|
|
288
|
-
onScroll={(ev) => this.reduceOnscroll(ev, this._onScroll, 40, this)}
|
|
289
|
-
// onDragStart={this.__onDragStart}
|
|
290
|
-
// onDrag={this.__onDrag}
|
|
291
|
-
>
|
|
292
|
-
{items}
|
|
293
|
-
|
|
294
|
-
</div>
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/*
|
|
299
|
-
drag事件暂时无法实现
|
|
300
|
-
1:要额外解决drag与scroll互斥
|
|
301
|
-
2:无overflow情况下无法修改scrollTop之类的属性,也就是无法模拟滚动
|
|
302
|
-
*/
|
|
303
|
-
__onDragStart = (event) => {
|
|
304
|
-
// this.log("onDragStart " + event.clientX, event.clientY);
|
|
305
|
-
this._dragData.clientX = event.clientX;
|
|
306
|
-
this._dragData.clientY = event.clientY;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
__onDrag = (event) => {
|
|
310
|
-
const clientSize = event.currentTarget[this.propKeyMap.size];
|
|
311
|
-
const scrollSize = event.currentTarget[this.propKeyMap.scrollSize];
|
|
312
|
-
const fromTop = event.currentTarget[this.propKeyMap.fromTop];
|
|
313
|
-
// this.log("_onDrag ", clientSize, scrollSize, fromTop);
|
|
314
|
-
if (clientSize < scrollSize) {
|
|
315
|
-
this._onScroll(event);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
let delta = event[this.propKeyMap.dragDir] - this._dragData[this.propKeyMap.dragDir];
|
|
320
|
-
if (delta != 0) {
|
|
321
|
-
this.scrollView[this.propKeyMap.fromTop] = 100;
|
|
322
|
-
event.currentTarget[this.propKeyMap.fromTop] = 100;
|
|
323
|
-
this.log("_onDrag ", delta, this.scrollView[this.propKeyMap.fromTop]);
|
|
324
|
-
this._onScroll(event);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
//通过index获取size
|
|
330
|
-
_getSizeByIndex(index) {
|
|
331
|
-
if (this.styleCache[index]) {
|
|
332
|
-
return this.styleCache[index].size;
|
|
333
|
-
}
|
|
334
|
-
else if (this.onMesureItem) {
|
|
335
|
-
let size = this.onMesureItem(index);
|
|
336
|
-
return size;
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
const dom = this.content.childNodes[0];
|
|
340
|
-
let firstSize = undefined;
|
|
341
|
-
if (dom) {
|
|
342
|
-
firstSize = this._calcDomSize(dom)
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return firstSize || 40;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 滚动事件, 内部函数
|
|
350
|
-
_onScroll(event) {
|
|
351
|
-
|
|
352
|
-
if (this.onScroll) this.onScroll()
|
|
353
|
-
|
|
354
|
-
let currentTarget = event.currentTarget;
|
|
355
|
-
|
|
356
|
-
const clientSize = currentTarget[this.propKeyMap.size];
|
|
357
|
-
const scrollSize = currentTarget[this.propKeyMap.scrollSize];
|
|
358
|
-
const fromTop = currentTarget[this.propKeyMap.fromTop];
|
|
359
|
-
|
|
360
|
-
let nowTopSize = fromTop;
|
|
361
|
-
|
|
362
|
-
if (this.startIndex == 0 && fromTop < -this.topHeight) {
|
|
363
|
-
this._onTop(fromTop);
|
|
364
|
-
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (
|
|
369
|
-
this.endIndex >= this.itemCount &&
|
|
370
|
-
scrollSize - fromTop - this.bottomHeight < clientSize
|
|
371
|
-
) {
|
|
372
|
-
this._onBottom(clientSize - (scrollSize - fromTop));
|
|
373
|
-
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
this.idx++;
|
|
377
|
-
|
|
378
|
-
if (scrollSize - fromTop - clientSize < this.generateBottomHeight && nowTopSize > this.lastTopSize) {
|
|
379
|
-
if (this.isRecycleBottomLastFrame) {
|
|
380
|
-
this.isRecycleBottomLastFrame = false;
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
this.forward();
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
else if (this.scrollDir && fromTop < this.generateTopHeight && nowTopSize < this.lastTopSize) {
|
|
387
|
-
if (this.isRecycleTopLastFrame) {
|
|
388
|
-
this.isRecycleTopLastFrame = false;
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
this.backward();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
this.lastTopSize = nowTopSize;
|
|
395
|
-
// this.enableScroll = true;
|
|
396
|
-
// this.log('the startIndex now is ',this.startIndex)
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
// 顶部触发,内部函数
|
|
400
|
-
_onTop = (fromTop) => {
|
|
401
|
-
if (this.onTop) this.onTop(fromTop);
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
// 底部触发,内部函数
|
|
405
|
-
_onBottom = (fromBottom) => {
|
|
406
|
-
if (this.onBottom) this.onBottom(fromBottom);
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// 往下填充
|
|
410
|
-
fill() {
|
|
411
|
-
this.log(
|
|
412
|
-
`startIndex:${this.startIndex}, endIndex:${this.endIndex}, itemCount:${this.itemCount}`
|
|
413
|
-
);
|
|
414
|
-
if (!this.scrollView) return;
|
|
415
|
-
this.forward();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// 清除瀑布流内容
|
|
419
|
-
clear(callback = undefined) {
|
|
420
|
-
this.itemCount = 0;
|
|
421
|
-
this.startIndex = 0;
|
|
422
|
-
this.endIndex = 0;
|
|
423
|
-
this.items = [];
|
|
424
|
-
this.styleCache = [];
|
|
425
|
-
this.scrollView.scrollTop = 0;
|
|
426
|
-
this.refresh(() => {
|
|
427
|
-
// pixui要下一帧拿到的scrollHeight才正确
|
|
428
|
-
setTimeout(callback(), 1);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// 回收顶端移出view的元素
|
|
433
|
-
recycleTop() {
|
|
434
|
-
|
|
435
|
-
let clientSize = this.scrollView[this.propKeyMap.size];
|
|
436
|
-
let scrollSize = this.scrollView[this.propKeyMap.scrollSize];
|
|
437
|
-
let fromTop = this.scrollView[this.propKeyMap.fromTop];
|
|
438
|
-
let accTop = fromTop;
|
|
439
|
-
let accRecycleHeight = 0;
|
|
440
|
-
if (
|
|
441
|
-
this.content &&
|
|
442
|
-
this.content.childNodes &&
|
|
443
|
-
this.content.childNodes.length > 1
|
|
444
|
-
) {
|
|
445
|
-
|
|
446
|
-
for (let i = 0; i < this.items.length - 1; ++i) {
|
|
447
|
-
const dom = this.content.childNodes[i];
|
|
448
|
-
if (!dom) break;
|
|
449
|
-
|
|
450
|
-
let domSize = this._calcDomSize(dom);
|
|
451
|
-
|
|
452
|
-
if (
|
|
453
|
-
accTop > domSize && scrollSize - accRecycleHeight - domSize >= scrollSize-fromTop + this.recycleTopHeight
|
|
454
|
-
) {
|
|
455
|
-
|
|
456
|
-
accTop -= domSize;
|
|
457
|
-
accRecycleHeight += domSize;
|
|
458
|
-
// this.dirty = true;
|
|
459
|
-
|
|
460
|
-
const remItem = this.items.shift();
|
|
461
|
-
this.isRecycleTopLastFrame = true;
|
|
462
|
-
this.log(
|
|
463
|
-
`removed:${remItem.key} index:${remItem.__waterfallIndex} clientSize:${domSize
|
|
464
|
-
}, accTop:${accTop}`
|
|
465
|
-
);
|
|
466
|
-
if (!this.styleCache[remItem.__waterfallIndex]) {
|
|
467
|
-
this.styleCache[remItem.__waterfallIndex] = {
|
|
468
|
-
size: domSize,
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
++this.startIndex;
|
|
472
|
-
} else {
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
scrollSize -= accRecycleHeight;
|
|
479
|
-
this.scrollOffset = Math.max(0, Math.min(accTop, scrollSize - clientSize));
|
|
480
|
-
this.lastScrollTop = this.scrollOffset;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// 往前生成item
|
|
484
|
-
forward() {
|
|
485
|
-
if (this.endIndex >= this.itemCount) return;
|
|
486
|
-
this.recycleTop();
|
|
487
|
-
const clientSize = this.scrollView[this.propKeyMap.size];
|
|
488
|
-
const scrollSize = this._calcContentSize()
|
|
489
|
-
const fromTop = this.scrollView[this.propKeyMap.fromTop];
|
|
490
|
-
|
|
491
|
-
if (scrollSize - fromTop - clientSize < this.generateBottomHeight) {
|
|
492
|
-
const genCount =
|
|
493
|
-
this.items.length < 1 ? this.initFillCount : this.GENERATE_COUNT;
|
|
494
|
-
for (let i = 0; i < genCount && this.endIndex < this.itemCount; ++i) {
|
|
495
|
-
const item = this.onFillItem(this.endIndex, this.props.itemPorps);
|
|
496
|
-
item.__waterfallIndex = this.endIndex;
|
|
497
|
-
this.items.push(item);
|
|
498
|
-
++this.endIndex;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
this.dirty = true;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
if (this.dirty) {
|
|
506
|
-
this.refresh(this.scrollOffset);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// 回收底部端移出view的元素
|
|
512
|
-
recycleBottom() {
|
|
513
|
-
const clientSize = this.scrollView[this.propKeyMap.size];
|
|
514
|
-
let accHeight = 0;
|
|
515
|
-
const outOfViewHeight = clientSize + this.recycleBottomHeight;
|
|
516
|
-
|
|
517
|
-
if (
|
|
518
|
-
this.content &&
|
|
519
|
-
this.content.childNodes &&
|
|
520
|
-
this.content.childNodes.length > 1
|
|
521
|
-
) {
|
|
522
|
-
for (let i = 0; i < this.content.childNodes.length - 1; ++i) {
|
|
523
|
-
const dom = this.content.childNodes[i];
|
|
524
|
-
if (!dom) break;
|
|
525
|
-
let domSize = this._calcDomSize(dom);
|
|
526
|
-
accHeight += domSize;
|
|
527
|
-
if (
|
|
528
|
-
accHeight >= outOfViewHeight &&
|
|
529
|
-
accHeight - domSize >= clientSize
|
|
530
|
-
) {
|
|
531
|
-
|
|
532
|
-
accHeight -= domSize;
|
|
533
|
-
const item = this.items.pop();
|
|
534
|
-
this.isRecycleBottomLastFrame = true;
|
|
535
|
-
if (item) {
|
|
536
|
-
this.styleCache[item.__waterfallIndex] = {
|
|
537
|
-
size: domSize,
|
|
538
|
-
};
|
|
539
|
-
--this.endIndex;
|
|
540
|
-
this.dirty = true;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// 顶部填充元素
|
|
548
|
-
backward(scrollOffset = undefined) {
|
|
549
|
-
if (this.startIndex <= 0) {
|
|
550
|
-
return
|
|
551
|
-
};
|
|
552
|
-
// this.enableScroll = false;
|
|
553
|
-
|
|
554
|
-
this.recycleBottom();
|
|
555
|
-
|
|
556
|
-
let fromTop = scrollOffset ? scrollOffset : this.scrollView[this.propKeyMap.fromTop];
|
|
557
|
-
|
|
558
|
-
this.scrollOffset = fromTop;
|
|
559
|
-
|
|
560
|
-
if (this.scrollDir && fromTop < this.generateTopHeight || !this.scrollDir && fromTop == 0) {
|
|
561
|
-
for (let i = 0; i < this.GENERATE_COUNT && this.startIndex > 0; ++i) {
|
|
562
|
-
|
|
563
|
-
const item = this.onFillItem(this.startIndex - 1, this.props.itemPorps);
|
|
564
|
-
item.__waterfallIndex = this.startIndex - 1;
|
|
565
|
-
this.items.unshift(item);
|
|
566
|
-
|
|
567
|
-
if(this.scrollDir) this.scrollOffset += this._getSizeByIndex(item.__waterfallIndex);
|
|
568
|
-
|
|
569
|
-
--this.startIndex;
|
|
570
|
-
}
|
|
571
|
-
this.dirty = true;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
if (this.dirty) {
|
|
575
|
-
if(!this.scrollDir) this.refreshForBackward = true;
|
|
576
|
-
this.refresh(this.scrollOffset);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
//更新某个元素
|
|
581
|
-
updateItemAtIndex(idx) {
|
|
582
|
-
for (let i = 0; i < this.items.length; ++i) {
|
|
583
|
-
let item = this.items[i];
|
|
584
|
-
if (item && idx === item.__waterfallIndex) {
|
|
585
|
-
const item = this.onFillItem(idx, this.props.itemPorps);
|
|
586
|
-
if (item == undefined) {
|
|
587
|
-
this.items.pop();
|
|
588
|
-
this.refresh();
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
item.__waterfallIndex = idx;
|
|
592
|
-
this.items.splice(i, 1, item);
|
|
593
|
-
this.refresh();
|
|
594
|
-
break;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
//更新全部元素
|
|
599
|
-
updateAllItem() {
|
|
600
|
-
// console.log("updateAllItem")
|
|
601
|
-
let top_waterfallIndex = this.items[0].__waterfallIndex;
|
|
602
|
-
let bottom_waterfallIndex = top_waterfallIndex + this.items.length;
|
|
603
|
-
for (let i = top_waterfallIndex; i < bottom_waterfallIndex; ++i) {
|
|
604
|
-
this.updateItemAtIndex(i)
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
stopScrollToItemBottom() {
|
|
609
|
-
if (this._toBottomHandler) {
|
|
610
|
-
clearInterval(this._toBottomHandler);
|
|
611
|
-
this._toBottomHandler = undefined;
|
|
612
|
-
this.log("clearInterval _toBottomHandler");
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
if (this._jumpToEndCallback) {
|
|
616
|
-
let cb = this._jumpToEndCallback;
|
|
617
|
-
this._jumpToEndCallback = undefined;
|
|
618
|
-
cb();
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
scrollToItemBottom(index) {
|
|
624
|
-
this.stopScrollToItemBottom();
|
|
625
|
-
|
|
626
|
-
this._toBottomHandler = setInterval(() => {
|
|
627
|
-
let itemPos = this._calcIBottomAtIndex(index);
|
|
628
|
-
let delta = this.scrollView[this.propKeyMap.size] + this.scrollView[this.propKeyMap.fromTop] - itemPos;
|
|
629
|
-
// this.log(delta, this.scrollView[this.propKeyMap.size], this.scrollView[this.propKeyMap.fromTop], itemPos);
|
|
630
|
-
// if (itemPos > 0 && Math.abs(delta) > 10) {
|
|
631
|
-
// this.scrollView[this.propKeyMap.fromTop] -= delta;
|
|
632
|
-
// if (this.scrollView[this.propKeyMap.fromTop] < 10) {
|
|
633
|
-
// this.backward();
|
|
634
|
-
// }
|
|
635
|
-
// }
|
|
636
|
-
if (itemPos > 0 && Math.abs(delta) > 10) {
|
|
637
|
-
this.scrollOffset -= delta;
|
|
638
|
-
if (this.scrollOffset < 10) {
|
|
639
|
-
this.backward(this.scrollOffset);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
this.stopScrollToItemBottom();
|
|
644
|
-
}
|
|
645
|
-
}, this.SCROLL_TO_BOTTOM_THRESHOLD);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
jumpTo(index, predefineGenCount, onEndCallback = undefined) {
|
|
649
|
-
this.log("jump to here")
|
|
650
|
-
this.log("jumpTo index:", index);
|
|
651
|
-
if (index >= this.itemCount) return;
|
|
652
|
-
|
|
653
|
-
let dir = index > this.startIndex ? 0 : 1;
|
|
654
|
-
|
|
655
|
-
const genCount = predefineGenCount || 10;
|
|
656
|
-
this.startIndex = index - genCount + 1;
|
|
657
|
-
this.startIndex = Math.max(this.startIndex, 0);
|
|
658
|
-
|
|
659
|
-
this.endIndex = this.startIndex;
|
|
660
|
-
this._jumpToEndCallback = onEndCallback;
|
|
661
|
-
|
|
662
|
-
this.log(
|
|
663
|
-
"jump to:" +
|
|
664
|
-
this.startIndex +
|
|
665
|
-
", " +
|
|
666
|
-
this.endIndex +
|
|
667
|
-
", itemCount:" +
|
|
668
|
-
this.itemCount
|
|
669
|
-
);
|
|
670
|
-
|
|
671
|
-
this.items = [];
|
|
672
|
-
|
|
673
|
-
//提前对齐避免偶发的滑动
|
|
674
|
-
this.scrollView[this.propKeyMap.fromTop] = 0;
|
|
675
|
-
for (let i = 0; i < genCount && this.endIndex < this.itemCount; ++i) {
|
|
676
|
-
const item = this.onFillItem(this.endIndex, this.props.itemPorps);
|
|
677
|
-
item.__waterfallIndex = this.endIndex;
|
|
678
|
-
this.items.push(item);
|
|
679
|
-
++this.endIndex;
|
|
680
|
-
}
|
|
681
|
-
// this.refresh(() => {
|
|
682
|
-
// this.scrollToItemBottom(index);
|
|
683
|
-
// });
|
|
684
|
-
this.refreshForJumpTo = true
|
|
685
|
-
this.refresh();
|
|
686
|
-
}
|
|
687
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
.frame {
|
|
2
|
-
/* border: 2px solid #990000; */
|
|
3
|
-
display: flex;
|
|
4
|
-
flex-direction: column;
|
|
5
|
-
/* flex-basis: content; */
|
|
6
|
-
/*justify-content: space-evenly;*/
|
|
7
|
-
width: 100%;
|
|
8
|
-
height: 100%;
|
|
9
|
-
}
|
|
10
|
-
.scrollbar_css{
|
|
11
|
-
scrollbar-width:"0px";
|
|
12
|
-
scrollbar-height:"0px";
|
|
13
|
-
}
|