@arco-design/mobile-react 2.27.0 → 2.27.2

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 (50) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.en-US.md +2 -2
  3. package/README.md +2 -2
  4. package/cjs/_helpers/index.d.ts +1 -0
  5. package/cjs/_helpers/index.js +10 -0
  6. package/cjs/index-bar/index.js +7 -9
  7. package/cjs/index-bar/type.d.ts +3 -3
  8. package/cjs/load-more/index.js +4 -1
  9. package/cjs/nav-bar/index.js +2 -2
  10. package/cjs/show-monitor/index.js +112 -38
  11. package/cjs/swipe-load/demo/style/css/mobile.css +3 -0
  12. package/cjs/swipe-load/demo/style/mobile.less +11 -0
  13. package/cjs/swipe-load/index.js +86 -32
  14. package/cjs/swipe-load/style/css/index.css +3 -0
  15. package/cjs/swipe-load/style/index.less +7 -0
  16. package/cjs/swipe-load/type.d.ts +29 -0
  17. package/cjs/tabs/index.js +1 -0
  18. package/dist/index.js +393 -838
  19. package/dist/index.min.js +5 -5
  20. package/dist/style.css +3 -0
  21. package/dist/style.min.css +1 -1
  22. package/esm/_helpers/index.d.ts +1 -0
  23. package/esm/_helpers/index.js +7 -0
  24. package/esm/index-bar/index.js +1 -2
  25. package/esm/index-bar/type.d.ts +3 -3
  26. package/esm/load-more/index.js +4 -1
  27. package/esm/nav-bar/index.js +2 -2
  28. package/esm/show-monitor/index.js +112 -38
  29. package/esm/swipe-load/demo/style/css/mobile.css +3 -0
  30. package/esm/swipe-load/demo/style/mobile.less +11 -0
  31. package/esm/swipe-load/index.js +85 -32
  32. package/esm/swipe-load/style/css/index.css +3 -0
  33. package/esm/swipe-load/style/index.less +7 -0
  34. package/esm/swipe-load/type.d.ts +29 -0
  35. package/esm/tabs/index.js +1 -0
  36. package/package.json +3 -3
  37. package/umd/_helpers/index.d.ts +1 -0
  38. package/umd/_helpers/index.js +10 -0
  39. package/umd/index-bar/index.js +10 -10
  40. package/umd/index-bar/type.d.ts +3 -3
  41. package/umd/load-more/index.js +4 -1
  42. package/umd/nav-bar/index.js +2 -2
  43. package/umd/show-monitor/index.js +112 -38
  44. package/umd/swipe-load/demo/style/css/mobile.css +3 -0
  45. package/umd/swipe-load/demo/style/mobile.less +11 -0
  46. package/umd/swipe-load/index.js +88 -36
  47. package/umd/swipe-load/style/css/index.css +3 -0
  48. package/umd/swipe-load/style/index.less +7 -0
  49. package/umd/swipe-load/type.d.ts +29 -0
  50. package/umd/tabs/index.js +1 -0
@@ -10,6 +10,8 @@ var _mobileUtils = require("@arco-design/mobile-utils");
10
10
 
11
11
  var _contextProvider = require("../context-provider");
12
12
 
13
+ var _helpers = require("../_helpers");
14
+
13
15
  var _hooks = require("../_helpers/hooks");
14
16
 
15
17
  var _type = require("./type");
@@ -57,7 +59,22 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
57
59
  _props$activeText = props.activeText,
58
60
  activeText = _props$activeText === void 0 ? '' : _props$activeText,
59
61
  _props$initPos = props.initPos,
