@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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.28.2](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.28.1...@arco-design/mobile-react@2.28.2) (2023-08-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * `Form` bind this in form-item ([#148](https://github.com/arco-design/arco-design-mobile/issues/148)) ([5616d53](https://github.com/arco-design/arco-design-mobile/commit/5616d537b921b009df61addccf966c5e9363a0cb))
12
+ * `PickerView` flicker issue with picker off and on when momentum scrolling is not over ([#143](https://github.com/arco-design/arco-design-mobile/issues/143)) ([e91557f](https://github.com/arco-design/arco-design-mobile/commit/e91557fc1545dd6179329dc342de4967301a7d73))
13
+ * `Tabs` use boundingRect instead of offset when calc tabs wrap size ([#146](https://github.com/arco-design/arco-design-mobile/issues/146)) ([7ece3a9](https://github.com/arco-design/arco-design-mobile/commit/7ece3a9eb76abb010aa88678af47c15a0bd319dc))
14
+
15
+
16
+
17
+
18
+
19
+ ## [2.28.1](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.28.0...@arco-design/mobile-react@2.28.1) (2023-08-02)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * `Avatar` make the prop "src" optional ([f99bbc8](https://github.com/arco-design/arco-design-mobile/commit/f99bbc812223ae6c8960b1d712040f1b221efb72))
25
+ * add [@types](https://github.com/types) to peerDependencies ([42f3d5a](https://github.com/arco-design/arco-design-mobile/commit/42f3d5ab19144702d7c371c6cbd1aa031a690abe))
26
+
27
+
28
+
29
+
30
+
6
31
  # [2.28.0](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.27.5...@arco-design/mobile-react@2.28.0) (2023-07-14)
7
32
 
8
33
 
package/README.en-US.md CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="_b
59
59
  React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">Click here</a>**
60
60
 
61
61
  ```
62
- <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.27.5/dist/style.min.css">
63
- <script src="https://unpkg.com/@arco-design/mobile-react@2.27.5/dist/index.min.js"></script>
62
+ <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.28.1/dist/style.min.css">
63
+ <script src="https://unpkg.com/@arco-design/mobile-react@2.28.1/dist/index.min.js"></script>
64
64
  ```
65
65
 
66
66
  ## Full import
package/README.md CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="
59
59
  React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">戳这里获取</a>**
60
60
 
61
61
  ```
62
- <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.27.5/dist/style.min.css">
63
- <script src="https://unpkg.com/@arco-design/mobile-react@2.27.5/dist/index.min.js"></script>
62
+ <link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.28.1/dist/style.min.css">
63
+ <script src="https://unpkg.com/@arco-design/mobile-react@2.28.1/dist/index.min.js"></script>
64
64
  ```
65
65
 
66
66
  ## 引入全部
@@ -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;
@@ -9,7 +9,7 @@ exports.useListenResize = useListenResize;
9
9
  exports.useMountedState = useMountedState;
10
10
  exports.usePopupScroll = usePopupScroll;
11
11
  exports.usePreventBodyScroll = usePreventBodyScroll;
12
- exports.useProgress = void 0;
12
+ exports.useProgress = useProgress;
13
13
  exports.useRefMountedState = useRefMountedState;
14
14
  exports.useRefState = useRefState;
15
15
  exports.useSameRefState = useSameRefState;
@@ -59,6 +59,12 @@ function useListenResize(resizeHandler, deps, needListen) {
59
59
  * @desc {en} Tips: Use in scenarios where asynchronous processing is not completed after unmount. It is not recommended to replace useState without brains
60
60
  * @param initialState 初始状态
61
61
  * @param initialState {en} Initial State
62
+ * @example
63
+ * ```
64
+ * import { useMountedState } from '@arco-design/mobile-react/esm/_helpers/hooks';
65
+ *
66
+ * const [scrollValue, setScrollValue] = useMountedState(value);
67
+ * ```
62
68
  */
63
69
 
64
70
 
@@ -487,7 +493,7 @@ function usePreventBodyScroll(visible, preventBodyScroll, initialBodyOverflow) {
487
493
  }, [visible]);
488
494
  }
489
495
 
490
- var useProgress = function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
496
+ function useProgress(mountedTransition, percentage, duration, mountedBezier, step) {
491
497
  var _useState8 = (0, _react.useState)(0),
492
498
  currentPercentage = _useState8[0],
493
499
  setCurrentPercentage = _useState8[1];
@@ -521,9 +527,7 @@ var useProgress = function useProgress(mountedTransition, percentage, duration,
521
527
  percentage === 100 ? setCurrentPercentage(100) : setCurrentPercentage(count * step);
522
528
  }, [count, percentage, step]);
523
529
  return [currentPercentage, transitionControl];
524
- };
525
-
526
- exports.useProgress = useProgress;
530
+ }
527
531
 
528
532
  function useSingleAndDoubleClick(onClick, onDoubleClick, delay) {
529
533
  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
@@ -42,15 +42,96 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
42
42
  _this._errors = [];
43
43
  _this._touched = false;
44
44
 
45
+ _this.onValueChange = function (preStore, curStore) {
46
+ _this._touched = true;
47
+ var shouldUpdate = _this.props.shouldUpdate;
48
+
49
+ if (typeof shouldUpdate === 'function') {
50
+ shouldUpdate({
51
+ preStore: preStore,
52
+ curStore: curStore
53
+ }) && _this.forceUpdate();
54
+ return;
55
+ }
56
+
57
+ _this.forceUpdate();
58
+ };
59
+
60
+ _this.getFieldError = function () {
61
+ return _this._errors;
62
+ };
63
+
64
+ _this.isFieldTouched = function () {
65
+ return _this._touched;
66
+ };
67
+
68
+ _this.validateField = function () {
69
+ var validateMessages = _this.context.validateMessages;
70
+ var getFieldValue = _this.context.form.getFieldValue;
71
+ var _this$props = _this.props,
72
+ field = _this$props.field,
73
+ rules = _this$props.rules,
74
+ onValidateStatusChange = _this$props.onValidateStatusChange;
75
+ var value = getFieldValue(field);
76
+
77
+ if (rules != null && rules.length && field) {
78
+ var _Validator;
79
+
80
+ var fieldDom = _this.props.getFormItemRef();
81
+
82
+ var fieldValidator = new _mobileUtils.Validator((_Validator = {}, _Validator[field] = rules, _Validator), {
83
+ validateMessages: validateMessages
84
+ });
85
+ return new Promise(function (resolve) {
86
+ var _fieldValidator$valid;
87
+
88
+ fieldValidator.validate((_fieldValidator$valid = {}, _fieldValidator$valid[field] = value, _fieldValidator$valid), function (errorsMap) {
89
+ var _getErrorAndWarnings = (0, _utils.getErrorAndWarnings)((errorsMap == null ? void 0 : errorsMap[field]) || []),
90
+ errors = _getErrorAndWarnings.errors,
91
+ warnings = _getErrorAndWarnings.warnings;
92
+
93
+ _this._errors = errors;
94
+ onValidateStatusChange({
95
+ errors: _this._errors,
96
+ warnings: warnings
97
+ });
98
+ return resolve({
99
+ errors: _this._errors,
100
+ warnings: warnings,
101
+ value: value,
102
+ field: field,
103
+ dom: fieldDom
104
+ });
105
+ });
106
+ });
107
+ }
108
+
109
+ return Promise.resolve({
110
+ errors: [],
111
+ warnings: [],
112
+ value: value,
113
+ field: field,
114
+ dom: null
115
+ });
116
+ };
117
+
118
+ _this.setFieldData = function (value) {
119
+ var field = _this.props.field;
120
+ var setFieldValue = _this.context.form.setFieldValue;
121
+ setFieldValue(field, value);
122
+
123
+ _this.validateField();
124
+ };
125
+
45
126
  _this.innerTriggerFunction = function (_, value) {
46
127
  var _children$props;
47
128
 
48
129
  _this.setFieldData(value);
49
130
 
50
- var _this$props = _this.props,
51
- children = _this$props.children,
52
- _this$props$trigger = _this$props.trigger,
53
- trigger = _this$props$trigger === void 0 ? 'onChange' : _this$props$trigger;
131
+ var _this$props2 = _this.props,
132
+ children = _this$props2.children,
133
+ _this$props2$trigger = _this$props2.trigger,
134
+ trigger = _this$props2$trigger === void 0 ? 'onChange' : _this$props2$trigger;
54
135
 
55
136
  if (trigger && (_children$props = children.props) != null && _children$props[trigger]) {
56
137
  var _children$props2;
@@ -68,10 +149,10 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
68
149
 
69
150
  _this.setFieldData(value);
70
151
 
71
- var _this$props2 = _this.props,
72
- children = _this$props2.children,
73
- _this$props2$trigger = _this$props2.trigger,
74
- trigger = _this$props2$trigger === void 0 ? 'onChange' : _this$props2$trigger;
152
+ var _this$props3 = _this.props,
153
+ children = _this$props3.children,
154
+ _this$props3$trigger = _this$props3.trigger,
155
+ trigger = _this$props3$trigger === void 0 ? 'onChange' : _this$props3$trigger;
75
156
 
76
157
  if (trigger && (_children$props3 = children.props) != null && _children$props3[trigger]) {
77
158
  var _children$props4;
@@ -84,6 +165,24 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
84
165
  }
85
166
  };
86
167
 
168
+ _this.innerClearFunction = function () {
169
+ var _children$props5;
170
+
171
+ var children = _this.props.children;
172
+
173
+ _this.setFieldData('');
174
+
175
+ if ((_children$props5 = children.props) != null && _children$props5.onClear) {
176
+ var _children$props6;
177
+
178
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
179
+ args[_key3] = arguments[_key3];
180
+ }
181
+
182
+ (_children$props6 = children.props) == null ? void 0 : _children$props6.onClear.apply(_children$props6, args);
183
+ }
184
+ };
185
+
87
186
  _this.destroyField = function () {};
88
187
 
89
188
  if (props != null && props.initialValue && props.field) {
@@ -111,108 +210,10 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
111
210
  this.destroyField();
112
211
  };
113
212
 
114
- _proto.onValueChange = function onValueChange(preStore, curStore) {
115
- this._touched = true;
116
- var shouldUpdate = this.props.shouldUpdate;
117
-
118
- if (typeof shouldUpdate === 'function') {
119
- shouldUpdate({
120
- preStore: preStore,
121
- curStore: curStore
122
- }) && this.forceUpdate();
123
- return;
124
- }
125
-
126
- this.forceUpdate();
127
- };
128
-
129
- _proto.getFieldError = function getFieldError() {
130
- return this._errors;
131
- };
132
-
133
- _proto.isFieldTouched = function isFieldTouched() {
134
- return this._touched;
135
- };
136
-
137
- _proto.validateField = function validateField() {
138
- var _this2 = this;
139
-
140
- var validateMessages = this.context.validateMessages;
141
- var getFieldValue = this.context.form.getFieldValue;
142
- var _this$props3 = this.props,
143
- field = _this$props3.field,
144
- rules = _this$props3.rules,
145
- onValidateStatusChange = _this$props3.onValidateStatusChange;
146
- var value = getFieldValue(field);
147
-
148
- if (rules != null && rules.length && field) {
149
- var _Validator;
150
-
151
- var fieldDom = this.props.getFormItemRef();
152
- var fieldValidator = new _mobileUtils.Validator((_Validator = {}, _Validator[field] = rules, _Validator), {
153
- validateMessages: validateMessages
154
- });
155
- return new Promise(function (resolve) {
156
- var _fieldValidator$valid;
157
-
158
- fieldValidator.validate((_fieldValidator$valid = {}, _fieldValidator$valid[field] = value, _fieldValidator$valid), function (errorsMap) {
159
- var _getErrorAndWarnings = (0, _utils.getErrorAndWarnings)((errorsMap == null ? void 0 : errorsMap[field]) || []),
160
- errors = _getErrorAndWarnings.errors,
161
- warnings = _getErrorAndWarnings.warnings;
162
-
163
- _this2._errors = errors;
164
- onValidateStatusChange({
165
- errors: _this2._errors,
166
- warnings: warnings
167
- });
168
- return resolve({
169
- errors: _this2._errors,
170
- warnings: warnings,
171
- value: value,
172
- field: field,
173
- dom: fieldDom
174
- });
175
- });
176
- });
177
- }
178
-
179
- return Promise.resolve({
180
- errors: [],
181
- warnings: [],
182
- value: value,
183
- field: field,
184
- dom: null
185
- });
186
- };
187
-
188
- _proto.setFieldData = function setFieldData(value) {
189
- var field = this.props.field;
190
- var setFieldValue = this.context.form.setFieldValue;
191
- setFieldValue(field, value);
192
- this.validateField();
193
- };
194
-
195
- _proto.innerClearFunction = function innerClearFunction() {
196
- var _children$props5;
197
-
198
- var children = this.props.children;
199
- this.setFieldData('');
200
-
201
- if ((_children$props5 = children.props) != null && _children$props5.onClear) {
202
- var _children$props6;
203
-
204
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
205
- args[_key3] = arguments[_key3];
206
- }
207
-
208
- (_children$props6 = children.props) == null ? void 0 : _children$props6.onClear.apply(_children$props6, args);
209
- }
210
- };
211
-
212
213
  _proto.renderChildren = function renderChildren() {
213
214
  var _props,
214
215
  _children$type,
215
- _this3 = this;
216
+ _this2 = this;
216
217
 
217
218
  var _this$props4 = this.props,
218
219
  children = _this$props4.children,
@@ -287,7 +288,7 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
287
288
  props.error = this._errors;
288
289
 
289
290
  props[trigger] = function (newValue) {
290
- _this3.setFieldData(newValue);
291
+ _this2.setFieldData(newValue);
291
292
 
292
293
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
293
294
  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
  /**
@@ -68,6 +68,7 @@ var PickerCell = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
68
68
  var rowCount = Math.max(rows % 2 === 0 ? rows + 1 : rows, 3);
69
69
  var isTouchMoveRef = (0, _react.useRef)(false);
70
70
  var isTouchStopped = (0, _react.useRef)(false);
71
+ var unmountCallbackRef = (0, _react.useRef)();
71
72
  var timeRef = (0, _react.useRef)(null);
72
73
  var colStyle = (0, _react.useMemo)(function () {
73
74
  return (0, _helpers.getStyleWithVendor)((0, _extends2.default)({
@@ -109,20 +110,24 @@ var PickerCell = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
109
110
  }
110
111
 
111
112
  setTransitionDuration(transDuration ? transDuration + "ms" : '');
112
- setTransformY(transY); // 处理连续滑动的情况:
113
- // @en handle the case of continuous sliding:
114
- // 如果上一次callback还未执行,先cancel掉上一次回调,只执行最近的一次回调
115
- // @en If the last callback has not been executed, cancel the last callback first, and only execute the latest callback
113
+ setTransformY(transY); // 处理连续滑动的情况:如果上一次callback还未执行,先cancel掉上一次回调
114
+ // @en handle the case of continuous sliding: If the last callback has not been executed, cancel the last callback first
116
115
 
117
116
  if (latestCallbackTimer.current) {
118
117
  clearTimeout(latestCallbackTimer.current);
119
118
  }
120
119
 
121
- latestCallbackTimer.current = window.setTimeout(function () {
120
+ var setNormalStatus = function setNormalStatus() {
121
+ // 如果timer顺利执行,则在unmount时不再重复执行
122
+ // @en If the timer is successfully executed, it will not be repeated when unmounting
123
+ unmountCallbackRef.current = undefined;
122
124
  movingStatusRef.current = 'normal';
123
125
  setTransitionDuration('');
124
126
  callback();
125
- }, transDuration);
127
+ };
128
+
129
+ unmountCallbackRef.current = setNormalStatus;
130
+ latestCallbackTimer.current = window.setTimeout(setNormalStatus, transDuration);
126
131
  }
127
132
 
128
133
  function _scrollToIndex(itemIndex, transDuration, callback) {
@@ -320,6 +325,15 @@ var PickerCell = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
320
325
  _scrollToIndexWithChange(itemIndex, 200);
321
326
  }
322
327
 
328
+ (0, _react.useEffect)(function () {
329
+ return function () {
330
+ // 卸载组件时,如果timer中还有未执行的onchange操作,则立刻执行该操作并移除timer
331
+ // @en When unloading the component, if there is an unexecuted onchange operation in the timer, execute it immediately and remove the timer
332
+ var timerId = latestCallbackTimer.current;
333
+ unmountCallbackRef.current == null ? void 0 : unmountCallbackRef.current();
334
+ timerId && clearTimeout(timerId);
335
+ };
336
+ }, []);
323
337
  (0, _react.useEffect)(function () {
324
338
  if (wrapRef.current) {
325
339
  wrapRef.current.addEventListener('touchstart', _handleColumnTouchStart);
package/cjs/tabs/index.js CHANGED
@@ -427,9 +427,15 @@ var Tabs = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
427
427
  }
428
428
 
429
429
  function updateLayout() {
430
+ var _domRef$current, _domRef$current2;
431
+
432
+ var _getOffset = (0, _mobileUtils.getOffset)(domRef.current),
433
+ width = _getOffset.width,
434
+ height = _getOffset.height;
435
+
430
436
  cellRef.current && cellRef.current.resetUnderlineStyle();
431
- setWrapWidth(domRef.current ? domRef.current.offsetWidth : 0);
432
- setWrapHeight(domRef.current ? domRef.current.offsetHeight : 0);
437
+ setWrapWidth(width || ((_domRef$current = domRef.current) == null ? void 0 : _domRef$current.offsetWidth) || 0);
438
+ setWrapHeight(height || ((_domRef$current2 = domRef.current) == null ? void 0 : _domRef$current2.offsetHeight) || 0);
433
439
  paneRef.current && paneRef.current.setCurrentHeight();
434
440
  }
435
441