pixuireactcomponents 1.5.45 → 1.5.47
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/package.json
CHANGED
|
@@ -96,6 +96,15 @@ export function Carousel(props) {
|
|
|
96
96
|
}); });
|
|
97
97
|
var duration = switchDuration < 1100 ? 1100 : switchDuration;
|
|
98
98
|
var _q = useState(defaultIndex), showIndex = _q[0], setShowIndex = _q[1];
|
|
99
|
+
// 监听 showIndex 变化
|
|
100
|
+
useEffect(function () {
|
|
101
|
+
console.log('[Carousel Debug] showIndex变化: ' +
|
|
102
|
+
JSON.stringify({
|
|
103
|
+
showIndex: showIndex,
|
|
104
|
+
defaultIndex: defaultIndex,
|
|
105
|
+
carouselItemsLength: children.length + 2, // 加上首尾补位
|
|
106
|
+
}));
|
|
107
|
+
}, [showIndex]);
|
|
99
108
|
//轮播元素正在滚动
|
|
100
109
|
var isMoving = useRef(false);
|
|
101
110
|
//鼠标手势信息
|
|
@@ -108,9 +117,67 @@ export function Carousel(props) {
|
|
|
108
117
|
var safeNextHandle = useRef();
|
|
109
118
|
var safePrevHandle = useRef();
|
|
110
119
|
var nextInterval = useRef();
|
|
111
|
-
|
|
120
|
+
// 初始化时关闭动画,避免初始化时尺寸变化导致的闪烁
|
|
121
|
+
var _r = useState(false), showTransition = _r[0], setShowTransition = _r[1];
|
|
112
122
|
var _s = useState([0, 0]), gestureoffset = _s[0], setGestureoffset = _s[1];
|
|
113
|
-
|
|
123
|
+
// 添加初始化保护标志
|
|
124
|
+
var isInitializing = useRef(true);
|
|
125
|
+
useEffect(function () {
|
|
126
|
+
console.log('[Carousel Debug] showTransition变化: ' +
|
|
127
|
+
JSON.stringify({
|
|
128
|
+
showTransition: showTransition,
|
|
129
|
+
compWidth: compWidth,
|
|
130
|
+
compHeight: compHeight,
|
|
131
|
+
}));
|
|
132
|
+
}, [showTransition]);
|
|
133
|
+
useEffect(function () {
|
|
134
|
+
console.log('[Carousel Debug] 尺寸变化检测: ' +
|
|
135
|
+
JSON.stringify({
|
|
136
|
+
compWidth: compWidth,
|
|
137
|
+
compHeight: compHeight,
|
|
138
|
+
currentShowIndex: showIndex,
|
|
139
|
+
defaultIndex: defaultIndex,
|
|
140
|
+
isInitializing: isInitializing.current,
|
|
141
|
+
}));
|
|
142
|
+
// 当尺寸从无效变为有效时,重置到默认索引
|
|
143
|
+
if (compWidth > 0 && compHeight > 0) {
|
|
144
|
+
// 只有在初始化期间才重置索引
|
|
145
|
+
if (isInitializing.current) {
|
|
146
|
+
console.log('[Carousel Debug] 初始化期间,重置到默认索引: ' + defaultIndex);
|
|
147
|
+
setShowIndex(defaultIndex);
|
|
148
|
+
// 确保动画关闭,避免从错误位置过渡
|
|
149
|
+
setShowTransition(false);
|
|
150
|
+
// 标记初始化完成
|
|
151
|
+
isInitializing.current = false;
|
|
152
|
+
// 延迟设置自动播放,避免立即触发动画开启逻辑
|
|
153
|
+
setTimeout(function () {
|
|
154
|
+
console.log('[Carousel Debug] 初始化完成,延迟设置自动播放');
|
|
155
|
+
setNextInterval();
|
|
156
|
+
}, 100);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, [compWidth, compHeight]);
|
|
160
|
+
// 添加调试日志
|
|
161
|
+
console.log('[Carousel Debug] 组件渲染 - props: ' +
|
|
162
|
+
JSON.stringify({
|
|
163
|
+
compWidth: compWidth,
|
|
164
|
+
compHeight: compHeight,
|
|
165
|
+
defaultIndex: defaultIndex,
|
|
166
|
+
autoplay: autoplay,
|
|
167
|
+
children: children.length,
|
|
168
|
+
}));
|
|
169
|
+
var offset = useMemo(function () {
|
|
170
|
+
var calculatedOffset = -(isVertical ? compHeight : compWidth) * showIndex;
|
|
171
|
+
console.log('[Carousel Debug] offset计算: ' +
|
|
172
|
+
JSON.stringify({
|
|
173
|
+
isVertical: isVertical,
|
|
174
|
+
compWidth: compWidth,
|
|
175
|
+
compHeight: compHeight,
|
|
176
|
+
showIndex: showIndex,
|
|
177
|
+
calculatedOffset: calculatedOffset,
|
|
178
|
+
}));
|
|
179
|
+
return calculatedOffset;
|
|
180
|
+
}, [showIndex, compHeight, compWidth]);
|
|
114
181
|
var itemBoxStyle = {
|
|
115
182
|
minWidth: compWidth + 'px',
|
|
116
183
|
minHeight: compHeight + 'px',
|
|
@@ -124,35 +191,123 @@ export function Carousel(props) {
|
|
|
124
191
|
}, [children]);
|
|
125
192
|
var isLastCarouseItem = function () { return showIndex === carouselItems.length - 1; };
|
|
126
193
|
var isFirstCarouseLastItem = function () { return showIndex === 0; };
|
|
194
|
+
var lastOnSlideChangeIndex = useRef(-1); //上一次onSlideChange的index,避免重复触发
|
|
127
195
|
useEffect(function () {
|
|
128
|
-
|
|
196
|
+
// 只有在初始化完成后才设置自动播放
|
|
197
|
+
if (!isInitializing.current) {
|
|
198
|
+
console.log('[Carousel Debug] autoplay变化,设置自动播放');
|
|
199
|
+
setNextInterval();
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.log('[Carousel Debug] 初始化期间,跳过autoplay变化处理');
|
|
203
|
+
}
|
|
129
204
|
}, [autoplay]);
|
|
130
205
|
//组件展示内容长度改变的时候改回到第一个元素,刷新autoplay判断
|
|
131
206
|
useEffect(function () {
|
|
132
|
-
|
|
133
|
-
|
|
207
|
+
console.log('[Carousel Debug] children变化: ' +
|
|
208
|
+
JSON.stringify({
|
|
209
|
+
childrenLength: children.length,
|
|
210
|
+
defaultIndex: defaultIndex,
|
|
211
|
+
compWidth: compWidth,
|
|
212
|
+
compHeight: compHeight,
|
|
213
|
+
isInitializing: isInitializing.current,
|
|
214
|
+
}));
|
|
215
|
+
// 只有在初始化完成后才设置自动播放和重置索引
|
|
216
|
+
if (!isInitializing.current) {
|
|
217
|
+
setNextInterval();
|
|
218
|
+
// 只有在尺寸有效时才重置索引,避免在初始化时干扰尺寸变化监听
|
|
219
|
+
if (compWidth > 0 && compHeight > 0) {
|
|
220
|
+
console.log('[Carousel Debug] children变化时重置索引: ' + defaultIndex);
|
|
221
|
+
setShowIndex(defaultIndex);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
console.log('[Carousel Debug] 初始化期间,跳过children变化处理');
|
|
226
|
+
}
|
|
134
227
|
}, [children]);
|
|
135
228
|
useEffect(function () {
|
|
229
|
+
console.log('[Carousel Debug] showIndex useEffect触发: ' +
|
|
230
|
+
JSON.stringify({
|
|
231
|
+
showIndex: showIndex,
|
|
232
|
+
isLast: isLastCarouseItem(),
|
|
233
|
+
isFirst: isFirstCarouseLastItem(),
|
|
234
|
+
isInitializing: isInitializing.current,
|
|
235
|
+
}));
|
|
136
236
|
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
137
|
-
|
|
237
|
+
// 但在初始化期间不开启动画
|
|
238
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && !isInitializing.current) {
|
|
239
|
+
console.log('[Carousel Debug] 因showIndex变化开启动画');
|
|
138
240
|
setShowTransition(true);
|
|
139
241
|
}
|
|
242
|
+
else if (isInitializing.current) {
|
|
243
|
+
console.log('[Carousel Debug] 初始化期间,跳过showIndex动画开启');
|
|
244
|
+
}
|
|
140
245
|
}, [showIndex]);
|
|
141
246
|
//更新handleNext的环境
|
|
142
247
|
useEffect(function () {
|
|
143
248
|
handleNextRef.current = handleNext;
|
|
144
249
|
});
|
|
145
250
|
var setNextInterval = function () {
|
|
251
|
+
console.log('[Carousel Debug] setNextInterval调用: ' +
|
|
252
|
+
JSON.stringify({
|
|
253
|
+
childrenLength: children.length,
|
|
254
|
+
autoplay: autoplay,
|
|
255
|
+
compWidth: compWidth,
|
|
256
|
+
compHeight: compHeight,
|
|
257
|
+
duration: duration,
|
|
258
|
+
isInitializing: isInitializing.current,
|
|
259
|
+
}));
|
|
146
260
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
147
|
-
|
|
261
|
+
// 只有在初始化完成后才设置自动播放
|
|
262
|
+
if (children.length > 1 && autoplay && !isInitializing.current) {
|
|
263
|
+
console.log('[Carousel Debug] 设置自动播放定时器');
|
|
148
264
|
nextInterval.current = setInterval(function () {
|
|
149
265
|
handleNextRef.current();
|
|
150
266
|
}, duration);
|
|
151
267
|
}
|
|
268
|
+
else {
|
|
269
|
+
console.log('[Carousel Debug] 跳过自动播放设置:', {
|
|
270
|
+
childrenLength: children.length,
|
|
271
|
+
autoplay: autoplay,
|
|
272
|
+
isInitializing: isInitializing.current,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// 当组件开始正常工作时(有子元素且尺寸有效),开启动画
|
|
276
|
+
// 但避免在尺寸刚变为有效时立即开启,给尺寸重置逻辑一些时间
|
|
277
|
+
var shouldEnableTransition = children.length > 0 && compWidth > 0 && compHeight > 0;
|
|
278
|
+
console.log('[Carousel Debug] 动画状态检查: ' +
|
|
279
|
+
JSON.stringify({
|
|
280
|
+
shouldEnableTransition: shouldEnableTransition,
|
|
281
|
+
currentShowTransition: showTransition,
|
|
282
|
+
isInitializing: isInitializing.current,
|
|
283
|
+
}));
|
|
284
|
+
// 只有在初始化完成后且当前没有动画时才开启动画
|
|
285
|
+
if (shouldEnableTransition && showTransition === false && !isInitializing.current) {
|
|
286
|
+
// 延迟开启动画,确保尺寸重置完成
|
|
287
|
+
setTimeout(function () {
|
|
288
|
+
// 再次检查初始化状态,确保在延迟期间没有重新初始化
|
|
289
|
+
if (!isInitializing.current) {
|
|
290
|
+
console.log('[Carousel Debug] 延迟开启动画过渡');
|
|
291
|
+
setShowTransition(true);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
console.log('[Carousel Debug] 延迟期间仍在初始化,跳过动画开启');
|
|
295
|
+
}
|
|
296
|
+
}, 50);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
console.log('[Carousel Debug] 跳过动画开启:', {
|
|
300
|
+
shouldEnableTransition: shouldEnableTransition,
|
|
301
|
+
showTransition: showTransition,
|
|
302
|
+
isInitializing: isInitializing.current,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
152
305
|
};
|
|
153
306
|
useEffect(function () {
|
|
307
|
+
console.log('[Carousel Debug] 组件初始化开始');
|
|
154
308
|
console.log('Carousel init');
|
|
155
|
-
|
|
309
|
+
// 初始化期间不设置自动播放
|
|
310
|
+
// setNextInterval();
|
|
156
311
|
window.addEventListener('close', function () {
|
|
157
312
|
console.log('Carousel close');
|
|
158
313
|
nextInterval.current && clearInterval(nextInterval.current);
|
|
@@ -188,21 +343,39 @@ export function Carousel(props) {
|
|
|
188
343
|
setShowIndex(showIndex + 1);
|
|
189
344
|
};
|
|
190
345
|
var handleTransitionEnd = function () {
|
|
346
|
+
console.log('[Carousel Debug] 动画结束: ' +
|
|
347
|
+
JSON.stringify({
|
|
348
|
+
showIndex: showIndex,
|
|
349
|
+
isLast: isLastCarouseItem(),
|
|
350
|
+
isFirst: isFirstCarouseLastItem(),
|
|
351
|
+
isInitializing: isInitializing.current,
|
|
352
|
+
}));
|
|
191
353
|
//判断前后补位元素准备跳转
|
|
192
354
|
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
193
355
|
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
356
|
+
console.log('[Carousel Debug] 因首尾特殊情况关闭动画');
|
|
194
357
|
setShowTransition(false);
|
|
195
358
|
}
|
|
196
359
|
isMoving.current = false;
|
|
197
360
|
//触发onSlideChange
|
|
198
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange &&
|
|
361
|
+
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange && lastOnSlideChangeIndex.current !== showIndex) {
|
|
362
|
+
console.log('[Carousel Debug] 触发onSlideChange: ' + (showIndex - 1));
|
|
199
363
|
onSlideChange(showIndex - 1);
|
|
200
|
-
|
|
201
|
-
if (isLastCarouseItem()) {
|
|
202
|
-
setShowIndex(1);
|
|
364
|
+
lastOnSlideChangeIndex.current = showIndex;
|
|
203
365
|
}
|
|
204
|
-
|
|
205
|
-
|
|
366
|
+
// 处理首尾特殊case,但在初始化期间跳过
|
|
367
|
+
if (!isInitializing.current) {
|
|
368
|
+
if (isLastCarouseItem()) {
|
|
369
|
+
console.log('[Carousel Debug] 处理末尾case,跳转到索引1');
|
|
370
|
+
setShowIndex(1);
|
|
371
|
+
}
|
|
372
|
+
if (isFirstCarouseLastItem()) {
|
|
373
|
+
console.log('[Carousel Debug] 处理开头case,跳转到索引' + (carouselItems.length - 2));
|
|
374
|
+
setShowIndex(carouselItems.length - 2);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
console.log('[Carousel Debug] 初始化期间,跳过首尾特殊情况处理');
|
|
206
379
|
}
|
|
207
380
|
};
|
|
208
381
|
var gestureUp = function () {
|
|
@@ -304,6 +477,18 @@ export function Carousel(props) {
|
|
|
304
477
|
onClick(showIndex - 1);
|
|
305
478
|
}
|
|
306
479
|
};
|
|
480
|
+
// 渲染时关键样式信息
|
|
481
|
+
var transformValue = isVertical ? "translate(0px, ".concat(offset + gestureoffset[1], "px)") : "translate(".concat(offset + gestureoffset[0], "px, 0px)");
|
|
482
|
+
var transitionValue = "transform ".concat(showTransition ? '0.4s' : '0s', " ease 0s");
|
|
483
|
+
console.log('[Carousel Debug] 渲染样式: ' +
|
|
484
|
+
JSON.stringify({
|
|
485
|
+
transformValue: transformValue,
|
|
486
|
+
transitionValue: transitionValue,
|
|
487
|
+
showTransition: showTransition,
|
|
488
|
+
offset: offset,
|
|
489
|
+
gestureoffset: gestureoffset,
|
|
490
|
+
carouselItemsLength: carouselItems.length,
|
|
491
|
+
}));
|
|
307
492
|
return (h("div", { style: { flexDirection: 'column', width: compWidth, height: compHeight }, id: rootId, className: rootClassName },
|
|
308
493
|
h("div", { draggable: true, style: __assign(__assign({}, itemBoxStyle), { position: 'absolute' }), onClick: function (ev) {
|
|
309
494
|
gestureClick(props);
|
|
@@ -325,10 +510,8 @@ export function Carousel(props) {
|
|
|
325
510
|
display: 'flex',
|
|
326
511
|
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
327
512
|
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
328
|
-
transition:
|
|
329
|
-
transform:
|
|
330
|
-
? "translate(0px, ".concat(offset + gestureoffset[1], "px)")
|
|
331
|
-
: "translate(".concat(offset + gestureoffset[0], "px, 0px)"),
|
|
513
|
+
transition: transitionValue,
|
|
514
|
+
transform: transformValue,
|
|
332
515
|
flexDirection: isVertical ? 'column' : 'row',
|
|
333
516
|
flexShrink: 0,
|
|
334
517
|
}, class: "wrapper", onTransitionEnd: handleTransitionEnd }, carouselItems.map(function (child) { return child; }))))));
|