@arco-design/mobile-react 2.28.0 → 2.28.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.
@@ -13,6 +13,12 @@ export declare function useListenResize(resizeHandler: () => void, deps?: any[],
13
13
  * @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
14
14
  * @param initialState 初始状态
15
15
  * @param initialState {en} Initial State
16
+ * @example
17
+ * ```
18
+ * import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
19
+ *
20
+ * const [scrollValue, setScrollValue] = useMountedState(value);
21
+ * ```
16
22
  */
17
23
  export declare function useMountedState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>];
18
24
  export declare function useSameRefState<T>(initialValue: T): [T, React.MutableRefObject<T>, (data: T) => void];
@@ -37,7 +43,7 @@ export declare function useAddListener(dom: HTMLDivElement | null, event: string
37
43
  capture: boolean;
38
44
  }): void;
39
45
  export declare function usePreventBodyScroll(visible: boolean, preventBodyScroll: boolean, initialBodyOverflow?: string): void;
40
- export declare const useProgress: (mountedTransition: boolean, percentage: number, duration: number, mountedBezier: BezierType, step: number) => [number, boolean];
46
+ export declare function useProgress(mountedTransition: boolean, percentage: number, duration: number, mountedBezier: BezierType, step: number): [number, boolean];
41
47
  export declare function useSingleAndDoubleClick(onClick: (e: React.MouseEvent) => void, onDoubleClick: (e: React.MouseEvent) => void, delay?: number): (e: React.MouseEvent) => void;
42
48
  export declare function useGenSvgKey(userSetSvgKey: string): {
43
49
  svgKey: string;
@@ -35,6 +35,12 @@ export function useListenResize(resizeHandler, deps, needListen) {
35
35
  * @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
36
36
  * @param initialState 初始状态
37
37
  * @param initialState {en} Initial State
38
+ * @example
39
+ * ```
40
+ * import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
41
+ *
42
+ * const [scrollValue, setScrollValue] = useMountedState(value);
43
+ * ```
38
44
  */
39
45
 
40
46
  export function useMountedState(initialState) {
@@ -449,7 +455,7 @@ export function usePreventBodyScroll(visible, preventBodyScroll, initialBodyOver
449
455
  };
450
456
  }, [visible]);
451
457
  }
452
- export var useProgress = function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
458
+ export function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
453
459
  var _useState8 = useState(0),
454
460
  currentPercentage = _useState8[0],
455
461
  setCurrentPercentage = _useState8[1];
@@ -483,7 +489,7 @@ export var useProgress = function useProgress(mountedTransition, percentage, dur
483
489
  percentage === 100 ? setCurrentPercentage(100) : setCurrentPercentage(count * step);
484
490
  }, [count, percentage, step]);
485
491
  return [currentPercentage, transitionControl];
