@shijiu/jsview-vue 0.9.302 → 0.9.311-alpha.0

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.
@@ -2,7 +2,7 @@
2
2
  * @Author: ChenChanghua
3
3
  * @Date: 2021-09-22 16:08:58
4
4
  * @LastEditors: ChenChanghua
5
- * @LastEditTime: 2021-12-28 16:08:15
5
+ * @LastEditTime: 2022-01-13 12:14:00
6
6
  * @Description: file content
7
7
  -->
8
8
 
@@ -35,6 +35,8 @@
35
35
  width: item的宽,
36
36
  height: item的高,
37
37
  focusable: item是否可以获得焦点,
38
+ marginBottom: item的下方margin,
39
+ marginRight: item的右方margin,
38
40
  }
39
41
  *
40
42
  * onClick {function} item点击回调
@@ -109,6 +111,7 @@ const _getPadding = function (padding) {
109
111
  }
110
112
  return result;
111
113
  };
114
+
112
115
  const _AddTemplateItem = function (
113
116
  data,
114
117
  measure_func,
@@ -121,6 +124,7 @@ const _AddTemplateItem = function (
121
124
  }
122
125
  template_parser.CalculateNeighborWhenAddStop();
123
126
  };
127
+
124
128
  const _getTemplateParser = function (width, height, direction, p) {
125
129
  let padding = _getPadding(p);
126
130
  let line_max =
@@ -130,6 +134,27 @@ const _getTemplateParser = function (width, height, direction, p) {
130
134
  return new TemplateParser(direction, line_max, "relative", width, height);
131
135
  };
132
136
 
137
+ // direction key 是 vertical 的值
138
+ const directionFreeKeyMap = {
139
+ pos: {
140
+ true: "yPos",
141
+ false: "xPos",
142
+ },
143
+ size: {
144
+ true: "height",
145
+ false: "width",
146
+ },
147
+ neighbor: {
148
+ true: {
149
+ 1: "bottom",
150
+ "-1": "top",
151
+ },
152
+ false: {
153
+ 1: "bottom",
154
+ "-1": "top",
155
+ },
156
+ },
157
+ };
133
158
  const SimpleWidget = {
134
159
  components: { RootView },
135
160
  props: {
@@ -259,8 +284,10 @@ const SimpleWidget = {
259
284
 
260
285
  visibleStart: 0,
261
286
  visibleRange: 0,
262
- visibleItemList: [],
263
- needHideItemList: [],
287
+
288
+ visibleItemIndexList: [],
289
+ needHideItemIndexList: [],
290
+
264
291
  visibleRangeSearchBaseItem: 0,
265
292
 
266
293
  touchContainerW: 0,
@@ -280,7 +307,7 @@ const SimpleWidget = {
280
307
  let visibleStart = 0;
281
308
  const targetItem = this.templateParser.GetItem(focusId);
282
309
  const pos_key = this.direction === VERTICAL ? "yPos" : "xPos";
283
- const width_key = this.direction === VERTICAL ? "height" : "width";
310
+ const size_key = this.direction === VERTICAL ? "height" : "width";
284
311
  if (this.slideStyle === SlideStyle.wholePage) {
285
312
  const visibleRange =
286
313
  this.direction === VERTICAL
@@ -303,17 +330,17 @@ const SimpleWidget = {
303
330
  let last_item = template_list[template_list.length - 1];
304
331
  let last_item_off_set =
305
332
  last_item[pos_key] +
306
- last_item[width_key] -
333
+ last_item[size_key] -
307
334
  visibleRange +
308
335
  padding[padding_key];
309
336
  for (let i = 0; i <= focusId; i++) {
310
337
  const curItem = this.templateParser.GetItem(i);
311
338
  if (
312
- curItem[pos_key] + curItem[width_key] >
339
+ curItem[pos_key] + curItem[size_key] >
313
340
  visibleStart + (visibleRange * 4) / 5
314
341
  ) {
315
342
  visibleStart =
316
- curItem[pos_key] + curItem[width_key] - (visibleRange * 4) / 5;
343
+ curItem[pos_key] + curItem[size_key] - (visibleRange * 4) / 5;
317
344
  }
318
345
  }
319
346
  visibleStart =
@@ -338,8 +365,8 @@ const SimpleWidget = {
338
365
  return this.focusId;
339
366
  },
340
367
 
341
- _registerItemFunc(id, handlerObj) {
342
- this.innerData.data[id].itemHandler = handlerObj;
368
+ _registerItemFunc(index, handlerObj) {
369
+ this.innerData.data[index].itemHandler = handlerObj;
343
370
  },
344
371
 
345
372
  _queryPosition(id) {
@@ -396,16 +423,22 @@ const SimpleWidget = {
396
423
  }
397
424
  },
398
425
 
399
- _getVisibleItemList(id, start, end) {
426
+ _getVisibleItemIndexList(id, start, end) {
427
+ // 扩展可视范围,避免快速滚动时闪烁
400
428
  let s = start - 100 > 0 ? start - 100 : 0;
401
429
  let e = end + 100;
402
430
  let visible_info = this.templateParser.GetVisibleItemList(s, e, id);
403
- return this.templateParser
404
- .GetTemplate()
405
- .List.slice(visible_info.visibleStart, visible_info.visibleEnd + 1);
431
+ let start_index = visible_info.visibleStart;
432
+ let end_index = visible_info.visibleEnd;
433
+
434
+ let index_list = new Array(end_index - start_index + 1);
435
+ for (let i = start_index; i <= end_index; i++) {
436
+ index_list[i - start_index] = i;
437
+ }
438
+ return index_list;
406
439
  },
407
440
 
408
- _calculateNearestItemByRect(template_item_list, enter_rect_info) {
441
+ _calculateNearestItemByRect(visible_item_index_list, enter_rect_info) {
409
442
  let edge_direction = enter_rect_info.direction;
410
443
  let rect = enter_rect_info.rect;
411
444
  var direction = "";
@@ -446,7 +479,9 @@ const SimpleWidget = {
446
479
 
447
480
  let key_pos = this.direction === VERTICAL ? "yPos" : "xPos";
448
481
  let key_width = this.direction === VERTICAL ? "height" : "width";
449
- for (let item of template_item_list) {
482
+ for (let index of visible_item_index_list) {
483
+ let item = this.templateParser.GetItem(index);
484
+ if (!item.focusable) continue;
450
485
  let full_show =
451
486
  item[key_pos] >= this.visibleStart &&
452
487
  item[key_pos] + item[key_width] - 1 <=
@@ -589,12 +624,9 @@ const SimpleWidget = {
589
624
  }
590
625
  },
591
626
 
592
- _updateItemVisibility(item_list, visibility) {
593
- let template = this.templateParser.GetTemplate();
594
- for (let i = 0; i < item_list.length; ++i) {
595
- this.innerData.data[
596
- template.IdsMap[item_list[i].id]
597
- ].controller.visible = visibility;
627
+ _updateItemVisibility(item_index_list, visibility) {
628
+ for (let index of item_index_list) {
629
+ this.innerData.data[index].controller.visible = visibility;
598
630
  }
599
631
  },
600
632
 
@@ -633,102 +665,77 @@ const SimpleWidget = {
633
665
  },
634
666
 
635
667
  _updateVisibleList(baseItemId, cur_visible_start, cur_visible_end) {
636
- let pre_visible_list = this.visibleItemList;
637
- this.visibleItemList = this._getVisibleItemList(
668
+ let pre_visible_list = this.visibleItemIndexList;
669
+ this.visibleItemIndexList = this._getVisibleItemIndexList(
638
670
  baseItemId,
639
671
  cur_visible_start,
640
672
  cur_visible_end
641
673
  );
642
- for (let item of pre_visible_list) {
674
+ for (let index of pre_visible_list) {
643
675
  if (
644
- this.visibleItemList.indexOf(item) < 0 &&
645
- this.needHideItemList.indexOf(item) < 0
676
+ this.visibleItemIndexList.indexOf(index) < 0 &&
677
+ this.needHideItemIndexList.indexOf(index) < 0
646
678
  ) {
647
- this.needHideItemList.push(item);
679
+ this.needHideItemIndexList.push(index);
648
680
  }
649
681
  }
650
- for (let item of this.visibleItemList) {
651
- let index = this.needHideItemList.indexOf(item);
652
- if (index >= 0) {
653
- this.needHideItemList.splice(index, 1);
682
+ for (let index of this.visibleItemIndexList) {
683
+ let i = this.needHideItemIndexList.indexOf(index);
684
+ if (i >= 0) {
685
+ this.needHideItemIndexList.splice(i, 1);
654
686
  }
655
687
  }
656
688
 
657
689
  this.visibleStart = cur_visible_start;
658
690
  //可见的item设置visibility
659
- this._updateItemVisibility(this.visibleItemList, true);
691
+ this._updateItemVisibility(this.visibleItemIndexList, true);
660
692
  },
661
693
 
662
694
  _moveToNext(horizontal_direction, vertical_direction, item_edge_rect) {
663
- let template = this.templateParser.GetTemplate();
664
- let focus_index = template.IdsMap[this.focusId];
665
- let next_item = this.templateParser.GetNextItem(
695
+ let cur_focus_item = this.templateParser.GetItemById(this.focusId);
696
+ let next_item_id = this.templateParser.GetNextItem(
666
697
  this.focusId,
667
698
  vertical_direction,
668
699
  horizontal_direction,
669
700
  this.loopFocus
670
701
  );
671
- if (next_item >= 0) {
702
+ if (next_item_id >= 0) {
672
703
  this.preFocusId = this.focusId;
673
- let focus_item = this.templateParser.GetItem(next_item);
674
- this.focusId = focus_item.id;
704
+ let next_focus_item = this.templateParser.GetItemById(next_item_id);
705
+ this.focusId = next_focus_item.id;
675
706
  let direction =
676
707
  this.direction === VERTICAL
677
708
  ? vertical_direction
678
709
  : horizontal_direction;
679
710
  let pre_visible_start = this.visibleStart;
680
711
  let cur_visible_start = this.slideFunction
681
- ? this.slideFunction(focus_item, direction, this.visibleStart)
682
- : this._CalculateSlide(focus_item, direction, this.visibleStart);
683
- cur_visible_start = this._adjustToValidPosition(cur_visible_start);
712
+ ? this.slideFunction(next_focus_item, direction, this.visibleStart)
713
+ : this._calculateSlide(next_focus_item, direction, this.visibleStart);
714
+ // cur_visible_start = this._adjustToValidPosition(cur_visible_start);
684
715
  if (pre_visible_start !== cur_visible_start) {
685
- let pre_visible_list = this.visibleItemList;
686
- this.visibleItemList = this._getVisibleItemList(
687
- next_item,
688
- cur_visible_start,
689
- cur_visible_start + this.visibleRange - 1
690
- );
691
-
692
- for (let item of pre_visible_list) {
693
- if (
694
- this.visibleItemList.indexOf(item) < 0 &&
695
- this.needHideItemList.indexOf(item) < 0
696
- ) {
697
- this.needHideItemList.push(item);
698
- }
699
- }
700
- for (let item of this.visibleItemList) {
701
- let index = this.needHideItemList.indexOf(item);
702
- if (index >= 0) {
703
- this.needHideItemList.splice(index, 1);
704
- }
705
- }
706
-
707
716
  this.visibleStart = cur_visible_start;
708
717
  let animObj = {
709
718
  easing: "",
710
719
  onstart: null,
711
720
  speed: this.slideSpeed,
712
- onend: this._onTransitionEnd,
721
+ onend: this._onSlideEnd,
713
722
  };
714
723
  if (this.direction === HORIZONTAL) {
715
724
  this.rootElement.updatePosition(-this.visibleStart, 0, animObj);
716
725
  } else {
717
726
  this.rootElement.updatePosition(0, -this.visibleStart, animObj);
718
727
  }
719
- this.visibleRangeSearchBaseItem = next_item;
728
+ this.visibleRangeSearchBaseItem = next_item_id;
720
729
  this._updateVisibleList(
721
- next_item,
730
+ next_item_id,
722
731
  cur_visible_start,
723
732
  cur_visible_start + this.visibleRange - 1
724
733
  );
725
734
  }
726
735
 
727
736
  let rect;
728
- let x_off_set =
729
- template.List[focus_index].xPos - template.List[next_item].xPos;
730
- let y_off_set =
731
- template.List[focus_index].yPos - template.List[next_item].yPos;
737
+ let x_off_set = cur_focus_item.xPos - next_focus_item.xPos;
738
+ let y_off_set = cur_focus_item.yPos - next_focus_item.yPos;
732
739
  if (item_edge_rect) {
733
740
  item_edge_rect.rect.x += x_off_set;
734
741
  item_edge_rect.rect.y += y_off_set;
@@ -739,8 +746,8 @@ const SimpleWidget = {
739
746
  rect: {
740
747
  x: x_off_set,
741
748
  y: y_off_set,
742
- width: template.List[focus_index].width,
743
- height: template.List[focus_index].height,
749
+ width: cur_focus_item.width,
750
+ height: cur_focus_item.height,
744
751
  },
745
752
  };
746
753
  }
@@ -748,61 +755,68 @@ const SimpleWidget = {
748
755
  this._updateBlurItem();
749
756
  this._updateFocusItem();
750
757
  if (this.isFocus) {
751
- this.innerData.data[this.preFocusId].itemHandler.onBlur();
758
+ this.innerData.data[
759
+ this.templateParser.FocusIdToIndex(this.preFocusId)
760
+ ].itemHandler.onBlur();
752
761
  }
753
762
 
754
763
  if (this.isFocus) {
755
- this.innerData.data[this.focusId].itemHandler.onFocus(
756
- this.preEdgeRect
757
- );
764
+ this.innerData.data[
765
+ this.templateParser.FocusIdToIndex(this.focusId)
766
+ ].itemHandler.onFocus(this.preEdgeRect);
758
767
  }
759
768
  } else {
760
769
  let x_off_set = this.direction === VERTICAL ? 0 : this.visibleStart;
761
- let y_off_set = this.direction === VERTICAL ? this.visibleStart : 0;
762
- let edge;
763
- if (horizontal_direction === 1) {
764
- edge = EdgeDirection.right;
765
- }
766
- if (horizontal_direction === -1) {
767
- edge = EdgeDirection.left;
768
- }
769
- if (vertical_direction === 1) {
770
- edge = EdgeDirection.bottom;
771
- }
772
- if (vertical_direction === -1) {
773
- edge = EdgeDirection.top;
774
- }
775
- let rect = {
776
- x: template.List[focus_index].xPos - x_off_set,
777
- y: template.List[focus_index].yPos - y_off_set,
778
- width: template.List[focus_index].width,
779
- height: template.List[focus_index].height,
780
- };
770
+ let y_off_set = this.direction === VERTICAL ? this.visibleStart : 0;
771
+ let edge;
772
+ if (horizontal_direction === 1) {
773
+ edge = EdgeDirection.right;
774
+ }
775
+ if (horizontal_direction === -1) {
776
+ edge = EdgeDirection.left;
777
+ }
778
+ if (vertical_direction === 1) {
779
+ edge = EdgeDirection.bottom;
780
+ }
781
+ if (vertical_direction === -1) {
782
+ edge = EdgeDirection.top;
783
+ }
784
+ let rect = {
785
+ x: cur_focus_item.xPos - x_off_set,
786
+ y: cur_focus_item.yPos - y_off_set,
787
+ width: cur_focus_item.width,
788
+ height: cur_focus_item.height,
789
+ };
781
790
  if (this.onEdge) {
782
791
  this.onEdge({ direction: edge, rect: rect });
783
792
  }
784
- this.innerData.data[this.focusId].itemHandler.reachEdge({ direction: edge })
793
+ this.innerData.data[
794
+ this.templateParser.FocusIdToIndex(this.focusId)
795
+ ].itemHandler.reachEdge({
796
+ direction: edge,
797
+ });
785
798
  }
786
799
  },
787
800
 
788
- _adjustToValidPosition(visible_start) {
801
+ _adjustToValidPosition(visible_start, adjust_end) {
789
802
  //TODO 优化
790
- let template_list = this.templateParser.GetTemplate().List;
791
- let last_item = template_list[template_list.length - 1];
792
- let pos_key = this.direction === VERTICAL ? "yPos" : "xPos";
793
- let width_key = this.direction === VERTICAL ? "height" : "width";
803
+ let last_item = this.templateParser.GetItem(-1);
804
+ let pos_key = directionFreeKeyMap.pos[this.direction === VERTICAL];
805
+ let size_key = directionFreeKeyMap.size[this.direction === VERTICAL];
794
806
  let padding = _getPadding(this.padding);
795
- let padding_offset = this.direction === VERTICAL ? padding["bottom"] + padding["top"] : padding["right"] + padding["left"];
807
+
808
+ let padding_offset =
809
+ this.direction === VERTICAL
810
+ ? padding["bottom"] + padding["top"]
811
+ : padding["right"] + padding["left"];
796
812
  let visible_range =
797
- this.direction === VERTICAL ? this.height : this.width;
813
+ (this.direction === VERTICAL ? this.height : this.width) -
814
+ padding_offset;
798
815
 
799
- let last_position = last_item[pos_key] + last_item[width_key];
800
- let last_item_off_set =
801
- last_position -
802
- visible_range
803
- + padding_offset;
816
+ let last_position = last_item[pos_key] + last_item[size_key];
817
+ let last_item_off_set = last_position - visible_range;
804
818
  last_item_off_set = last_item_off_set < 0 ? 0 : last_item_off_set;
805
- if (visible_start > last_item_off_set) {
819
+ if (adjust_end && visible_start > last_item_off_set) {
806
820
  return last_item_off_set;
807
821
  } else if (visible_start < 0) {
808
822
  return 0;
@@ -811,62 +825,72 @@ const SimpleWidget = {
811
825
  }
812
826
  },
813
827
 
814
- _CalculateSlide(target_item, direction, visible_start) {
828
+ _calculateSlide(target_item, direction, visible_start) {
815
829
  let pre_visible_start = visible_start;
816
830
  let cur_visible_start = pre_visible_start;
817
- // let template_list = this.templateParser.GetTemplate().List;
818
- // let last_item = template_list[template_list.length - 1];
819
- let pos_key = this.direction === VERTICAL ? "yPos" : "xPos";
820
- let width_key = this.direction === VERTICAL ? "height" : "width";
821
- // let padding_key = this.direction === VERTICAL ? "bottom" : "right";
831
+ let pos_key = directionFreeKeyMap.pos[this.direction === VERTICAL];
832
+ let size_key = directionFreeKeyMap.size[this.direction === VERTICAL];
833
+ let neighbor_keys =
834
+ directionFreeKeyMap.neighbor[this.direction === VERTICAL];
822
835
  let visible_range =
823
836
  this.direction === VERTICAL ? this.height : this.width;
824
- // let last_item_off_set;
837
+
825
838
  switch (this.slideStyle) {
826
839
  case SlideStyle.seamLess:
827
- // last_item_off_set =
828
- // last_item[pos_key] +
829
- // last_item[width_key] -
830
- // visible_range +
831
- // _getPadding(this.padding)[padding_key];
832
840
  if (direction > 0) {
833
841
  if (
834
- target_item[pos_key] + target_item[width_key] >
842
+ target_item[pos_key] + target_item[size_key] >
835
843
  pre_visible_start + (visible_range * 4) / 5
836
844
  ) {
837
845
  cur_visible_start =
838
846
  target_item[pos_key] +
839
- target_item[width_key] -
847
+ target_item[size_key] -
840
848
  (visible_range * 4) / 5;
849
+
850
+ let target_neighbors =
851
+ target_item.neighborIndexList[neighbor_keys[direction]];
852
+ if (
853
+ target_neighbors &&
854
+ !this.templateParser.GetItem(-1).focusable &&
855
+ target_neighbors.indexOf(this.templateParser.GetLength() - 1) >=
856
+ 0
857
+ ) {
858
+ cur_visible_start += this.templateParser.GetItem(-1)[size_key];
859
+ }
841
860
  }
842
861
  } else if (direction < 0) {
843
862
  if (target_item[pos_key] < pre_visible_start + visible_range / 5) {
844
863
  cur_visible_start = target_item[pos_key] - visible_range / 5;
864
+ let target_neighbors =
865
+ target_item.neighborIndexList[neighbor_keys[direction]];
866
+ if (
867
+ target_neighbors &&
868
+ !this.templateParser.GetItem(0).focusable &&
869
+ target_neighbors.indexOf(0) >= 0
870
+ ) {
871
+ cur_visible_start -= this.templateParser.GetItem(0)[size_key];
872
+ }
845
873
  }
846
874
  } else {
847
875
  //不是沿widget方向的移动
848
876
  if (target_item[pos_key] < pre_visible_start) {
849
877
  cur_visible_start = target_item[pos_key] - visible_range / 5;
850
878
  } else if (
851
- target_item[pos_key] + target_item[width_key] >
879
+ target_item[pos_key] + target_item[size_key] >
852
880
  pre_visible_start + visible_range
853
881
  ) {
854
882
  cur_visible_start =
855
883
  target_item[pos_key] +
856
- target_item[width_key] -
884
+ target_item[size_key] -
857
885
  (visible_range * 4) / 5;
858
886
  }
859
887
  }
860
- // cur_visible_start =
861
- // cur_visible_start > last_item_off_set
862
- // ? last_item_off_set
863
- // : cur_visible_start;
864
- // cur_visible_start = cur_visible_start < 0 ? 0 : cur_visible_start;
888
+ cur_visible_start = this._adjustToValidPosition(cur_visible_start, true);
865
889
  break;
866
890
  case SlideStyle.wholePage:
867
891
  if (direction > 0) {
868
892
  if (
869
- target_item[pos_key] + target_item[width_key] >
893
+ target_item[pos_key] + target_item[size_key] >
870
894
  pre_visible_start + visible_range + 1
871
895
  ) {
872
896
  cur_visible_start = target_item[pos_key];
@@ -874,10 +898,10 @@ const SimpleWidget = {
874
898
  } else if (direction < 0) {
875
899
  if (target_item[pos_key] < pre_visible_start) {
876
900
  cur_visible_start =
877
- target_item[pos_key] + target_item[width_key] - visible_range;
878
- // cur_visible_start = cur_visible_start < 0 ? 0 : cur_visible_start;
901
+ target_item[pos_key] + target_item[size_key] - visible_range;
879
902
  }
880
903
  }
904
+ cur_visible_start = this._adjustToValidPosition(cur_visible_start, false);
881
905
  break;
882
906
  case SlideStyle.seamlessFixedId:
883
907
  break;
@@ -926,7 +950,7 @@ const SimpleWidget = {
926
950
  : this.focusId;
927
951
  focus_id = this._ifValidEnterRect(this.enterFocusRect)
928
952
  ? this._calculateNearestItemByRect(
929
- this.visibleItemList,
953
+ this.visibleItemIndexList,
930
954
  this.enterFocusRect
931
955
  )
932
956
  : focus_id;
@@ -938,7 +962,9 @@ const SimpleWidget = {
938
962
 
939
963
  if (this.isFocus) {
940
964
  Promise.resolve().then(() => {
941
- this.innerData.data[focus_id].itemHandler.onFocus(this.preEdgeRect);
965
+ this.innerData.data[
966
+ this.templateParser.FocusIdToIndex(this.focusId)
967
+ ].itemHandler.onFocus(this.preEdgeRect);
942
968
  });
943
969
  }
944
970
 
@@ -955,41 +981,41 @@ const SimpleWidget = {
955
981
  this.preFocusId = this.focusId;
956
982
  this.preEdgeRect = null;
957
983
  this._updateBlurItem();
958
- this.innerData.data[this.preFocusId].itemHandler.onBlur();
984
+ this.innerData.data[
985
+ this.templateParser.FocusIdToIndex(this.preFocusId)
986
+ ].itemHandler.onBlur();
959
987
 
960
988
  if (this.onBlur) {
961
989
  this.onBlur();
962
990
  }
963
991
  },
964
992
 
965
- _onTransitionEnd(event) {
993
+ _applyHideItemIndexList() {
994
+ this._updateItemVisibility(this.needHideItemIndexList, false);
995
+ this.needHideItemIndexList = [];
996
+ },
997
+
998
+ _onSlideEnd(event) {
966
999
  if (event && event.stopPropagation) {
967
1000
  event.stopPropagation();
968
1001
  }
969
- this._updateItemVisibility(this.needHideItemList, false);
970
- this.needHideItemList = [];
1002
+ this._applyHideItemIndexList();
971
1003
  },
972
1004
 
973
1005
  _onContentUpdate() {
974
- this._updateItemVisibility(this.visibleItemList, true);
1006
+ this._updateItemVisibility(this.visibleItemIndexList, true);
975
1007
  this._updateFocusItem();
976
1008
  },
977
1009
 
978
1010
  _updateFocusItem() {
979
- let focus_item = this.templateParser.GetItem(this.focusId);
980
- if (focus_item) {
981
- this._setZIndex(
982
- this.templateParser.GetTemplate().IdsMap[this.focusId],
983
- this.data.length
984
- );
985
- }
1011
+ this._setZIndex(
1012
+ this.templateParser.FocusIdToIndex(this.focusId),
1013
+ this.data.length
1014
+ );
986
1015
  },
987
1016
 
988
1017
  _updateBlurItem() {
989
- this._setZIndex(
990
- this.templateParser.GetTemplate().IdsMap[this.preFocusId],
991
- 0
992
- );
1018
+ this._setZIndex(this.templateParser.FocusIdToIndex(this.preFocusId), 0);
993
1019
  },
994
1020
 
995
1021
  _onFocusUpdate() {},
@@ -1073,14 +1099,13 @@ const SimpleWidget = {
1073
1099
  anchor_info.doAnim;
1074
1100
 
1075
1101
  if (!do_anim) {
1076
- this._updateItemVisibility(this.needHideItemList, false);
1077
- this.needHideItemList = [];
1102
+ this._applyHideItemIndexList();
1078
1103
  } else if (this.rootElement) {
1079
1104
  let animObj = {
1080
1105
  easing: "",
1081
1106
  onstart: null,
1082
1107
  speed: this.slideSpeed,
1083
- onend: this._onTransitionEnd,
1108
+ onend: this._onSlideEnd,
1084
1109
  };
1085
1110
  if (this.direction === HORIZONTAL) {
1086
1111
  this.rootElement.updatePosition(-this.visibleStart, 0, animObj);
@@ -1115,7 +1140,7 @@ const SimpleWidget = {
1115
1140
  };
1116
1141
  }
1117
1142
  this.focusId = this._calculateNearestItemByRect(
1118
- this.visibleItemList,
1143
+ this.visibleItemIndexList,
1119
1144
  enterFocusRect
1120
1145
  );
1121
1146
  },
@@ -1169,18 +1194,14 @@ const SimpleWidget = {
1169
1194
  // console.log("SimpleWidget Container OnDragEnd:", msg);
1170
1195
  this._tryReoprtVisibleEvent(msg);
1171
1196
  this._updateFocusByDragInfo(msg["viewX"], msg["viewY"]);
1172
- if (this.needHideItemList.length > 0) {
1173
- this._onTransitionEnd();
1174
- }
1197
+ this._onSlideEnd();
1175
1198
  return true;
1176
1199
  },
1177
1200
  OnFling: (msg) => {
1178
1201
  // console.log("SimpleWidget Container OnFling:", msg);
1179
1202
  this._tryReoprtVisibleEvent(msg);
1180
1203
  this._updateFocusByDragInfo(msg["viewX"], msg["viewY"]);
1181
- if (this.needHideItemList.length > 0) {
1182
- this._onTransitionEnd();
1183
- }
1204
+ this._onSlideEnd();
1184
1205
  return true;
1185
1206
  },
1186
1207
  OnRelease: () => {
@@ -1197,6 +1218,12 @@ const SimpleWidget = {
1197
1218
  onKeyDown: this.onKeyDown,
1198
1219
  };
1199
1220
  },
1221
+ // randomColor() {
1222
+ // let randomColor = Math.round(Math.random() * 2 ** 24).toString(16);
1223
+ // return (
1224
+ // "#" + new Array(6 - randomColor.length).fill("0").join("") + randomColor
1225
+ // );
1226
+ // },
1200
1227
  },
1201
1228
  created() {
1202
1229
  if (this.dispatcher) {
@@ -1233,9 +1260,10 @@ const SimpleWidget = {
1233
1260
  this.direction === VERTICAL
1234
1261
  ? Forge.DragSetting.DIRECTION_VERTICAL
1235
1262
  : Forge.DragSetting.DIRECTION_HORIZONTAL;
1236
- this.innerData.data = template_list.map((item) => {
1263
+ this.innerData.data = template_list.map((item, index) => {
1237
1264
  return {
1238
1265
  data: item,
1266
+ index: index,
1239
1267
  controller: {
1240
1268
  visible: ref(false),
1241
1269
  zIndex: ref(0),
@@ -1248,34 +1276,28 @@ const SimpleWidget = {
1248
1276
  };
1249
1277
  });
1250
1278
 
1279
+ let visible_base_index = 0;
1251
1280
  let init_focus_id = 0;
1252
1281
  let cur_visible_start = 0;
1253
1282
  let visible_range = this.direction === VERTICAL ? this.height : this.width;
1254
- this.visibleItemList = this._getVisibleItemList(
1255
- init_focus_id,
1256
- cur_visible_start,
1257
- cur_visible_start + visible_range - 1
1258
- );
1259
- if (typeof this.baseAnchor !== "undefined") {
1260
- let pos = this._BaseAnchorInfo2Pos(this.baseAnchor, 0, visible_range);
1261
- cur_visible_start = this.direction === VERTICAL ? pos.yPos : pos.xPos;
1262
- this.visibleItemList = this._getVisibleItemList(
1263
- this.baseAnchor.id,
1264
- cur_visible_start,
1265
- cur_visible_start + visible_range - 1
1266
- );
1267
- }
1268
1283
  if (this.initFocusId) {
1269
1284
  init_focus_id = this.initFocusId;
1285
+ visible_base_index = this.templateParser.FocusIdToIndex(init_focus_id);
1270
1286
  if (typeof this.baseAnchor === "undefined") {
1271
1287
  cur_visible_start = this._initVisibleStart(init_focus_id);
1272
- this.visibleItemList = this._getVisibleItemList(
1273
- init_focus_id,
1274
- cur_visible_start,
1275
- cur_visible_start + visible_range - 1
1276
- );
1277
1288
  }
1278
1289
  }
1290
+ if (typeof this.baseAnchor !== "undefined") {
1291
+ let pos = this._BaseAnchorInfo2Pos(this.baseAnchor, 0, visible_range);
1292
+ cur_visible_start = this.direction === VERTICAL ? pos.yPos : pos.xPos;
1293
+ visible_base_index = this.baseAnchor.index;
1294
+ }
1295
+
1296
+ this.visibleItemIndexList = this._getVisibleItemIndexList(
1297
+ visible_base_index,
1298
+ cur_visible_start,
1299
+ cur_visible_start + visible_range - 1
1300
+ );
1279
1301
  this.focusId = init_focus_id;
1280
1302
  this.visibleStart = cur_visible_start;
1281
1303
  this.visibleRange = visible_range;
@@ -1314,7 +1336,7 @@ const SimpleWidget = {
1314
1336
  if (
1315
1337
  this.baseAnchor &&
1316
1338
  !(
1317
- this.baseAnchor.id === this.perAnchor.id &&
1339
+ this.baseAnchor.index === this.perAnchor.id &&
1318
1340
  this.baseAnchor.type === this.perAnchor.type
1319
1341
  )
1320
1342
  ) {
@@ -1360,6 +1382,7 @@ const SimpleWidget = {
1360
1382
  this.innerData.data = template_list.map((item, index) => {
1361
1383
  return {
1362
1384
  data: item,
1385
+ index: index,
1363
1386
  controller: {
1364
1387
  visible: ref(false),
1365
1388
  zIndex: ref(0),
@@ -1381,7 +1404,7 @@ const SimpleWidget = {
1381
1404
  }
1382
1405
  }
1383
1406
  //重新获取可视itemlist
1384
- this.visibleItemList = this._getVisibleItemList(
1407
+ this.visibleItemIndexList = this._getVisibleItemIndexList(
1385
1408
  this.visibleRangeSearchBaseItem,
1386
1409
  this.visibleStart,
1387
1410
  this.visibleStart + this.visibleRange - 1
@@ -1389,7 +1412,9 @@ const SimpleWidget = {
1389
1412
  if (this.isFocus) {
1390
1413
  this._updateFocusItem();
1391
1414
  Promise.resolve().then(() => {
1392
- this.innerData.data[this.focusId].itemHandler.onFocus(null);
1415
+ this.innerData.data[
1416
+ this.templateParser.FocusIdToIndex(this.focusId)
1417
+ ].itemHandler.onFocus(null);
1393
1418
  });
1394
1419
  }
1395
1420
  },