@dolphinweex/weex-vue-render 0.2.60 → 0.2.62

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.
@@ -1,3 +1,4 @@
1
1
  {
2
- "compile-hero.disable-compile-files-on-did-save-code": true
2
+ "compile-hero.disable-compile-files-on-did-save-code": true,
3
+ "liveServer.settings.port": 5501
3
4
  }
@@ -3485,7 +3485,7 @@ function applySrc (item, src, placeholderSrc) {
3485
3485
  return /%[0-9A-Fa-f]{2}/.test(url);
3486
3486
  }
3487
3487
 
3488
- // 优化:如果是clone节点且原始图片已加载,直接复制背景图片
3488
+ // 如果是clone节点且原始图片已加载,直接复制背景图片
3489
3489
  if (item._isClone && item._originalNode) {
3490
3490
  var originalBg = item._originalNode.style.backgroundImage;
3491
3491
  if (originalBg && originalBg !== 'none') {
@@ -8251,7 +8251,7 @@ var slideMixin = {
8251
8251
  this$1._clones[key] = [];
8252
8252
  });
8253
8253
 
8254
- // 优化:清理预加载的clone节点
8254
+ // 清理预加载的clone节点
8255
8255
  if (this._preloadedClones) {
8256
8256
  Object.keys(this._preloadedClones).forEach(function (key) {
8257
8257
  var clone = this$1._preloadedClones[key];
@@ -8285,7 +8285,7 @@ var slideMixin = {
8285
8285
  // node.style.opacity = 0;
8286
8286
  });
8287
8287
 
8288
- // 优化:延迟预加载clone节点,避免阻塞初始化
8288
+ // 延迟预加载clone节点,避免阻塞初始化
8289
8289
  setTimeout(function() {
8290
8290
  if (this$1.infinite && this$1.frameCount > 1) {
8291
8291
  this$1._preloadClones();
@@ -8347,7 +8347,7 @@ var slideMixin = {
8347
8347
  }
8348
8348
  },
8349
8349
 
8350
- // 优化:获取预加载的clone节点
8350
+ // 获取预加载的clone节点
8351
8351
  _getPreloadedClone: function _getPreloadedClone (index) {
8352
8352
  var key = 'preloaded_' + index;
8353
8353
  var clone = this._preloadedClones && this._preloadedClones[key];
@@ -8361,7 +8361,7 @@ var slideMixin = {
8361
8361
  return null;
8362
8362
  },
8363
8363
 
8364
- // 优化:创建优化的clone节点,预设图片
8364
+ // 创建优化的clone节点,预设图片
8365
8365
  _createOptimizedClone: function _createOptimizedClone (originalNode) {
8366
8366
  var cloneNode = originalNode.cloneNode(true);
8367
8367
  cloneNode._isClone = true;
@@ -8384,7 +8384,7 @@ var slideMixin = {
8384
8384
  return cloneNode;
8385
8385
  },
8386
8386
 
8387
- // 优化:预加载常用的clone节点
8387
+ // 预加载常用的clone节点
8388
8388
  _preloadClones: function _preloadClones () {
8389
8389
  if (!this._preloadedClones) {
8390
8390
  this._preloadedClones = {};
@@ -8608,8 +8608,12 @@ var slideMixin = {
8608
8608
  }
8609
8609
  weex.weexSliderTouchStart = true
8610
8610
 
8611
+ // 重置velocity相关变量
8611
8612
  this.lastMoveTime = Date.now();
8612
8613
  this.lastMovePosition = event.touches[0].pageX;
8614
+ this.velocity = 0;
8615
+ this.transitionDuration = 0.3;
8616
+
8613
8617
  var touch = event.changedTouches[0];
8614
8618
  this._stopAutoPlay();
8615
8619
  var inner = this.$refs.inner;
@@ -8661,18 +8665,32 @@ var slideMixin = {
8661
8665
  tp.offsetY = offsetY;
8662
8666
 
8663
8667
  const now = Date.now();
8664
- const deltaTime = now - this.lastMoveTime;
8665
- const deltaX = Math.abs(event.touches[0].pageX - this.lastMovePosition);
8666
- if (deltaTime > 0) {
8667
- this.velocity = deltaX / deltaTime; // 像素/毫秒
8668
- // 计算动画时间,速度越大动画时间越短
8669
- const baseTime = TRANSITION_TIME / 1200; // 基准时间
8670
- const minTime = 0.1; // 最小动画时间(秒)
8671
- this.transitionDuration = Math.max(minTime, baseTime / (this.velocity + 1));
8672
- }
8673
8668
 
8674
- this.lastMoveTime = now;
8675
- this.lastMovePosition = event.touches[0].pageX;
8669
+ // 初始化velocity相关变量
8670
+ if (!this.lastMoveTime) {
8671
+ this.lastMoveTime = now;
8672
+ this.lastMovePosition = event.touches[0].pageX;
8673
+ this.velocity = 0;
8674
+ this.transitionDuration = 0.3;
8675
+ } else {
8676
+ const deltaTime = now - this.lastMoveTime;
8677
+ const deltaX = Math.abs(event.touches[0].pageX - this.lastMovePosition);
8678
+
8679
+ if (deltaTime > 0 && deltaTime < 100) { // 限制deltaTime范围,避免异常值
8680
+ // 使用滑动平均来平滑velocity计算
8681
+ const currentVelocity = deltaX / deltaTime;
8682
+ this.velocity = this.velocity ? (this.velocity * 0.7 + currentVelocity * 0.3) : currentVelocity;
8683
+
8684
+ // 计算动画时间,速度越大动画时间越短
8685
+ const baseTime = TRANSITION_TIME / 1200; // 基准时间
8686
+ const minTime = 0.15; // 最小动画时间(秒)
8687
+ const maxTime = 0.5; // 最大动画时间(秒)
8688
+ this.transitionDuration = Math.max(minTime, Math.min(maxTime, baseTime / (this.velocity + 0.5)));
8689
+ }
8690
+
8691
+ this.lastMoveTime = now;
8692
+ this.lastMovePosition = event.touches[0].pageX;
8693
+ }
8676
8694
  var isV = tp.isVertical;
8677
8695
  if (typeof isV === 'undefined') {
8678
8696
  isV = tp.isVertical = Math.abs(offsetX) < Math.abs(offsetY);
@@ -8690,10 +8708,12 @@ var slideMixin = {
8690
8708
  const isRightSwipe = offsetX > 0;
8691
8709
  const atFirst = this._preIndex === 0;
8692
8710
  const atLast = this._preIndex === this.frameCount - 1;
8711
+ //修改 非无缝衔接嵌套轮播图的时候 到边界能够触发外层的轮播图滚动
8693
8712
  if (!this.infinite && !this.autoPlay && ((atLast && isLeftSwipe) || (atFirst && isRightSwipe)) && !weex.weexSliderTouchBoundary) {
8694
8713
  weex.weexSliderTouchBoundary = true
8695
- this._parentNav._touchParams = ref
8696
- //如果是边界并继续滑动
8714
+ delete this._touchParams
8715
+ this._parentNav._handleTouchStart(event)
8716
+ this._parentNav._handleTouchMove(event)
8697
8717
  return
8698
8718
  }
8699
8719
 
@@ -8733,13 +8753,13 @@ var slideMixin = {
8733
8753
 
8734
8754
  var inner = this.$refs.inner;
8735
8755
  // 如果已经有一个激活的slider,则不再处理其他slider
8736
- if (touchSliderInstance && touchSliderInstance != inner) {
8737
- event.stopPropagation();
8738
- return;
8739
- }
8756
+ // if (touchSliderInstance && touchSliderInstance != inner) {
8757
+ // event.stopPropagation();
8758
+ // return;
8759
+ // }
8740
8760
 
8741
- // horizontal scroll. trigger scroll event.
8742
- event.stopPropagation()
8761
+ // // horizontal scroll. trigger scroll event.
8762
+ // event.stopPropagation()
8743
8763
 
8744
8764
  touchSliderInstance = inner;
8745
8765
 
@@ -8789,16 +8809,213 @@ var slideMixin = {
8789
8809
  var offsetX = tp.offsetX;
8790
8810
  if (inner) {
8791
8811
  this._nodesOffsetCleared = false;
8792
- // TODO: test the velocity if it's less than 0.2.
8793
- var reset = Math.abs(offsetX / this._wrapperWidth) < 0.2;
8812
+
8813
+ // 计算滑动距离比例和方向
8814
+ var moveRatio = offsetX / this._wrapperWidth;
8815
+ var absMoveRatio = Math.abs(moveRatio);
8794
8816
  var direction = offsetX > 0 ? 1 : -1;
8795
- var newIndex = reset ? this.currentIndex : (this.currentIndex - direction);
8796
- this._slideTo(newIndex, true ,this.transitionDuration);
8817
+
8818
+ // 结合距离和速度
8819
+ var shouldSwitch = false;
8820
+ var animationDuration = this.transitionDuration || 0.3;
8821
+
8822
+ // 如果滑动距离超过30%,或者速度够快(大于0.5像素/毫秒),则切换
8823
+ if (absMoveRatio > 0.3 || (this.velocity && this.velocity > 0.5 && absMoveRatio > 0.15)) {
8824
+ shouldSwitch = true;
8825
+ // 根据速度调整动画时间,速度越快动画越短
8826
+ if (this.velocity && this.velocity > 0.3) {
8827
+ animationDuration = Math.max(0.15, Math.min(0.4, 0.4 / this.velocity));
8828
+ }
8829
+ }
8830
+
8831
+ var newIndex = shouldSwitch ? (this.currentIndex - direction) : this.currentIndex;
8832
+
8833
+ // 边界检查
8834
+ if (!this.infinite || this.infinite === 'false') {
8835
+ if (newIndex < 0) newIndex = 0;
8836
+ if (newIndex >= this.frameCount) newIndex = this.frameCount - 1;
8837
+ }
8838
+
8839
+ // 如果是复位操作(没有切换页面),使用更平滑的动画
8840
+ if (newIndex === this.currentIndex) {
8841
+ this._smoothResetPosition(inner, animationDuration);
8842
+ } else {
8843
+ this._smoothSlideTo(newIndex, animationDuration, moveRatio);
8844
+ }
8797
8845
  }
8798
8846
  delete this._touchParams;
8847
+
8848
+ // 清理velocity相关变量
8849
+ this.lastMoveTime = null;
8850
+ this.lastMovePosition = null;
8851
+ this.velocity = 0;
8852
+
8799
8853
  weex.sliderHorizontalScrolling = false;
8800
8854
  },
8801
8855
 
8856
+ // 平滑复位到当前位置
8857
+ _smoothResetPosition: function _smoothResetPosition(inner, duration) {
8858
+ var targetOffset = this.innerOffset;
8859
+ var currentOffset = this._getPosition(inner);
8860
+
8861
+ if (Math.abs(currentOffset - targetOffset) < 1) {
8862
+ return; // 位置已经很接近,无需动画
8863
+ }
8864
+
8865
+ // 使用ease-out缓动函数进行平滑复位
8866
+ var transitionStyle = this.isTransform ?
8867
+ `transform ${duration}s cubic-bezier(0.25, 0.46, 0.45, 0.94)` :
8868
+ `left ${duration}s cubic-bezier(0.25, 0.46, 0.45, 0.94)`;
8869
+
8870
+ inner.style.transition = transitionStyle;
8871
+ this._setPosition(inner, targetOffset);
8872
+
8873
+ // 清除transition
8874
+ setTimeout(() => {
8875
+ inner.style.transition = '';
8876
+ }, duration * 1000);
8877
+ },
8878
+
8879
+ // 平滑切换到目标页面
8880
+ _smoothSlideTo: function _smoothSlideTo(newIndex, duration, moveRatio) {
8881
+ var this$1 = this;
8882
+
8883
+ if (this.frameCount <= 0) return;
8884
+ if (this.frameCount <= 1) {
8885
+ this.currentIndex = 0;
8886
+ this._preIndex = 0;
8887
+ return;
8888
+ }
8889
+
8890
+ // 边界处理
8891
+ if (!this.infinite || this.infinite === 'false') {
8892
+ if (newIndex < 0 || newIndex >= this.frameCount) {
8893
+ this._smoothResetPosition(this.$refs.inner, duration);
8894
+ return;
8895
+ }
8896
+ }
8897
+
8898
+ if (this._sliding) return;
8899
+ this._sliding = true;
8900
+
8901
+ var inner = this.$refs.inner;
8902
+ if (!inner) return;
8903
+
8904
+ var originalIndex = newIndex;
8905
+ var currentOffset = this._getPosition(inner);
8906
+ var targetOffset;
8907
+ var needsReset = false;
8908
+ var cloneNode = null;
8909
+ var lastNode = null;
8910
+
8911
+ // 使用更自然的缓动函数
8912
+ var easing = Math.abs(moveRatio) > 0.4 ?
8913
+ 'cubic-bezier(0.25, 0.46, 0.45, 0.94)' : // 更快的切换
8914
+ 'cubic-bezier(0.4, 0.0, 0.2, 1)'; // 更柔和的复位
8915
+
8916
+ var transitionStyle = this.isTransform ?
8917
+ `transform ${duration}s ${easing}` :
8918
+ `left ${duration}s ${easing}`;
8919
+
8920
+ // 处理无限轮播的边界情况
8921
+ if (this.infinite && this.infinite !== 'false') {
8922
+ if (newIndex < 0) {
8923
+ // 从第一张向右滑到最后一张
8924
+ newIndex = this.frameCount - 1;
8925
+ lastNode = this._cells[newIndex].elm;
8926
+ lastNode.style.position = 'absolute';
8927
+ this._setPosition(lastNode, -this._wrapperWidth);
8928
+ lastNode.style.opacity = '1';
8929
+ lastNode.style.zIndex = '10';
8930
+
8931
+ // 目标是向右滑动到左侧的最后一张图片
8932
+ targetOffset = this.innerOffset + this._wrapperWidth;
8933
+ needsReset = true;
8934
+ } else if (newIndex >= this.frameCount) {
8935
+ // 从最后一张向左滑到第一张
8936
+ newIndex = 0;
8937
+ var firstNode = this._cells[0].elm;
8938
+ cloneNode = this._getPreloadedClone(0) || this._createOptimizedClone(firstNode);
8939
+ cloneNode.style.position = 'absolute';
8940
+ this._setPosition(cloneNode, this.frameCount * this._wrapperWidth);
8941
+ cloneNode.style.width = `${this._wrapperWidth}px`;
8942
+ cloneNode.style.zIndex = '10';
8943
+ if (!cloneNode.parentNode) {
8944
+ inner.appendChild(cloneNode);
8945
+ }
8946
+
8947
+ // 目标是向左滑动到右侧的克隆图片
8948
+ targetOffset = this.innerOffset - this._wrapperWidth;
8949
+ needsReset = true;
8950
+ } else {
8951
+ // 正常切换
8952
+ targetOffset = -newIndex * this._wrapperWidth;
8953
+ }
8954
+ } else {
8955
+ // 非无限轮播的正常切换
8956
+ targetOffset = -newIndex * this._wrapperWidth;
8957
+ }
8958
+
8959
+ // 执行动画
8960
+ inner.style.transition = transitionStyle;
8961
+ this._setPosition(inner, targetOffset);
8962
+
8963
+ // 触发滚动事件
8964
+ this._emitScrollEvent('scrollstart');
8965
+ // 添加持续的滚动事件触发
8966
+ var step = this._step = this.frameCount <= 1 ? 0 : this._preIndex - newIndex;
8967
+
8968
+ var dist = currentOffset - this.innerOffset + step;
8969
+ setTimeout(() => {
8970
+ this$1._throttleEmitScroll(dist, () => {
8971
+ this$1._emitScrollEvent('scrollend');
8972
+ });
8973
+ }, THROTTLE_SCROLL_TIME);
8974
+ // 动画完成后的处理
8975
+ setTimeout(() => {
8976
+ inner.style.transition = 'none';
8977
+
8978
+ if (needsReset) {
8979
+ // 无缝轮播需要重置位置
8980
+ if (lastNode) {
8981
+ // 重置最后一张图片位置
8982
+ lastNode.style.position = '';
8983
+ lastNode.style.zIndex = '';
8984
+ this$1._setPosition(lastNode, 0);
8985
+ }
8986
+
8987
+ if (cloneNode && cloneNode.parentNode) {
8988
+ // 移除克隆节点
8989
+ inner.removeChild(cloneNode);
8990
+ }
8991
+
8992
+ // 重置到正确的最终位置
8993
+ this$1.innerOffset = -newIndex * this$1._wrapperWidth;
8994
+ this$1._setPosition(inner, this$1.innerOffset);
8995
+
8996
+ // 短暂延迟后恢复transition
8997
+ setTimeout(() => {
8998
+ inner.style.transition = '';
8999
+ }, 50);
9000
+ } else {
9001
+ this$1.innerOffset = targetOffset;
9002
+ }
9003
+
9004
+ this$1._sliding = false;
9005
+
9006
+ // 触发change事件 - 在设置currentIndex之前比较
9007
+ if (newIndex !== this$1._preIndex) {
9008
+ weex.utils.dispatchNativeEvent(this$1.$el, 'change', {
9009
+ index: newIndex
9010
+ });
9011
+ }
9012
+
9013
+ this$1.currentIndex = newIndex;
9014
+ this$1._preIndex = newIndex;
9015
+ this$1._emitScrollEvent('scrollend');
9016
+ }, duration * 800);
9017
+ },
9018
+
8802
9019
  _handleTouchCancel: function _handleTouchCancel (event) {
8803
9020
  var inner = this.$refs.inner;
8804
9021
  if (touchSliderInstance == inner) {
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "type": "git",
50
50
  "url": "git+ssh://git@github.com/weexteam/weex-vue-render.git"
51
51
  },
52
- "version": "0.2.60"
52
+ "version": "0.2.62"
53
53
  }