60
- initPos = _props$initPos === void 0 ? 0 : _props$initPos;
62
+ initPos = _props$initPos === void 0 ? 0 : _props$initPos,
63
+ _props$bounceWhenBump = props.bounceWhenBumpBoundary,
64
+ bounceWhenBumpBoundary = _props$bounceWhenBump === void 0 ? false : _props$bounceWhenBump,
65
+ _props$bounceDampRate = props.bounceDampRate,
66
+ bounceDampRate = _props$bounceDampRate === void 0 ? 3 : _props$bounceDampRate,
67
+ _props$bounceAnimateD = props.bounceAnimateDuration,
68
+ bounceAnimateDuration = _props$bounceAnimateD === void 0 ? 300 : _props$bounceAnimateD,
69
+ damping = props.damping,
70
+ bounceDistanceProcessor = props.bounceDistanceProcessor,
71
+ getScrollContainer = props.getScrollContainer,
72
+ getBounceContainer = props.getBounceContainer,
73
+ onTouchStart = props.onTouchStart,
74
+ onTouchEnd = props.onTouchEnd,
75
+ onTouchCancel = props.onTouchCancel,
76
+ onTouchMove = props.onTouchMove,
77
+ renderLabel = props.renderLabel;
61
78
 
62
79
  var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
63
80
  _useContext$locale = _useContext.locale,
@@ -76,13 +93,14 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
76
93
  var loadingLabelRef = (0, _react.useRef)(null);
77
94
  var showLoadMoreRef = (0, _react.useRef)(false);
78
95
  var ifToRightRef = (0, _react.useRef)(false);
96
+ var bouncingRef = (0, _react.useRef)(false);
79
97
  var offsetRef = (0, _react.useRef)(0);
80
98
  var domRef = (0, _react.useRef)(null);
81
99
  var wrapperEl = domRef.current;
