@dolphinweex/weex-harmony 0.1.50 → 0.1.51

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dolphinweex/weex-harmony",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "description": "weex harmony adapter",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -301,8 +301,25 @@ export default {
301
301
  this.isUpdatingPosition = true;
302
302
 
303
303
  const easing = 0.6;
304
- const targetX = this.targetTouchX - this.touchOffsetX + window.pageXOffset;
305
- const targetY = this.targetTouchY - this.touchOffsetY + window.pageYOffset;
304
+
305
+ // 获取outer-container的边界
306
+ const containerRect = this.containerElement.getBoundingClientRect();
307
+
308
+ // 计算相对于容器的目标位置
309
+ let targetX = this.targetTouchX - this.touchOffsetX - containerRect.left;
310
+ let targetY = this.targetTouchY - this.touchOffsetY - containerRect.top;
311
+
312
+ // 限制拖拽范围在容器内
313
+ const cloneWidth = this.fixedItemWidth;
314
+ const cloneHeight = this.fixedItemHeight;
315
+ const maxX = containerRect.width - cloneWidth;
316
+ const maxY = containerRect.height - cloneHeight;
317
+
318
+ // 限制X坐标
319
+ targetX = Math.max(0, Math.min(targetX, maxX));
320
+
321
+ // 限制Y坐标
322
+ targetY = Math.max(0, Math.min(targetY, maxY));
306
323
 
307
324
  this.dragCloneX += (targetX - this.dragCloneX) * easing;
308
325
  this.dragCloneY += (targetY - this.dragCloneY) * easing;
