@tuya-miniapp/smart-ui 2.7.0-beta-5 → 2.7.0-beta-6
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/dist/picker-column/index.wxs +21 -18
- package/lib/picker-column/index.wxs +21 -18
- package/package.json +1 -1
|
@@ -29,7 +29,9 @@ var preStateObj = {}
|
|
|
29
29
|
|
|
30
30
|
function updateState(instanceId, key, value) {
|
|
31
31
|
if (!key) return;
|
|
32
|
-
|
|
32
|
+
if (!state[instanceId]) {
|
|
33
|
+
state[instanceId] = {}
|
|
34
|
+
}
|
|
33
35
|
state[instanceId][key] = value
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -288,12 +290,12 @@ function touchMove(instanceId) {
|
|
|
288
290
|
var direction =
|
|
289
291
|
offsetCompare < 0 ? 'down' : offsetCompare > 0 ? 'up' : state.movingDirection;
|
|
290
292
|
updateVisibleOptions(animationIndex, instanceId);
|
|
291
|
-
var
|
|
293
|
+
var isOverOptionsItem = state.loop ? false : animationIndex < 0 || animationIndex > state.options.length - 1;
|
|
292
294
|
var activeIndex = Math.round(animationIndex);
|
|
293
295
|
var isDisabled = wxUtils.isObj(state.options[activeIndex]) && state.options[activeIndex].disabled;
|
|
294
296
|
if (
|
|
295
297
|
intPreIndex !== intCurIndex
|
|
296
|
-
&& !
|
|
298
|
+
&& !isOverOptionsItem
|
|
297
299
|
&& !isDisabled
|
|
298
300
|
) {
|
|
299
301
|
ownerInstance.callMethod('animationIndexChange', animationIndex);
|
|
@@ -379,10 +381,10 @@ function touchEnd(instanceId) {
|
|
|
379
381
|
currTargetActiveIndex = adjustIndex(Math.round(currTargetActiveIndex), state.options, state.loop);
|
|
380
382
|
targetOffset = -currTargetActiveIndex * state.itemHeight;
|
|
381
383
|
var animationOffset = Math.abs(targetOffset - state.preOffsetting);
|
|
382
|
-
var
|
|
384
|
+
var isOverOptionsLimit = state.loop ? false : state.animationIndex < 0 || state.animationIndex > state.options.length - 1;
|
|
383
385
|
var totalDistance = targetOffset - state.preOffsetting;
|
|
384
386
|
// 如果动画时间大于150ms,并且滚动距离大于itemHeight,则需要进行动态更新列表
|
|
385
|
-
if (state.animationTime > 200 && animationOffset > state.itemHeight && !
|
|
387
|
+
if (state.animationTime > 200 && animationOffset > state.itemHeight && !isOverOptionsLimit) {
|
|
386
388
|
var countOffsetIndex = Math.abs(Math.round(currTargetActiveIndex - state.animationIndex));
|
|
387
389
|
var maxVibrateShort = Math.floor(state.animationTime / 30);
|
|
388
390
|
|
|
@@ -446,6 +448,13 @@ function touchEnd(instanceId) {
|
|
|
446
448
|
}
|
|
447
449
|
}
|
|
448
450
|
|
|
451
|
+
|
|
452
|
+
function updateVisibleOptions(currentIndex, instanceId) {
|
|
453
|
+
var newArr = getVisibleOptions(currentIndex, instanceId);
|
|
454
|
+
updateState(instanceId, 'optionsVIndexList', newArr);
|
|
455
|
+
return newArr
|
|
456
|
+
}
|
|
457
|
+
|
|
449
458
|
var Cache = {}
|
|
450
459
|
|
|
451
460
|
function getVisibleOptions(currentIndex, instanceId) {
|
|
@@ -528,12 +537,6 @@ function getVisibleOptions(currentIndex, instanceId) {
|
|
|
528
537
|
return newArr
|
|
529
538
|
}
|
|
530
539
|
|
|
531
|
-
function updateVisibleOptions(currentIndex, instanceId) {
|
|
532
|
-
var newArr = getVisibleOptions(currentIndex, instanceId);
|
|
533
|
-
updateState(instanceId, 'optionsVIndexList', newArr);
|
|
534
|
-
return newArr
|
|
535
|
-
}
|
|
536
|
-
|
|
537
540
|
function getWrapperCSSVar(instanceId) {
|
|
538
541
|
var state = getCurrState(instanceId);
|
|
539
542
|
var optionsVIndexList = state.optionsVIndexList;
|
|
@@ -541,7 +544,7 @@ function getWrapperCSSVar(instanceId) {
|
|
|
541
544
|
if (currentValue === '' || currentValue === undefined) {
|
|
542
545
|
previousValue['--picker-item-content_' + currentIndex] = '""';
|
|
543
546
|
} else {
|
|
544
|
-
var index =
|
|
547
|
+
var index = currentValue;
|
|
545
548
|
var text = optionText(state.options, index, state.valueKey);
|
|
546
549
|
previousValue['--picker-item-content_' + currentIndex] = '"' + (text === undefined ? '' : text) + '"';
|
|
547
550
|
}
|
|
@@ -583,17 +586,17 @@ function tapItem(instanceId) {
|
|
|
583
586
|
clearTimeout(state.tapTimer);
|
|
584
587
|
updateState(instanceId, 'tapTimer', null);
|
|
585
588
|
}
|
|
586
|
-
var
|
|
587
|
-
var offsetCount = Math.abs(
|
|
588
|
-
updateVisibleOptions(
|
|
589
|
-
updateState(instanceId, 'animationIndex',
|
|
589
|
+
var targetAnimationIndex = getNewAnimationIndex(state.animationIndex, currOptionsActiveIndex, state.options.length || 1, state.loop);
|
|
590
|
+
var offsetCount = Math.abs(targetAnimationIndex - state.animationIndex);
|
|
591
|
+
updateVisibleOptions(targetAnimationIndex, instanceId);
|
|
592
|
+
updateState(instanceId, 'animationIndex', targetAnimationIndex);
|
|
590
593
|
updateWrapperStyle(instanceId, ownerInstance, {
|
|
591
594
|
transition: 'transform ' + 300 + 'ms cubic-bezier(0.2, 0.9, 0.25, 1)'
|
|
592
595
|
});
|
|
593
|
-
ownerInstance.callMethod('animationIndexChange',
|
|
596
|
+
ownerInstance.callMethod('animationIndexChange', targetAnimationIndex);
|
|
594
597
|
ownerInstance.callMethod('vibrateShort', offsetCount, 200);
|
|
595
598
|
var tapTimer = setTimeout(function() {
|
|
596
|
-
ownerInstance.callMethod('activeIndexChange',
|
|
599
|
+
ownerInstance.callMethod('activeIndexChange', targetAnimationIndex);
|
|
597
600
|
updateState(instanceId, 'tapTimer', null);
|
|
598
601
|
setTimeout(function() {
|
|
599
602
|
ownerInstance.callMethod('animationEnd');
|
|
@@ -29,7 +29,9 @@ var preStateObj = {}
|
|
|
29
29
|
|
|
30
30
|
function updateState(instanceId, key, value) {
|
|
31
31
|
if (!key) return;
|
|
32
|
-
|
|
32
|
+
if (!state[instanceId]) {
|
|
33
|
+
state[instanceId] = {}
|
|
34
|
+
}
|
|
33
35
|
state[instanceId][key] = value
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -288,12 +290,12 @@ function touchMove(instanceId) {
|
|
|
288
290
|
var direction =
|
|
289
291
|
offsetCompare < 0 ? 'down' : offsetCompare > 0 ? 'up' : state.movingDirection;
|
|
290
292
|
updateVisibleOptions(animationIndex, instanceId);
|
|
291
|
-
var
|
|
293
|
+
var isOverOptionsItem = state.loop ? false : animationIndex < 0 || animationIndex > state.options.length - 1;
|
|
292
294
|
var activeIndex = Math.round(animationIndex);
|
|
293
295
|
var isDisabled = wxUtils.isObj(state.options[activeIndex]) && state.options[activeIndex].disabled;
|
|
294
296
|
if (
|
|
295
297
|
intPreIndex !== intCurIndex
|
|
296
|
-
&& !
|
|
298
|
+
&& !isOverOptionsItem
|
|
297
299
|
&& !isDisabled
|
|
298
300
|
) {
|
|
299
301
|
ownerInstance.callMethod('animationIndexChange', animationIndex);
|
|
@@ -379,10 +381,10 @@ function touchEnd(instanceId) {
|
|
|
379
381
|
currTargetActiveIndex = adjustIndex(Math.round(currTargetActiveIndex), state.options, state.loop);
|
|
380
382
|
targetOffset = -currTargetActiveIndex * state.itemHeight;
|
|
381
383
|
var animationOffset = Math.abs(targetOffset - state.preOffsetting);
|
|
382
|
-
var
|
|
384
|
+
var isOverOptionsLimit = state.loop ? false : state.animationIndex < 0 || state.animationIndex > state.options.length - 1;
|
|
383
385
|
var totalDistance = targetOffset - state.preOffsetting;
|
|
384
386
|
// 如果动画时间大于150ms,并且滚动距离大于itemHeight,则需要进行动态更新列表
|
|
385
|
-
if (state.animationTime > 200 && animationOffset > state.itemHeight && !
|
|
387
|
+
if (state.animationTime > 200 && animationOffset > state.itemHeight && !isOverOptionsLimit) {
|
|
386
388
|
var countOffsetIndex = Math.abs(Math.round(currTargetActiveIndex - state.animationIndex));
|
|
387
389
|
var maxVibrateShort = Math.floor(state.animationTime / 30);
|
|
388
390
|
|
|
@@ -446,6 +448,13 @@ function touchEnd(instanceId) {
|
|
|
446
448
|
}
|
|
447
449
|
}
|
|
448
450
|
|
|
451
|
+
|
|
452
|
+
function updateVisibleOptions(currentIndex, instanceId) {
|
|
453
|
+
var newArr = getVisibleOptions(currentIndex, instanceId);
|
|
454
|
+
updateState(instanceId, 'optionsVIndexList', newArr);
|
|
455
|
+
return newArr
|
|
456
|
+
}
|
|
457
|
+
|
|
449
458
|
var Cache = {}
|
|
450
459
|
|
|
451
460
|
function getVisibleOptions(currentIndex, instanceId) {
|
|
@@ -528,12 +537,6 @@ function getVisibleOptions(currentIndex, instanceId) {
|
|
|
528
537
|
return newArr
|
|
529
538
|
}
|
|
530
539
|
|
|
531
|
-
function updateVisibleOptions(currentIndex, instanceId) {
|
|
532
|
-
var newArr = getVisibleOptions(currentIndex, instanceId);
|
|
533
|
-
updateState(instanceId, 'optionsVIndexList', newArr);
|
|
534
|
-
return newArr
|
|
535
|
-
}
|
|
536
|
-
|
|
537
540
|
function getWrapperCSSVar(instanceId) {
|
|
538
541
|
var state = getCurrState(instanceId);
|
|
539
542
|
var optionsVIndexList = state.optionsVIndexList;
|
|
@@ -541,7 +544,7 @@ function getWrapperCSSVar(instanceId) {
|
|
|
541
544
|
if (currentValue === '' || currentValue === undefined) {
|
|
542
545
|
previousValue['--picker-item-content_' + currentIndex] = '""';
|
|
543
546
|
} else {
|
|
544
|
-
var index =
|
|
547
|
+
var index = currentValue;
|
|
545
548
|
var text = optionText(state.options, index, state.valueKey);
|
|
546
549
|
previousValue['--picker-item-content_' + currentIndex] = '"' + (text === undefined ? '' : text) + '"';
|
|
547
550
|
}
|
|
@@ -583,17 +586,17 @@ function tapItem(instanceId) {
|
|
|
583
586
|
clearTimeout(state.tapTimer);
|
|
584
587
|
updateState(instanceId, 'tapTimer', null);
|
|
585
588
|
}
|
|
586
|
-
var
|
|
587
|
-
var offsetCount = Math.abs(
|
|
588
|
-
updateVisibleOptions(
|
|
589
|
-
updateState(instanceId, 'animationIndex',
|
|
589
|
+
var targetAnimationIndex = getNewAnimationIndex(state.animationIndex, currOptionsActiveIndex, state.options.length || 1, state.loop);
|
|
590
|
+
var offsetCount = Math.abs(targetAnimationIndex - state.animationIndex);
|
|
591
|
+
updateVisibleOptions(targetAnimationIndex, instanceId);
|
|
592
|
+
updateState(instanceId, 'animationIndex', targetAnimationIndex);
|
|
590
593
|
updateWrapperStyle(instanceId, ownerInstance, {
|
|
591
594
|
transition: 'transform ' + 300 + 'ms cubic-bezier(0.2, 0.9, 0.25, 1)'
|
|
592
595
|
});
|
|
593
|
-
ownerInstance.callMethod('animationIndexChange',
|
|
596
|
+
ownerInstance.callMethod('animationIndexChange', targetAnimationIndex);
|
|
594
597
|
ownerInstance.callMethod('vibrateShort', offsetCount, 200);
|
|
595
598
|
var tapTimer = setTimeout(function() {
|
|
596
|
-
ownerInstance.callMethod('activeIndexChange',
|
|
599
|
+
ownerInstance.callMethod('activeIndexChange', targetAnimationIndex);
|
|
597
600
|
updateState(instanceId, 'tapTimer', null);
|
|
598
601
|
setTimeout(function() {
|
|
599
602
|
ownerInstance.callMethod('animationEnd');
|