82
- (0, _hooks.useAddListener)(wrapperEl, 'touchstart', props.onTouchStart);
83
- (0, _hooks.useAddListener)(wrapperEl, 'touchend', props.onTouchEnd);
84
- (0, _hooks.useAddListener)(wrapperEl, 'touchcancel', props.onTouchCancel);
85
- (0, _hooks.useAddListener)(wrapperEl, 'touchmove', props.onTouchMove);
100
+ (0, _hooks.useAddListener)(wrapperEl, 'touchstart', onTouchStart);
101
+ (0, _hooks.useAddListener)(wrapperEl, 'touchend', onTouchEnd);
102
+ (0, _hooks.useAddListener)(wrapperEl, 'touchcancel', onTouchCancel);
103
+ (0, _hooks.useAddListener)(wrapperEl, 'touchmove', onTouchMove);
86
104
  (0, _react.useEffect)(function () {
87
105
  if (disabled || !containerRef.current || disableState) {
88
106
  return;
@@ -96,13 +114,11 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
96
114
  // @en If no child element is passed in, component will be disabled
97
115
  setDisableState(true);
98
116
  } else if (containerRef.current.childNodes.length === 1) {
117
+ var _getScrollContainer;
118
+
99
119
  // 传入一个子元素 滑动单个元素
100
120
  // @en Pass in a child element swipe the single element
101
- if (props.getScrollContainer) {
102
- scrollContainer = props.getScrollContainer();
103
- } else {
104
- scrollContainer = containerRef.current.firstChild;
105
- }
121
+ scrollContainer = (_getScrollContainer = getScrollContainer == null ? void 0 : getScrollContainer()) != null ? _getScrollContainer : containerRef.current.firstChild;
106
122
  } else {
107
123
  // 传入多个子元素(列表元素为例) 组件控制自行滑动 不推荐
108
124
  // @en Pass in multiple sub-elements (list elements as an example) Component control slides by itself which is not recommended
@@ -122,17 +138,20 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
122
138
 
123
139
  if (!loadingCurrent) {
124
140
  return;
125
- } // 初始不显示标签
126
- // @en Initially no labels are displayed
141
+ }
127
142
 
143
+ var bounceScrollContainer = (getBounceContainer == null ? void 0 : getBounceContainer()) || scrollContainer; // 初始不显示标签
144
+ // @en Initially no labels are displayed
128
145
 
129
146
  loadingCurrent.style.display = 'none';
130
147
  var startX = 0;
131
- var endX = 0; // 触摸页面确定X起始坐标
148
+ var endX = 0;
149
+ var bounceDistance = 0; // 触摸页面确定X起始坐标
132
150
  // @en Determine the X starting coordinate on touchstart
133
151
 
134
152
  var touchstart = function touchstart(e) {
135
- startX = e.touches[0].pageX;
153
+ var evt = e.touches[0];
154
+ startX = evt.clientX || 0;
136
155
  }; // 页面滑动确定X终止坐标,更新手指的X坐标,改变loading中的文字和大小
137
156
  // @en Determine the X end coordinate, update the X coordinate of the finger, change the text and size in the loading on touchmove
138
157
 
@@ -144,12 +163,30 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
144
163
  scrollContainer.scrollLeft = 1;
145
164
  }
146
165
 
147
- endX = e.touches[0].pageX;
166
+ endX = e.touches[0].clientX || 0;
148
167
  var diff = endX - startX;
149
168
  offsetRef.current = diff;
150
- var labelDiff = (0, _mobileUtils.fingerDisToLabelDis)(Math.abs(diff), props.damping); // 向左滑动到尽头 '更多'标签加载 根据scrollLeft判断 滚动容器到达边缘触发 非滚动容器不判断
169
+ var labelDiff = (0, _mobileUtils.fingerDisToLabelDis)(Math.abs(diff), damping); // 滑动到最左侧,处理回弹效果
170
+ // @en Swipe to the far left to handle the rebound effect
171
+
172
+ if (diff > 0 && scrollContainer.scrollLeft <= 1 && bounceWhenBumpBoundary) {
173
+ e.stopPropagation();
174
+ e.cancelBubble && e.preventDefault();
175
+ bouncingRef.current = true;
176
+
177
+ var processor = bounceDistanceProcessor || function (dis) {
178
+ return Math.min(dis, bounceScrollContainer.offsetWidth) / bounceDampRate;
179
+ };
180
+
181
+ bounceDistance = processor(diff);
182
+ (0, _helpers.setStyleWithVendor)(bounceScrollContainer, {
183
+ transition: 'none',
184
+ transform: "translateX(" + bounceDistance + "px) translateZ(0)"
185
+ });
186
+ } // 向左滑动到尽头 '更多'标签加载 根据scrollLeft判断 滚动容器到达边缘触发 非滚动容器不判断
151
187
  // @en Swipe left to the end and the 'more' label is loaded. Judging by scrollLeft, the scroll container reaches the edge and the non-scroll container does not judge
152
188
 
189
+
153
190
  if (diff < 0 && (scrollContainer.scrollLeft + scrollContainer.clientWidth >= scrollContainer.scrollWidth - 1 || !scrollContainer.scrollLeft) && !ifToRightRef.current) {
154
191
  showLoadMoreRef.current = true;
155
192
  loadingCurrent.style.display = 'flex';
@@ -175,12 +212,14 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
175
212
  loadingLabelCurrent.innerHTML = labelDiff >= minConfirmOffset ? activeText || locale.SwipeLoad.activeText : normalText || locale.SwipeLoad.normalText;
176
213
  }
177
214
 
178
- loadingCurrent.style.transition = 'all 0.02s';
179
- loadingCurrent.style.webkitTransform = "translateX(-" + labelRightMargin + "px)";
180
- loadingCurrent.style.transform = "translateX(-" + labelRightMargin + "px)";
181
- scrollContainer.style.transition = 'all 0.03s';
182
- scrollContainer.style.webkitTransform = "translateX(-" + listRightMargin + "px)";
183
- scrollContainer.style.transform = "translateX(-" + listRightMargin + "px)";
215
+ (0, _helpers.setStyleWithVendor)(loadingCurrent, {
216
+ transition: 'none',
217
+ transform: "translateX(-" + labelRightMargin + "px) translateZ(0)"
218
+ });
219
+ (0, _helpers.setStyleWithVendor)(scrollContainer, {
220
+ transition: 'none',
221
+ transform: "translateX(-" + listRightMargin + "px) translateZ(0)"
222
+ });
184
223
  }