486
- };
492
+ }
487
493
  export function useSingleAndDoubleClick(onClick, onDoubleClick, delay) {
488
494
  if (delay === void 0) {
489
495
  delay = 200;
@@ -18,7 +18,7 @@ export interface AvatarProps<T extends ImageProps = ImageProps> extends BaseProp
18
18
  * 图片头像的资源地址
19
19
  * @en resource of avatar picture
20
20
  */
21
- src: string;
21
+ src?: string;
22
22
  /**
23
23
  * 图片头像组件参数,透传给Image组件
24
24
  * @en Image avatar component props, transparently passed to the Image component
@@ -24,15 +24,96 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
24
24
  _this._errors = [];
25
25
  _this._touched = false;
26
26
 
27
+ _this.onValueChange = function (preStore, curStore) {
28
+ _this._touched = true;
29
+ var shouldUpdate = _this.props.shouldUpdate;
30
+
31
+ if (typeof shouldUpdate === 'function') {
32
+ shouldUpdate({
33
+ preStore: preStore,
34
+ curStore: curStore
35
+ }) && _this.forceUpdate();
36
+ return;
37
+ }
38
+
39
+ _this.forceUpdate();
40
+ };
41
+
42
+ _this.getFieldError = function () {
43
+ return _this._errors;
44
+ };
45
+
46
+ _this.isFieldTouched = function () {
47
+ return _this._touched;
48
+ };
49
+
50
+ _this.validateField = function () {
51
+ var validateMessages = _this.context.validateMessages;
52
+ var getFieldValue = _this.context.form.getFieldValue;
53
+ var _this$props = _this.props,
54
+ field = _this$props.field,
55
+ rules = _this$props.rules,
56
+ onValidateStatusChange = _this$props.onValidateStatusChange;
57
+ var value = getFieldValue(field);
58
+
59
+ if (rules != null && rules.length && field) {
60
+ var _Validator;
61
+
62
+ var fieldDom = _this.props.getFormItemRef();
63
+
64
+ var fieldValidator = new Validator((_Validator = {}, _Validator[field] = rules, _Validator), {
65
+ validateMessages: validateMessages
66
+ });
67
+ return new Promise(function (resolve) {
68
+ var _fieldValidator$valid;
69
+
70
+ fieldValidator.validate((_fieldValidator$valid = {}, _fieldValidator$valid[field] = value, _fieldValidator$valid), function (errorsMap) {
71
+ var _getErrorAndWarnings = getErrorAndWarnings((errorsMap == null ? void 0 : errorsMap[field]) || []),
72
+ errors = _getErrorAndWarnings.errors,
73
+ warnings = _getErrorAndWarnings.warnings;
74
+
75
+ _this._errors = errors;
76
+ onValidateStatusChange({
77
+ errors: _this._errors,
78
+ warnings: warnings
79
+ });
80
+ return resolve({
81
+ errors: _this._errors,
82
+ warnings: warnings,
83
+ value: value,
84
+ field: field,
85
+ dom: fieldDom
86
+ });
87
+ });
88
+ });
89
+ }
90
+
91
+ return Promise.resolve({
92
+ errors: [],
93
+ warnings: [],
94
+ value: value,
95
+ field: field,
96
+ dom: null
97
+ });
98
+ };
99
+
100
+ _this.setFieldData = function (value) {
101
+ var field = _this.props.field;
102
+ var setFieldValue = _this.context.form.setFieldValue;
103
+ setFieldValue(field, value);
104
+
105
+ _this.validateField();
106
+ };
107
+
27
108
  _this.innerTriggerFunction = function (_, value) {
28
109
  var _children$props;
29
110
 
30
111
  _this.setFieldData(value);
31
112
 
32
- var _this$props = _this.props,
33
- children = _this$props.children,
34
- _this$props$trigger = _this$props.trigger,
35
- trigger = _this$props$trigger === void 0 ? 'onChange' : _this$props$trigger;
113
+ var _this$props2 = _this.props,
114
+ children = _this$props2.children,
115
+ _this$props2$trigger = _this$props2.trigger,
116
+ trigger = _this$props2$trigger === void 0 ? 'onChange' : _this$props2$trigger;
36
117
 
37
118
  if (trigger && (_children$props = children.props) != null && _children$props[trigger]) {
38
119
  var _children$props2;
@@ -50,10 +131,10 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
50
131
 
51
132
  _this.setFieldData(value);
52
133
 
53
- var _this$props2 = _this.props,
54
- children = _this$props2.children,
55
- _this$props2$trigger = _this$props2.trigger,
56
- trigger = _this$props2$trigger === void 0 ? 'onChange' : _this$props2$trigger;
134
+ var _this$props3 = _this.props,
135
+ children = _this$props3.children,
136
+ _this$props3$trigger = _this$props3.trigger,
137
+ trigger = _this$props3$trigger === void 0 ? 'onChange' : _this$props3$trigger;
57
138
 
58
139
  if (trigger && (_children$props3 = children.props) != null && _children$props3[trigger]) {
59
140
  var _children$props4;
@@ -66,6 +147,24 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
66
147
  }
67
148
  };
68
149
 
150
+ _this.innerClearFunction = function () {
151
+ var _children$props5;
152
+
153
+ var children = _this.props.children;
154
+
155
+ _this.setFieldData('');
156
+
157
+ if ((_children$props5 = children.props) != null && _children$props5.onClear) {
158
+ var _children$props6;
159
+
160
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
161
+ args[_key3] = arguments[_key3];
162
+ }
163
+
164
+ (_children$props6 = children.props) == null ? void 0 : _children$props6.onClear.apply(_children$props6, args);
165
+ }
166
+ };
167
+
69
168
  _this.destroyField = function () {};
70
169
 
71
170
  if (props != null && props.initialValue && props.field) {
@@ -93,108 +192,10 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
93
192
  this.destroyField();
94
193
  };
95
194
 
96
- _proto.onValueChange = function onValueChange(preStore, curStore) {
97
- this._touched = true;
98
- var shouldUpdate = this.props.shouldUpdate;
99
-
100
- if (typeof shouldUpdate === 'function') {
101
- shouldUpdate({
102
- preStore: preStore,
103
- curStore: curStore
104
- }) && this.forceUpdate();
105
- return;
106
- }
107
-
108
- this.forceUpdate();
109
- };
110
-
111
- _proto.getFieldError = function getFieldError() {
112
- return this._errors;
113
- };
114
-
115
- _proto.isFieldTouched = function isFieldTouched() {
116
- return this._touched;
117
- };
118
-
119
- _proto.validateField = function validateField() {
120
- var _this2 = this;
121
-
122
- var validateMessages = this.context.validateMessages;
123
- var getFieldValue = this.context.form.getFieldValue;
124
- var _this$props3 = this.props,
125
- field = _this$props3.field,
126
- rules = _this$props3.rules,
127
- onValidateStatusChange = _this$props3.onValidateStatusChange;
128
- var value = getFieldValue(field);
129
-
130
- if (rules != null && rules.length && field) {
131
- var _Validator;
132
-
133
- var fieldDom = this.props.getFormItemRef();
134
- var fieldValidator = new Validator((_Validator = {}, _Validator[field] = rules, _Validator), {
135
- validateMessages: validateMessages
136
- });
137
- return new Promise(function (resolve) {
138
- var _fieldValidator$valid;
139
-
140
- fieldValidator.validate((_fieldValidator$valid = {}, _fieldValidator$valid[field] = value, _fieldValidator$valid), function (errorsMap) {
141
- var _getErrorAndWarnings = getErrorAndWarnings((errorsMap == null ? void 0 : errorsMap[field]) || []),
142
- errors = _getErrorAndWarnings.errors,
143
- warnings = _getErrorAndWarnings.warnings;
144
-
145
- _this2._errors = errors;
146
- onValidateStatusChange({
147
- errors: _this2._errors,
148
- warnings: warnings
149
- });
150
- return resolve({
151
- errors: _this2._errors,
152
- warnings: warnings,
153
- value: value,
154
- field: field,
155
- dom: fieldDom
156
- });
157
- });
158
- });
159
- }
160
-
161
- return Promise.resolve({
162
- errors: [],
163
- warnings: [],
164
- value: value,
165
- field: field,
166
- dom: null
167
- });
168
- };
169
-
170
- _proto.setFieldData = function setFieldData(value) {
171
- var field = this.props.field;
172
- var setFieldValue = this.context.form.setFieldValue;
173
- setFieldValue(field, value);
174
- this.validateField();
175
- };
176
-
177
- _proto.innerClearFunction = function innerClearFunction() {
178
- var _children$props5;
179
-
180
- var children = this.props.children;
181
- this.setFieldData('');
182
-
183
- if ((_children$props5 = children.props) != null && _children$props5.onClear) {
184
- var _children$props6;
185
-
186
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
187
- args[_key3] = arguments[_key3];
188
- }
189
-
190
- (_children$props6 = children.props) == null ? void 0 : _children$props6.onClear.apply(_children$props6, args);
191
- }
192
- };
193
-
194
195
  _proto.renderChildren = function renderChildren() {
195
196
  var _props,
196
197
  _children$type,
197
- _this3 = this;
198
+ _this2 = this;
198
199
 
199
200
  var _this$props4 = this.props,
200
201
  children = _this$props4.children,
@@ -269,7 +270,7 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
269
270
  props.error = this._errors;
270
271
 
271
272
  props[trigger] = function (newValue) {
272
- _this3.setFieldData(newValue);
273
+ _this2.setFieldData(newValue);
273
274
 
274
275
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
275
276
  args[_key4 - 1] = arguments[_key4];
@@ -32,13 +32,13 @@ export interface NavBarProps {
32
32
  */
33
33
  rightContent?: React.ReactNode;
34
34
  /**
35
- * 自定义样式,背景和文字颜色可在此定义
35
+ * 自定义样式,最外层元素的背景文字颜色可在此定义
36
36
  * @en Custom stylesheet, background and text colors can be defined here
37
37
  */
38
38
  style?: React.CSSProperties;
39
39
  /**
40
- * 自定义类名
41
- * @en Custom classname
40
+ * 内层自定义类名
41
+ * @en Inner custom classname
42
42
  */
43
43
  className?: string;
44
44
  /**
@@ -53,6 +53,7 @@ var PickerCell = /*#__PURE__*/forwardRef(function (props, ref) {
53
53
  var rowCount = Math.max(rows % 2 === 0 ? rows + 1 : rows, 3);
54
54
  var isTouchMoveRef = useRef(false);
55
55
  var isTouchStopped = useRef(false);
56
+ var unmountCallbackRef = useRef();
56
57
  var timeRef = useRef(null);
57
58
  var colStyle = useMemo(function () {
58
59
  return getStyleWithVendor(_extends({
@@ -94,20 +95,24 @@ var PickerCell = /*#__PURE__*/forwardRef(function (props, ref) {
94
95
  }
95
96
 
96
97
  setTransitionDuration(transDuration ? transDuration + "ms" : '');
97
- setTransformY(transY); // 处理连续滑动的情况:
98
- // @en handle the case of continuous sliding:
99
- // 如果上一次callback还未执行,先cancel掉上一次回调,只执行最近的一次回调
100
- // @en If the last callback has not been executed, cancel the last callback first, and only execute the latest callback
98
+ setTransformY(transY); // 处理连续滑动的情况:如果上一次callback还未执行,先cancel掉上一次回调
99
+ // @en handle the case of continuous sliding: If the last callback has not been executed, cancel the last callback first
101
100
 
102
101
  if (latestCallbackTimer.current) {
103
102
  clearTimeout(latestCallbackTimer.current);
104
103
  }
105
104
 
106
- latestCallbackTimer.current = window.setTimeout(function () {
105
+ var setNormalStatus = function setNormalStatus() {
106
+ // 如果timer顺利执行,则在unmount时不再重复执行
107
+ // @en If the timer is successfully executed, it will not be repeated when unmounting
108
+ unmountCallbackRef.current = undefined;
107
109
  movingStatusRef.current = 'normal';
108
110
  setTransitionDuration('');
109
111
  callback();
110
- }, transDuration);
112
+ };
113
+
114
+ unmountCallbackRef.current = setNormalStatus;
115
+ latestCallbackTimer.current = window.setTimeout(setNormalStatus, transDuration);
111
116
  }
112
117
 
113
118
  function _scrollToIndex(itemIndex, transDuration, callback) {
@@ -305,6 +310,15 @@ var PickerCell = /*#__PURE__*/forwardRef(function (props, ref) {
305
310
  _scrollToIndexWithChange(itemIndex, 200);
306
311
  }
307
312
 
313
+ useEffect(function () {
314
+ return function () {
315
+ // 卸载组件时,如果timer中还有未执行的onchange操作,则立刻执行该操作并移除timer
316
+ // @en When unloading the component, if there is an unexecuted onchange operation in the timer, execute it immediately and remove the timer
317
+ var timerId = latestCallbackTimer.current;
318
+ unmountCallbackRef.current == null ? void 0 : unmountCallbackRef.current();
319
+ timerId && clearTimeout(timerId);
320
+ };
321
+ }, []);
308
322
  useEffect(function () {
309
323
  if (wrapRef.current) {
310
324
  wrapRef.current.addEventListener('touchstart', _handleColumnTouchStart);
package/esm/tabs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useRef, forwardRef, useImperativeHandle, useState, useEffect, useCallback, useContext } from 'react';
3
- import { cls, nextTick } from '@arco-design/mobile-utils';
3
+ import { cls, nextTick, getOffset } from '@arco-design/mobile-utils';
4
4
  import { ContextLayout, GlobalContext } from '../context-provider';
5
5
  import TabCell from './tab-cell';
6
6
  import TabPane from './tab-pane';
@@ -401,9 +401,15 @@ var Tabs = /*#__PURE__*/forwardRef(function (props, ref) {
401
401
  }
402
402
 
403
403
  function updateLayout() {
404
+ var _domRef$current, _domRef$current2;
405
+
406
+ var _getOffset = getOffset(domRef.current),
407
+ width = _getOffset.width,
408
+ height = _getOffset.height;
409
+
404
410
  cellRef.current && cellRef.current.resetUnderlineStyle();
405
- setWrapWidth(domRef.current ? domRef.current.offsetWidth : 0);
406
- setWrapHeight(domRef.current ? domRef.current.offsetHeight : 0);
411
+ setWrapWidth(width || ((_domRef$current = domRef.current) == null ? void 0 : _domRef$current.offsetWidth) || 0);
412
+ setWrapHeight(height || ((_domRef$current2 = domRef.current) == null ? void 0 : _domRef$current2.offsetHeight) || 0);
407
413
  paneRef.current && paneRef.current.setCurrentHeight();
408
414
  }
409
415
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arco-design/mobile-react",
3
- "version": "2.28.0",
3
+ "version": "2.28.2",
4
4
  "description": "",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -15,7 +15,7 @@
15
15
  "author": "taoyiyue@bytedance.com",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@arco-design/mobile-utils": "2.16.0",
18
+ "@arco-design/mobile-utils": "2.16.2",
19
19
  "@arco-design/transformable": "^1.0.0",
20
20
  "lodash.throttle": "^4.1.1",
21
21
  "resize-observer-polyfill": "^1.5.1"
@@ -28,12 +28,26 @@
28
28
  "jest": "^25.3.0"
29
29
  },
30
30
  "peerDependencies": {
31
+ "@types/react": ">=16.9.0",
32
+ "@types/react-dom": ">=16.9.0",
33
+ "@types/react-transition-group": ">=4.3.0",
31
34
  "react": ">=16.9.0",
32
35
  "react-dom": ">=16.9.0",
33
36
  "react-transition-group": ">=4.3.0"
34
37
  },
38
+ "peerDependenciesMeta": {
39
+ "@types/react": {
40
+ "optional": true
41
+ },
42
+ "@types/react-dom": {
43
+ "optional": true
44
+ },
45
+ "@types/react-transition-group": {
46
+ "optional": true
47
+ }
48
+ },
35
49
  "publishConfig": {
36
50
  "access": "public"
37
51
  },
38
- "gitHead": "6809000ae9f4310979628d4bd43a728d34266899"
52
+ "gitHead": "f923a5d573d8af95e6b158614f8e7d8184afc481"
39
53
  }
@@ -13,6 +13,12 @@ export declare function useListenResize(resizeHandler: () => void, deps?: any[],
13
13
  * @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
14
14
  * @param initialState 初始状态
15
15
  * @param initialState {en} Initial State
16
+ * @example
17
+ * ```
18
+ * import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
19
+ *
20
+ * const [scrollValue, setScrollValue] = useMountedState(value);
21
+ * ```
16
22
  */
17
23
  export declare function useMountedState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>];
18
24
  export declare function useSameRefState<T>(initialValue: T): [T, React.MutableRefObject<T>, (data: T) => void];
@@ -37,7 +43,7 @@ export declare function useAddListener(dom: HTMLDivElement | null, event: string
37
43
  capture: boolean;
38
44
  }): void;
39
45
  export declare function usePreventBodyScroll(visible: boolean, preventBodyScroll: boolean, initialBodyOverflow?: string): void;
40
- export declare const useProgress: (mountedTransition: boolean, percentage: number, duration: number, mountedBezier: BezierType, step: number) => [number, boolean];
46
+ export declare function useProgress(mountedTransition: boolean, percentage: number, duration: number, mountedBezier: BezierType, step: number): [number, boolean];
41
47
  export declare function useSingleAndDoubleClick(onClick: (e: React.MouseEvent) => void, onDoubleClick: (e: React.MouseEvent) => void, delay?: number): (e: React.MouseEvent) => void;
42
48
  export declare function useGenSvgKey(userSetSvgKey: string): {
43
49
  svgKey: string;
@@ -22,7 +22,7 @@
22
22
  _exports.useMountedState = useMountedState;
23
23
  _exports.usePopupScroll = usePopupScroll;
24
24
  _exports.usePreventBodyScroll = usePreventBodyScroll;
25
- _exports.useProgress = void 0;
25
+ _exports.useProgress = useProgress;
26
26
  _exports.useRefMountedState = useRefMountedState;
27
27
  _exports.useRefState = useRefState;
28
28
  _exports.useSameRefState = useSameRefState;
@@ -66,6 +66,12 @@
66
66
  * @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
67
67
  * @param initialState 初始状态
68
68
  * @param initialState {en} Initial State
69
+ * @example
70
+ * ```
71
+ * import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
72
+ *
73
+ * const [scrollValue, setScrollValue] = useMountedState(value);
74
+ * ```
69
75
  */
70
76
 
71
77
 
@@ -494,7 +500,7 @@
494
500
  }, [visible]);
495
501
  }
496
502
 
497
- var useProgress = function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
503
+ function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
498
504
  var _useState8 = (0, _react.useState)(0),
499
505
  currentPercentage = _useState8[0],
500
506
  setCurrentPercentage = _useState8[1];
@@ -528,9 +534,7 @@
528
534
  percentage === 100 ? setCurrentPercentage(100) : setCurrentPercentage(count * step);
529
535
  }, [count, percentage, step]);
530
536
  return [currentPercentage, transitionControl];
531
- };
532
-
533
- _exports.useProgress = useProgress;
537
+ }
534
538
 
535
539
  function useSingleAndDoubleClick(onClick, onDoubleClick, delay) {
536
540
  if (delay === void 0) {
@@ -18,7 +18,7 @@ export interface AvatarProps<T extends ImageProps = ImageProps> extends BaseProp
18
18
  * 图片头像的资源地址
19
19
  * @en resource of avatar picture
20
20
  */
21
- src: string;
21
+ src?: string;
22
22
  /**
23
23
  * 图片头像组件参数,透传给Image组件
24
24
  * @en Image avatar component props, transparently passed to the Image component