@dolphinweex/weex-vue-render 0.2.27 → 0.2.28

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.
Files changed (2) hide show
  1. package/dist/index.common.js +195 -110
  2. package/package.json +1 -1
@@ -5930,7 +5930,7 @@ var scrollable$1 = {
5930
5930
  this._loadmoreReset = false;
5931
5931
  var el = this.$el;
5932
5932
  if (el) {
5933
- weex.utils.dispatchNativeEvent(el, 'loadmore');
5933
+ weex.utils.dispatchNativeEvent(el, 'loading');
5934
5934
  }
5935
5935
  }
5936
5936
  }
@@ -7443,7 +7443,6 @@ var slideMixin = {
7443
7443
  this._clones = [];
7444
7444
  this.innerOffset = 0;
7445
7445
  this._indicator = null;
7446
- this.cloneIndex = 0 //需要减或者加去克隆下标
7447
7446
  },
7448
7447
 
7449
7448
  beforeUpdate: function beforeUpdate () {
@@ -7499,7 +7498,7 @@ var slideMixin = {
7499
7498
 
7500
7499
  mounted: function mounted () {
7501
7500
  this._getWrapperSize();
7502
- this._slideTo(this.currentIndex + this.cloneIndex);
7501
+ this._slideTo(this.currentIndex);
7503
7502
  weex.utils.fireLazyload(this.$el, true);
7504
7503
  },
7505
7504
 
@@ -7532,34 +7531,11 @@ var slideMixin = {
7532
7531
  }, [vnode])
7533
7532
  });
7534
7533
 
7535
- if (this.infinite && cells.length > 1) {
7536
- // 克隆第一个和最后一个有效节点
7537
- const cloneFirst = () => {
7538
- const first = cells[0];
7539
- return first ? createElement('li', {
7540
- staticClass: "weex-slider-cell weex-ct clone-cell",
7541
- key: 'clone-first'
7542
- }, [first.children || first.componentOptions.children]) : null
7543
- };
7544
-
7545
- const cloneLast = () => {
7546
- const last = cells[cells.length - 1];
7547
- return last ? createElement('li', {
7548
- staticClass: "weex-slider-cell weex-ct clone-cell",
7549
- key: 'clone-last'
7550
- }, [last.children || last.componentOptions.children]) : null
7551
- };
7552
- const lastClone = cloneLast();
7553
- const firstClone = cloneFirst();
7554
-
7555
- if (firstClone && lastClone) {
7556
- cells = [lastClone].concat(cells).concat([firstClone]);
7557
- }
7558
- }
7534
+
7559
7535
  if (indicatorVnode) {
7560
7536
  indicatorVnode.data.attrs = indicatorVnode.data.attrs || {};
7561
7537
  indicatorVnode.data.attrs.count = cells.length - (this.infinite ? 2 : 0 ); // 显示实际数量
7562
- indicatorVnode.data.attrs.active = this.currentIndex - this.cloneIndex;
7538
+ indicatorVnode.data.attrs.active = this.currentIndex ;
7563
7539
  this._indicator = indicatorVnode;
7564
7540
  }
7565
7541
  return cells