185
224
 
186
225
  if (diff > 0 && scrollContainer.scrollLeft + scrollContainer.clientWidth <= scrollContainer.scrollWidth - 1) {
@@ -205,13 +244,28 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
205
244
  var labelDiff = (0, _mobileUtils.fingerDisToLabelDis)(Math.abs(diff));
206
245
 
207
246
  var resumeAnimation = function resumeAnimation() {
208
- scrollContainer.style.transition = "all " + labelAnimationDuration + "ms " + labelAnimationFunction;
209
- scrollContainer.style.webkitTransform = 'translateX(0px)';
210
- scrollContainer.style.transform = 'translateX(0px)';
211
- loadingCurrent.style.transition = "all " + labelAnimationDuration + "ms " + labelAnimationFunction;
212
- loadingCurrent.style.webkitTransform = 'translateX(0px)';
213
- loadingCurrent.style.transform = 'translateX(0px)';
214
- showLoadMoreRef.current = false;
247
+ if (showLoadMoreRef.current) {
248
+ showLoadMoreRef.current = false;
249
+ var scrollTransitionCssStyle = "all " + labelAnimationDuration + "ms " + labelAnimationFunction;
250
+ var scrollTransformCssStyle = 'translateX(0px) translateZ(0)';
251
+ (0, _helpers.setStyleWithVendor)(scrollContainer, {
252
+ transition: scrollTransitionCssStyle,
253
+ transform: scrollTransformCssStyle
254
+ });
255
+ (0, _helpers.setStyleWithVendor)(loadingCurrent, {
256
+ transition: scrollTransitionCssStyle,
257
+ transform: scrollTransformCssStyle
258
+ });
259
+ }
260
+
261
+ if (bouncingRef.current) {
262
+ bouncingRef.current = false;
263
+ (0, _helpers.setStyleWithVendor)(bounceScrollContainer, {
264
+ transition: "all " + bounceAnimateDuration + "ms",
265
+ transform: 'translateX(0px) translateZ(0)'
266
+ });
267
+ }
268
+
215
269
  ifToRightRef.current = false;
216
270
  setTimeout(function () {
217
271
  loadingCurrent.style.display = 'none';
@@ -241,7 +295,7 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
241
295
  scrollContainer.removeEventListener('touchmove', touchmove);
242
296
  scrollContainer.removeEventListener('touchend', touchend);
243
297
  };
244
- }, [disabled]);
298
+ }, [disabled, getScrollContainer, getBounceContainer, bounceWhenBumpBoundary, bounceDampRate, bounceAnimateDuration]);
245
299
  (0, _react.useImperativeHandle)(ref, function () {
246
300
  return {
247
301
  dom: domRef.current
@@ -255,14 +309,14 @@ var SwipeLoad = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
255
309
  }, /*#__PURE__*/_react.default.createElement("div", {
256
310
  className: (0, _mobileUtils.cls)(prefixCls + "-list-area"),
257
311
  ref: containerRef
258
- }, children), props.renderLabel ? /*#__PURE__*/_react.default.createElement("div", {
312
+ }, children), renderLabel ? /*#__PURE__*/_react.default.createElement("div", {
259
313
  className: (0, _mobileUtils.cls)(prefixCls + "-custom-loading-area"),
260
314
  ref: loadingRef,
261
315
  style: {
262
316
  position: 'absolute',
263
317
  right: initPos + "px"
264
318
  }
265
- }, props.renderLabel.length ? props.renderLabel(labelOffsetState) : props.renderLabel()) : /*#__PURE__*/_react.default.createElement("div", {
319
+ }, renderLabel.length ? renderLabel(labelOffsetState) : renderLabel()) : /*#__PURE__*/_react.default.createElement("div", {
266
320
  className: (0, _mobileUtils.cls)(prefixCls + "-loading-area"),
267
321
  ref: loadingRef,
268
322
  style: {
@@ -9,6 +9,9 @@
9
9
  position: relative;
10
10
  width: 100%;
11
11
  }
12
+ .arco-swipe-load .arco-list-area::-webkit-scrollbar {
13
+ display: none;
14
+ }
12
15
  .arco-swipe-load .arco-loading-area {
13
16
  background-color: #f8f8f8 ;
14
17
  margin-top: 0;
@@ -4,14 +4,21 @@
4
4
  position: relative;
5
5
  display: inline-flex;
6
6
  width: 100%;
7
+
7
8
  .@{prefix}-list-area {
8
9
  position: relative;
9
10
  width: 100%;
11
+
12
+ &::-webkit-scrollbar {
13
+ display: none;
14
+ }
10
15
  }
16
+
11
17
  .@{prefix}-loading-area {
12
18
  .use-var(background-color, swipe-load-label-background);
13
19
  margin-top: 0;
14
20
  .use-var(border-radius, swipe-load-label-border-radius);
21
+
15
22
  .@{prefix}-loading-label {
16
23
  .use-var(margin-left, swipe-load-label-text-margin-left);
17
24
  .use-var(width, swipe-load-label-text-width);
@@ -77,6 +77,35 @@ export interface SwipeLoadProps {
77
77
  * @default_en "Release to view"
78
78
  */
79
79
  activeText?: string;
80
+ /**
81
+ * 触碰左侧边界时是否需要回弹效果
82
+ * @en Whether a bounce effect is required when touching the left boundary
83
+ * @default false
84
+ */
85
+ bounceWhenBumpBoundary?: boolean;
86
+ /**
87
+ * 当开启回弹效果时的阻尼系数
88
+ * @en Damping coefficient when the rebound effect is turned on
89
+ * @default 3
90
+ */
91
+ bounceDampRate?: number;
92
+ /**
93
+ * 当开启回弹效果时的动画毫秒时间
94
+ * @en Animation in milliseconds when the bounce effect is turned on
95
+ * @default 300
96
+ */
97
+ bounceAnimateDuration?: number;
98
+ /**
99
+ * 回弹效果开启时需要回弹的容器,默认为 getScrollContainer 返回的容器或容器的一个子元素
100
+ * @en The container that needs to be rebounded when the rebound effect is enabled, the default is the container returned by getScrollContainer or a child element of the container
101
+ */
102
+ getBounceContainer?: () => HTMLElement | null;
103
+ /**
104
+ * 当开启回弹效果时自定义手指滑动跟手的距离计算方式,dis表示touchmove的距离
105
+ * @en When the rebound effect is turned on, customize the calculation method of the distance between the finger sliding and the hand, and dis indicates the distance of touchmove
106
+ * @default (dis) => Math.min(dis, bounceScrollContainer.offsetWidth) / bounceDampRate
107
+ */
108
+ bounceDistanceProcessor?: (dis: number) => number;
80
109
  /**
81
110
  * 抛出外层touch事件,便于自定义,常用于阻止划动退出,切换tab等手势冲突
82
111
  * @en Throw the outer touchstart event, which is easy to customize. It is often used to prevent gesture conflicts such as swiping to exit, switching tabs, etc.
package/cjs/tabs/index.js CHANGED
@@ -246,6 +246,7 @@ var Tabs = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
246
246
  // 利用受控手动更改index时,给cell line加上动画
247
247
  // @en Animate the cell line when changeing the index
248
248
  setCellTrans(true);
249
+ changeFromRef.current = 'manual';
249
250
  }, [activeTab]);
250
251
  (0, _helpers.useUpdateEffect)(function () {
251
252
  onDistanceChange && onDistanceChange(distance, wrapWidth, activeIndex);