@@ -499,32 +516,32 @@ export default {
499
516
  this.dragCloneElement = document.createElement('div');
500
517
  this.dragCloneElement.className = 'drag-clone-dynamic';
501
518
 
502
- // 设置基本样式(使用不带缩放的样式方法)
503
- const itemViewStyle = this.applyOptimizedAttribute(item.itemView, 'itemView', false);
504
- Object.assign(this.dragCloneElement.style, {
505
- position: 'absolute',
506
- zIndex: '9999',
507
- userSelect: 'none',
508
- boxSizing: 'border-box',
509
- flexDirection: 'column',
510
- pointerEvents: 'none',
511
- transition: 'none',
512
- willChange: 'transform',
513
- left: '0',
514
- top: '0',
515
- // 覆盖itemViewStyle中可能的宽高设置,确保使用固定尺寸
516
- ...itemViewStyle,
517
- width: `${this.fixedItemWidth }px`,
518
- height: `${this.fixedItemHeight }px`,
519
- display: 'flex',
520
- justifyContent: 'space-between',
521
- });
522
-
523
- // 创建内容HTML(不使用缩放)
524
- const iconImageStyle = this.applyOptimizedAttribute(item.iconImage, 'iconImage', false);
525
- const selectIconStyle = this.applyOptimizedAttribute(item.selectIcon, 'selectIcon', false);
526
- const textStyle = this.applyOptimizedAttribute(item.text, 'text', false);
527
- const actionButtonStyle = this.applyOptimizedAttribute(item.actionButton, 'actionButton', false);
519
+ // 设置基本样式(使用不带缩放的样式方法)
520
+ const itemViewStyle = this.applyOptimizedAttribute(item.itemView, 'itemView', false);
521
+ Object.assign(this.dragCloneElement.style, {
522
+ position: 'absolute',
523
+ zIndex: '9999',
524
+ userSelect: 'none',
525
+ boxSizing: 'border-box',
526
+ flexDirection: 'column',
527
+ pointerEvents: 'none',
528
+ transition: 'none',
529
+ willChange: 'transform',
530
+ left: '0',
531
+ top: '0',
532
+ // 覆盖itemViewStyle中可能的宽高设置,确保使用固定尺寸
533
+ ...itemViewStyle,
534
+ width: `${this.fixedItemWidth}px`,
535
+ height: `${this.fixedItemHeight}px`,
536
+ display: 'flex',
537
+ justifyContent: 'space-between',
538
+ });
539
+
540
+ // 创建内容HTML(不使用缩放)
541
+ const iconImageStyle = this.applyOptimizedAttribute(item.iconImage, 'iconImage', false);
542
+ const selectIconStyle = this.applyOptimizedAttribute(item.selectIcon, 'selectIcon', false);
543
+ const textStyle = this.applyOptimizedAttribute(item.text, 'text', false);
544
+ const actionButtonStyle = this.applyOptimizedAttribute(item.actionButton, 'actionButton', false);
528
545
 
529
546
  // 将样式对象转换为CSS字符串
530
547
  const stylesToString = (styleObj) => {
@@ -533,35 +550,35 @@ export default {
533
550
  .join('; ');
534
551
  };
535
552
 
536
- // 确保内部grid-box也使用固定尺寸(使用不带缩放的样式方法)
537
- const gridBoxStyle = {
538
- ...this.applyOptimizedAttribute(item.itemView, 'itemView', false),
539
- width: `${this.fixedItemWidth }px`,
540
- height: `${this.fixedItemHeight }px`
541
- };
553
+ // 确保内部grid-box也使用固定尺寸(使用不带缩放的样式方法)
554
+ const gridBoxStyle = {
555
+ ...this.applyOptimizedAttribute(item.itemView, 'itemView', false),
556
+ width: `${this.fixedItemWidth}px`,
557
+ height: `${this.fixedItemHeight}px`
558
+ };
542
559
 
543
- this.dragCloneElement.innerHTML = `
544
- <div class="grid-box" style="${stylesToString(gridBoxStyle)} ;display: flex; justify-content: space-between;flex-direction: column">
545
- <div class="flexBox" style="display: flex; justify-content: space-between; width: 100%; position: relative; flex-direction: row;">
546
- <img src="${this.getUrl(item, 'iconImage')}" style="${stylesToString(iconImageStyle)}" />
547
- <div style="pointer-events: none;">
548
- <img
549
- class="isSelected"
550
- src="${item.itemView.isSelected
551
- ? this.getUrl(item, 'selectIcon', 'selectedUrl')
552
- : this.getUrl(item, 'selectIcon')}"
553
- style="${stylesToString(selectIconStyle)}"
554
- />
555
- </div>
556
- </div>
557
- <div class="itemText" style="${stylesToString(textStyle)}; display: block; width: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
558
- ${this.getText(item, 'text')}
559
- </div>
560
- </div>
561
- `;
562
-
563
- // 挂载到body
564
- document.body.appendChild(this.dragCloneElement);
560
+ this.dragCloneElement.innerHTML = `
561
+ <div class="grid-box" style="${stylesToString(gridBoxStyle)} ;display: flex; justify-content: space-between;flex-direction: column">
562
+ <div class="flexBox" style="display: flex; justify-content: space-between; width: 100%; position: relative; flex-direction: row;">
563
+ <img src="${this.getUrl(item, 'iconImage')}" style="${stylesToString(iconImageStyle)}" />
564
+ <div style="pointer-events: none;">
565
+ <img
566
+ class="isSelected"
567
+ src="${item.itemView.isSelected
568
+ ? this.getUrl(item, 'selectIcon', 'selectedUrl')
569
+ : this.getUrl(item, 'selectIcon')}"
570
+ style="${stylesToString(selectIconStyle)}"
571
+ />
572
+ </div>
573
+ </div>
574
+ <div class="itemText" style="${stylesToString(textStyle)}; display: block; width: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
575
+ ${this.getText(item, 'text')}
576
+ </div>
577
+ </div>
578
+ `;
579
+
580
+ // 挂载到outer-container而不是body,这样可以更好地控制拖拽范围
581
+ this.containerElement.appendChild(this.dragCloneElement);
565
582
 
566
583
  return this.dragCloneElement;
567
584
  },
@@ -947,18 +964,26 @@ export default {
947
964
  // 创建拖拽克隆元素
948
965
  this.createDragClone(index);
949
966
 
950
- // 设置克隆元素的初始位置(直接使用视口坐标加滚动偏移)
951
- this.dragCloneX = rect.left + window.pageXOffset;
952
- this.dragCloneY = rect.top + window.pageYOffset;
967
+ // 计算相对于outer-container的位置
968
+ const containerRect = this.containerElement.getBoundingClientRect();
969
+ this.dragCloneX = rect.left - containerRect.left;
970
+ this.dragCloneY = rect.top - containerRect.top;
953
971
  this.isDragClone = true;
954
972
 
955
973
  // 立即更新位置
956
974
  this.updateDragClonePosition();
957
975
 
958
976
  requestAnimationFrame(() => {
959
- // 使用触摸点减去偏移来计算正确位置
960
- this.dragCloneX = this.touchStartX - this.touchOffsetX + window.pageXOffset;
961
- this.dragCloneY = this.touchStartY - this.touchOffsetY + window.pageYOffset;
977
+ // 使用触摸点减去偏移来计算正确位置,相对于容器
978
+ const targetX = this.touchStartX - this.touchOffsetX - containerRect.left;
979
+ const targetY = this.touchStartY - this.touchOffsetY - containerRect.top;
980
+
981
+ // 限制在容器范围内
982
+ const maxX = containerRect.width - this.fixedItemWidth;
983
+ const maxY = containerRect.height - this.fixedItemHeight;
984
+
985
+ this.dragCloneX = Math.max(0, Math.min(targetX, maxX));
986
+ this.dragCloneY = Math.max(0, Math.min(targetY, maxY));
962
987
  this.updateDragClonePosition();
963
988
  });
964
989
 
@@ -1044,29 +1069,46 @@ export default {
1044
1069
  this.lastTouchX = touchX;
1045
1070
  this.lastTouchY = touchY;
1046
1071
 
1072
+ // 获取容器边界
1073
+ const containerRect = this.containerElement.getBoundingClientRect();
1074
+
1075
+ // 计算用于交换检测的有效触摸点
1076
+ // 如果触摸点在容器外,使用拖拽克隆元素的中心位置
1077
+ let effectiveTouchX = touchX;
1078
+ let effectiveTouchY = touchY;
1079
+
1080
+ if (touchX < containerRect.left || touchX > containerRect.right ||
1081
+ touchY < containerRect.top || touchY > containerRect.bottom) {
1082
+ // 触摸点在容器外,使用拖拽克隆元素的中心位置
1083
+ const cloneCenterX = this.dragCloneX + this.fixedItemWidth / 2;
1084
+ const cloneCenterY = this.dragCloneY + this.fixedItemHeight / 2;
1085
+ effectiveTouchX = containerRect.left + cloneCenterX;
1086
+ effectiveTouchY = containerRect.top + cloneCenterY;
1087
+ }
1088
+
1047
1089
  // 使用缓存的网格元素
1048
1090
  const gridItems = this.getCachedGridItems();
1049
1091
  let targetIndex = null;
1050
1092
 
1051
- // 寻找触摸点所在的目标元素
1093
+ // 寻找有效触摸点所在的目标元素
1052
1094
  for (const item of gridItems) {
1053
1095
  const itemIndex = parseInt(item.getAttribute('data-index'), 10);
1054
1096
  if (itemIndex === this.draggingIndex) continue;
1055
1097
 
1056
1098
  const rect = item.getBoundingClientRect();
1057
1099
 
1058
- // 触摸点是否在元素的中心区域内
1100
+ // 有效触摸点是否在元素的中心区域内
1059
1101
  const centerX = (rect.left + rect.right) / 2;
1060
1102
  const centerY = (rect.top + rect.bottom) / 2;
1061
1103
  const halfWidth = rect.width * 0.3; // 缩小判断区域到30%,减少误触
1062
1104
  const halfHeight = rect.height * 0.3;
1063
1105
 
1064
- // 检查触摸点是否在元素的中心区域内
1106
+ // 检查有效触摸点是否在元素的中心区域内
1065
1107
  if (
1066
- touchX >= centerX - halfWidth &&
1067
- touchX <= centerX + halfWidth &&
1068
- touchY >= centerY - halfHeight &&
1069
- touchY <= centerY + halfHeight
1108
+ effectiveTouchX >= centerX - halfWidth &&
1109
+ effectiveTouchX <= centerX + halfWidth &&
1110
+ effectiveTouchY >= centerY - halfHeight &&
1111
+ effectiveTouchY <= centerY + halfHeight
1070
1112
  ) {
1071
1113
  targetIndex = itemIndex;
1072
1114
  break; // 找到第一个符合条件的就退出
@@ -1355,6 +1397,8 @@ button {
1355
1397
  width: 100%;
1356
1398
  position: relative;
1357
1399
  z-index: 1;
1400
+ /* 确保容器可以作为拖拽克隆元素的定位父元素 */
1401
+ overflow: visible;
1358
1402
  }
1359
1403
 
1360
1404
  .items-container {
@@ -1472,6 +1516,18 @@ button {
1472
1516
  }
1473
1517
 
1474
1518
  /* 拖拽克隆元素样式(现在通过JavaScript动态应用) */
1519
+ .drag-clone-dynamic {
1520
+ position: absolute;
1521
+ z-index: 9999;
1522
+ pointer-events: none;
1523
+ user-select: none;
1524
+ box-sizing: border-box;
1525
+ transform-origin: center center;
1526
+ /* 确保拖拽克隆元素不会超出容器边界 */
1527
+ max-width: 100%;
1528
+ max-height: 100%;
1529
+ overflow: hidden;
1530
+ }
1475
1531
 
1476
1532
  .flexBox {
1477
1533
  display: flex;