@@ -7568,7 +7544,6 @@ var slideMixin = {
7568
7544
  _renderSlides: function _renderSlides (createElement) {
7569
7545
  this._cells = this._formatChildren(createElement);
7570
7546
  this.frameCount = this._cells.length;
7571
- this.cloneIndex = this.frameCount > 1 ? Boolean(this.infinite) : 0 //需要减或者加去克隆下标
7572
7547
  return createElement(
7573
7548
  'nav',
7574
7549
  {
@@ -7625,12 +7600,20 @@ var slideMixin = {
7625
7600
  if (this.frameCount <= 0) {
7626
7601
  return;
7627
7602
  }
7603
+ //一张图片无需滚动操作
7604
+ if (this.frameCount <= 1) {
7605
+ this.currentIndex = 0;
7606
+ this._preIndex = 0;
7607
+ return;
7608
+ }
7609
+ // 非无限轮播的边界处理
7628
7610
  if (!this.infinite || this.infinite === 'false') {
7629
7611
  if (index === -1 || index > (this.frameCount - 1)) {
7630
7612
  this._slideTo(this.currentIndex);
7631
7613
  return;
7632
7614
  }
7633
7615
  }
7616
+
7634
7617
  if (!this._preIndex && this._preIndex !== 0) {
7635
7618
  this._preIndex = this.currentIndex || 0;
7636
7619
  }
@@ -7640,98 +7623,163 @@ var slideMixin = {
7640
7623
  }
7641
7624
  this._sliding = true;
7642
7625
 
7643
- var newIndex = this._normalizeIndex(index);
7644
7626
  var inner = this.$refs.inner;
7645
7627
  var step = this._step = this.frameCount <= 1 ? 0 : this._preIndex - index;
7646
7628
 
7647
7629
  if (inner) {
7648
7630
  this._prepareNodes();
7649
- var translate = weex.utils.getTransformObj(inner).translate;
7650
- var match = translate && translate.match(/translate[^(]+\(([+-\d.]+)/);
7651
- var innerX = parseFloat(inner.style.left);
7631
+ var innerX = parseFloat(inner.style.left) || 0;
7652
7632
  var dist = innerX - this.innerOffset + step;
7653
- this.innerOffset += step * this._wrapperWidth;
7654
7633
 
7655
- // 克隆处理:先执行正常动画到克隆的最后一张,再瞬间跳回真实的第一张
7656
- if (this.cloneIndex && this.infinite && index >= this.frameCount - 1) {
7657
- // 先滑到克隆的 `第一张`
7658
- newIndex = this.frameCount - 1;
7659
- this.innerOffset = -newIndex * this._wrapperWidth;
7634
+ // 处理无限轮播的边界情况 将目标元素先定位到目的地 动画结束后再回归原位
7635
+ if (this.infinite && this.infinite !== 'false') {
7636
+ if (index < 0) {
7637
+ // 从第一张向左滑
7638
+ var lastIndex = this.frameCount - 1;
7639
+
7640
+ // 先将最后一张放到左侧
7641
+ var lastNode = this._cells[lastIndex].elm;
7642
+ lastNode.style.position = 'absolute';
7643
+ lastNode.style.left = `-${this._wrapperWidth}px`;
7644
+ lastNode.style.opacity = '1';
7645
+ lastNode.style.zIndex = '10';
7646
+ // 执行向左滑动动画
7660
7647
  inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7648
+ this.innerOffset += this._wrapperWidth;
7661
7649
  inner.style.left = `${this.innerOffset}px`;
7662
- newIndex = 1; // 视觉上显示 `第一张`
7663
7650
 
7664
- // 等待动画完成后瞬间跳到 `第一张`
7651
+ // 动画结束后第一张在充值回原先位置
7665
7652
  setTimeout(() => {
7666
7653
  inner.style.transition = 'none';
7667
- this.innerOffset = -this._wrapperWidth; // 瞬间跳到 `第一张`
7654
+ lastNode.style.position = '';
7655
+ lastNode.style.left = '';
7656
+ this.innerOffset = -lastIndex * this._wrapperWidth;
7668
7657
  inner.style.left = `${this.innerOffset}px`;
7658
+
7659
+ setTimeout(() => {
7660
+ inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7661
+ }, 50);
7669
7662
  }, TRANSITION_TIME);
7670
- } else if (this.cloneIndex && this.infinite && index <= 0) {
7671
- // 先滑到克隆的 `最后一张`
7672
- newIndex = 0;
7673
- this.innerOffset = -newIndex * this._wrapperWidth;
7663
+
7664
+ index = lastIndex;
7665
+ } else if (index >= this.frameCount) {
7666
+ // 从最后一张向右滑
7667
+ // 克隆第一张图片并放置在适当位置
7668
+ var firstNode = this._cells[0].elm;
7669
+ var cloneNode = firstNode.cloneNode(true);
7670
+ cloneNode.style.position = 'absolute';
7671
+ cloneNode.style.left = `${this.frameCount * this._wrapperWidth}px`;
7672
+ cloneNode.style.width = `${this._wrapperWidth}px`;
7673
+ cloneNode.style.zIndex = '10';
7674
+ inner.appendChild(cloneNode);
7675
+
7676
+ // 执行向右滑动动画
7674
7677
  inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7678
+ this.innerOffset -= this._wrapperWidth;
7675
7679
  inner.style.left = `${this.innerOffset}px`;
7676
- newIndex = this.frameCount - 2; // 视觉上显示 `最后一张`
7677
7680
 
7678
- // 等待动画完成后瞬间跳到 `最后一张`
7681
+ // 动画结束后重置位置
7679
7682
  setTimeout(() => {
7683
+ // 移除过渡效果
7680
7684
  inner.style.transition = 'none';
7681
- this.innerOffset = -(this.frameCount - 2) * this._wrapperWidth; // 瞬间跳到 `最后一张`
7682
- inner.style.left = `${this.innerOffset}px`;
7685
+
7686
+ // 移除克隆节点
7687
+ if (cloneNode.parentNode) {
7688
+ inner.removeChild(cloneNode);
7689
+ }
7690
+
7691
+ // 重置位置到第一张
7692
+ this.innerOffset = 0;
7693
+ inner.style.left = '0px';
7694
+
7695
+ // 短暂延迟后恢复过渡效果
7696
+ setTimeout(() => {
7697
+ inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7698
+ }, 50);
7683
7699
  }, TRANSITION_TIME);
7684
7700
 
7701
+ index = 0;
7685
7702
  } else {
7686
7703
  // 正常切换
7687
- this.innerOffset = -newIndex * this._wrapperWidth;
7704
+ this.innerOffset = -index * this._wrapperWidth;
7705
+ inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7706
+ inner.style.left = `${this.innerOffset}px`;
7707
+ }
7708
+ } else {
7709
+ // 非无限轮播的正常切换
7710
+ this.innerOffset = -index * this._wrapperWidth;
7688
7711
  inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
7689
7712
  inner.style.left = `${this.innerOffset}px`;
7690
7713
  }
7691
7714
 
7692
- // 触发事件
7715
+ // 触发滚动事件
7693
7716
  if (!isTouchScroll) {
7694
7717
  this._emitScrollEvent('scrollstart');
7695
7718
  }
7696
- setTimeout(function () {
7697
- this$1._throttleEmitScroll(dist, function () {
7719
+
7720
+ setTimeout(() => {
7721
+ this$1._throttleEmitScroll(dist, () => {
7698
7722
  this$1._emitScrollEvent('scrollend');
7699
7723
  });
7700
7724
  }, THROTTLE_SCROLL_TIME);
7701
7725
 
7702
7726
  this._loopShowNodes(step);
7703
7727
 
7704
- setTimeout(function () {
7728
+ setTimeout(() => {
7705
7729
  if (this$1.isNeighbor) {
7706
7730
  this$1._setNeighbors();
7707
7731
  }
7708
7732
 
7709
- setTimeout(function () {
7710
- inner.style.webkitTransition = '';
7711
- inner.style.mozTransition = '';
7733
+ setTimeout(() => {
7712
7734
  inner.style.transition = '';
7713
7735
  for (var i = this$1._showStartIdx; i <= this$1._showEndIdx; i++) {
7714
7736
  var node = this$1._showNodes[i];
7715
- if (!node) {continue;}
7737
+ if (!node) continue;
7716
7738
  var elm = node.firstElementChild;
7717
- if (!elm) {continue;}
7718
- elm.style.webkitTransition = '';
7719
- elm.style.mozTransition = '';
7739
+ if (!elm) continue;
7720
7740
  elm.style.transition = '';
7721
7741
  }
7722
- this$1._rearrangeNodes(newIndex);
7742
+ this$1._rearrangeNodes(index);
7723
7743
  }, NEIGHBOR_SCALE_TIME);
7724
7744
  }, TRANSITION_TIME);
7725
7745
  }
7726
7746
 
7727
- if (newIndex !== this._preIndex) {
7747
+ if (index !== this._preIndex) {
7728
7748
  weex.utils.dispatchNativeEvent(this.$el, 'change', {
7729
- index: newIndex - this.cloneIndex
7749
+ index: index
7730
7750
  });
7731
7751
  }
7752
+
7753
+ this.currentIndex = index;
7754
+ this._preIndex = index;
7755
+ },
7756
+ // 优化_prepareNodes方法以支持无缝切换
7757
+ _prepareNodes: function _prepareNodes() {
7758
+ var step = this._step;
7759
+ if (!this._inited) {
7760
+ this._initNodes();
7761
+ this._inited = true;
7762
+ this._showNodes = {};
7763
+ }
7732
7764
 
7733
- this.currentIndex = newIndex;
7734
- this._preIndex = newIndex;
7765
+ if (this.frameCount <= 1) {
7766
+ this._showStartIdx = this._showEndIdx = 0;
7767
+ var node = this._cells[0].elm;
7768
+ node.style.opacity = 1;
7769
+ node.index = 0;
7770
+ this._showNodes[0] = node;
7771
+ node._inShow = true;
7772
+ node._showIndex = 0;
7773
+ return;
7774
+ }
7775
+
7776
+ // 计算需要显示的节点范围,确保边界切换时有足够的节点
7777
+ var showCount = this._showCount = Math.abs(step) + 3;
7778
+ this._showStartIdx = step <= 0 ? -1 : 2 - showCount;
7779
+ this._showEndIdx = step <= 0 ? showCount - 2 : 1;
7780
+
7781
+ this._clearNodesOffset();
7782
+ this._positionNodes(this._showStartIdx, this._showEndIdx, step);
7735
7783
  },
7736
7784
 
7737
7785
  _clearNodesOffset: function _clearNodesOffset () {
@@ -7769,31 +7817,32 @@ var slideMixin = {
7769
7817
  this._showEndIdx += step;
7770
7818
  },
7771
7819
 
7772
- _prepareNodes: function _prepareNodes () {
7773
- // test if the next slide towards the direction exists.
7774
- // e.g. currentIndex 0 -> 1: should prepare 4 slides: -1, 0, 1, 2
7775
- // if not, translate a node to here, or just clone it.
7820
+ _prepareNodes: function _prepareNodes() {
7776
7821
  var step = this._step;
7777
7822
  if (!this._inited) {
7778
7823
  this._initNodes();
7779
7824
  this._inited = true;
7780
7825
  this._showNodes = {};
7781
7826
  }
7827
+
7828
+ // 单张图片特殊处理
7782
7829
  if (this.frameCount <= 1) {
7783
7830
  this._showStartIdx = this._showEndIdx = 0;
7784
7831
  var node = this._cells[0].elm;
7785
7832
  node.style.opacity = 1;
7786
- // node.style.zIndex = 99;
7787
7833
  node.index = 0;
7788
7834
  this._showNodes[0] = node;
7789
7835
  node._inShow = true;
7790
7836
  node._showIndex = 0;
7791
- return
7837
+ return;
7792
7838
  }
7793
7839
 
7840
+ // 计算需要显示的节点范围
7794
7841
  var showCount = this._showCount = Math.abs(step) + 3;
7795
7842
  this._showStartIdx = step <= 0 ? -1 : 2 - showCount;
7796
7843
  this._showEndIdx = step <= 0 ? showCount - 2 : 1;
7844
+
7845
+ // 清理并更新节点位置
7797
7846
  this._clearNodesOffset();
7798
7847
  this._positionNodes(this._showStartIdx, this._showEndIdx, step);
7799
7848
  },
@@ -8116,7 +8165,43 @@ var slideMixin = {
8116
8165
  if (isV) {
8117
8166
  return
8118
8167
  }
8119
-
8168
+ // 判断是否到达边界,决定是否放行事件
8169
+ const isLeftSwipe = offsetX < 0;
8170
+ const isRightSwipe = offsetX > 0;
8171
+ const atFirst = this._preIndex === 0;
8172
+ const atLast = this._preIndex === this.frameCount - 1;
8173
+ //修改自动轮播或者无缝轮播边界滚动的过渡动画
8174
+ if (this.infinite && this.infinite !== 'false') {
8175
+ var inner = this.$refs.inner;
8176
+ if (inner && ((atFirst && isRightSwipe) || (atLast && isLeftSwipe))) {
8177
+ if (!tp.boundaryHandled) {
8178
+ tp.boundaryHandled = true;
8179
+ if (atFirst && isRightSwipe) {
8180
+ // 从第一张向右滑到最后一张
8181
+ var lastIndex = this.frameCount - 1;
8182
+ var lastNode = this._cells[lastIndex].elm;
8183
+ lastNode.style.position = 'absolute';
8184
+ lastNode.style.left = `-${this._wrapperWidth}px`;
8185
+ lastNode.style.opacity = '1';
8186
+ lastNode.style.zIndex = '10';
8187
+ } else if (atLast && isLeftSwipe) {
8188
+ // 从最后一张向左滑到第一张
8189
+ var firstNode = this._cells[0].elm;
8190
+ var cloneNode = firstNode.cloneNode(true);
8191
+ cloneNode.style.position = 'absolute';
8192
+ cloneNode.style.left = `${this.frameCount * this._wrapperWidth}px`;
8193
+ cloneNode.style.width = `${this._wrapperWidth}px`;
8194
+ cloneNode.style.zIndex = '10';
8195
+ inner.appendChild(cloneNode);
8196
+ tp.cloneNode = cloneNode;
8197
+ }
8198
+ }
8199
+ }
8200
+ }
8201
+ if (!this.infinite && !this.autoPlay && ((atLast && isLeftSwipe) || (atFirst && isRightSwipe))) {
8202
+ // ✅ 如果是边界并继续滑动,就放手,不拦截
8203
+ return;
8204
+ }
8120
8205
  if (this._sliding) {
8121
8206
  event.stopPropagation();
8122
8207
  return
@@ -8134,7 +8219,7 @@ var slideMixin = {
8134
8219
 
8135
8220
  touchSliderInstance = inner;
8136
8221
 
8137
- if (!this.autoPlay) {
8222
+ if (!this.autoPlay && !this.infinite) {
8138
8223
  // 如果不是自动播放,则当滚动到最后一页时,offsetX不能 < 0
8139
8224
  // 如果不是自动播放,则当滚动到第一页时,offsetX不能 > 0
8140
8225
  if (this._preIndex == this.frameCount - 1) {
@@ -10041,49 +10126,49 @@ function detectEvents () {
10041
10126
  detectEvents();
10042
10127
 
10043
10128
  function transitionOnce (vnode, config, callback) {
10044
- var nextFrame = utils$2.nextFrame;
10045
- var toCSSText = utils$2.toCSSText;
10046
- var styleObject2rem = utils$2.styleObject2rem;
10047
- var isArray = utils$2.isArray;
10129
+ var nextFrame = utils$2.nextFrame;
10130
+ var toCSSText = utils$2.toCSSText;
10131
+ var styleObject2rem = utils$2.styleObject2rem;
10132
+ var isArray = utils$2.isArray;
10048
10133
 
10049
- if (isArray(vnode)) {
10050
- vnode = vnode[0];
10051
- }
10134
+ if (isArray(vnode)) {
10135
+ vnode = vnode[0];
10136
+ }
10052
10137
 
10053
- var duration = config.duration || 0; // ms
10054
- var timing = config.timingFunction || 'linear';
10055
- var delay = config.delay || 0; // ms
10138
+ var duration = config.duration || 100; // ms
10139
+ var timing = config.timingFunction || 'linear';
10140
+ var delay = config.delay || 0; // ms
10056
10141
 
10057
- // TODO: parse transition properties
10058
- var transitionValue = "all " + duration + "ms " + timing + " " + delay + "ms";
10142
+ // TODO: parse transition properties
10143
+ var transitionValue = "all " + duration + "ms " + timing + " " + delay + "ms";
10059
10144
 
10060
- var dom = vnode instanceof HTMLElement ? vnode : vnode.$el;
10061
- // trigger image lazyloading by force.
10062
- dom && weex.utils.fireLazyload(dom, true);
10145
+ var dom = vnode instanceof HTMLElement ? vnode : vnode.$el;
10146
+ // trigger image lazyloading by force.
10147
+ dom && weex.utils.fireLazyload(dom, true);
10063
10148
 
10064
- var transitionEndHandler = function (event) {
10065
- event && event.stopPropagation();
10149
+ var transitionEndHandler = function (event) {
10150
+ event && event.stopPropagation();
10151
+ if (endEvent) {
10152
+ dom.removeEventListener(endEvent, transitionEndHandler);
10153
+ dom.style[styleName] = '';
10154
+ }
10155
+ setTimeout(()=>{
10156
+ callback(); //解决嵌套animation的时候 duration过小时会出现瞬间执行完毕的问题
10157
+ })
10158
+ };
10066
10159
  if (endEvent) {
10067
- dom.removeEventListener(endEvent, transitionEndHandler);
10068
- dom.style[styleName] = '';
10069
- }
10070
- setTimeout(()=>{
10071
- callback(); //解决嵌套animation的时候 duration过小时会出现瞬间执行完毕的问题
10072
- })
10073
- };
10074
- if (endEvent) {
10075
- dom.style[styleName] = transitionValue;
10076
- dom.addEventListener(endEvent, transitionEndHandler);
10077
- }
10078
- nextFrame(function () {
10079
- // 修改 transform:translate让它支持传3个参数,且第三个参数无效
10080
- if (config.styles["transform"]) {
10081
- config.styles["transform"] = config.styles["transform"].replace(/(translate\([^,]+,[^,]+),[^)]+\)/, '$1)')
10160
+ dom.style[styleName] = transitionValue;
10161
+ dom.addEventListener(endEvent, transitionEndHandler);
10082
10162
  }
10163
+ nextFrame(function () {
10164
+ // 修改 transform:translate让它支持传3个参数,且第三个参数无效
10165
+ if (config.styles["transform"]) {
10166
+ config.styles["transform"] = config.styles["transform"].replace(/(translate\([^,]+,[^,]+),[^)]+\)/, '$1)')
10167
+ }
10083
10168
 
10084
- dom.style.cssText
10085
- += toCSSText(styleObject2rem(config.styles, DESIGN_ROOT_VALUE) || {});
10086
- });
10169
+ dom.style.cssText
10170
+ += toCSSText(styleObject2rem(config.styles, DESIGN_ROOT_VALUE) || {});
10171
+ });
10087
10172
  }
10088
10173
 
10089
10174
  var animation = {
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.27"
52
+ "version": "0.2.28"
53
53
  }