antd-mobile 5.0.0 → 5.1.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.
Files changed (125) hide show
  1. package/2x/README.md +3 -6
  2. package/2x/cjs/components/floating-panel/floating-panel.css +2 -1
  3. package/2x/cjs/components/floating-panel/floating-panel.d.ts +2 -2
  4. package/2x/cjs/components/floating-panel/floating-panel.js +6 -5
  5. package/2x/cjs/components/form/form-subscribe.d.ts +11 -0
  6. package/2x/cjs/components/form/form-subscribe.js +27 -0
  7. package/2x/cjs/components/form/index.d.ts +2 -0
  8. package/2x/cjs/components/form/index.js +3 -0
  9. package/2x/cjs/components/image/image.js +2 -2
  10. package/2x/cjs/components/image-uploader/image-uploader.d.ts +1 -0
  11. package/2x/cjs/components/image-uploader/image-uploader.js +16 -9
  12. package/2x/cjs/components/image-viewer/slide.js +59 -19
  13. package/2x/cjs/components/index-bar/index-bar.d.ts +1 -1
  14. package/2x/cjs/components/index-bar/index-bar.js +12 -4
  15. package/2x/cjs/components/index-bar/index.d.ts +2 -1
  16. package/2x/cjs/components/index-bar/panel.d.ts +5 -4
  17. package/2x/cjs/components/index-bar/sidebar.d.ts +6 -3
  18. package/2x/cjs/components/index-bar/sidebar.js +6 -3
  19. package/2x/cjs/components/picker/picker.css +3 -0
  20. package/2x/cjs/components/picker/picker.d.ts +1 -1
  21. package/2x/cjs/components/picker-view/picker-view.css +14 -3
  22. package/2x/cjs/components/picker-view/picker-view.d.ts +1 -1
  23. package/2x/cjs/components/picker-view/wheel.js +23 -9
  24. package/2x/cjs/components/slider/slider.css +2 -1
  25. package/2x/cjs/components/toast/index.d.ts +1 -1
  26. package/2x/cjs/components/toast/methods.d.ts +4 -1
  27. package/2x/cjs/components/toast/methods.js +17 -4
  28. package/2x/cjs/utils/use-drag-and-pinch.d.ts +2 -0
  29. package/2x/cjs/utils/use-drag-and-pinch.js +11 -0
  30. package/2x/cjs/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  31. package/2x/cjs/utils/use-isomorphic-update-layout-effect.js +13 -0
  32. package/2x/es/components/floating-panel/floating-panel.css +2 -1
  33. package/2x/es/components/floating-panel/floating-panel.d.ts +2 -2
  34. package/2x/es/components/floating-panel/floating-panel.js +5 -5
  35. package/2x/es/components/form/form-subscribe.d.ts +11 -0
  36. package/2x/es/components/form/form-subscribe.js +14 -0
  37. package/2x/es/components/form/index.d.ts +2 -0
  38. package/2x/es/components/form/index.js +2 -0
  39. package/2x/es/components/image/image.js +2 -2
  40. package/2x/es/components/image-uploader/image-uploader.d.ts +1 -0
  41. package/2x/es/components/image-uploader/image-uploader.js +16 -9
  42. package/2x/es/components/image-viewer/slide.js +56 -18
  43. package/2x/es/components/index-bar/index-bar.d.ts +1 -1
  44. package/2x/es/components/index-bar/index-bar.js +12 -4
  45. package/2x/es/components/index-bar/index.d.ts +2 -1
  46. package/2x/es/components/index-bar/panel.d.ts +5 -4
  47. package/2x/es/components/index-bar/sidebar.d.ts +6 -3
  48. package/2x/es/components/index-bar/sidebar.js +6 -3
  49. package/2x/es/components/picker/picker.css +3 -0
  50. package/2x/es/components/picker/picker.d.ts +1 -1
  51. package/2x/es/components/picker-view/picker-view.css +14 -3
  52. package/2x/es/components/picker-view/picker-view.d.ts +1 -1
  53. package/2x/es/components/picker-view/wheel.js +22 -8
  54. package/2x/es/components/slider/slider.css +2 -1
  55. package/2x/es/components/toast/index.d.ts +1 -1
  56. package/2x/es/components/toast/methods.d.ts +4 -1
  57. package/2x/es/components/toast/methods.js +16 -5
  58. package/2x/es/utils/use-drag-and-pinch.d.ts +2 -0
  59. package/2x/es/utils/use-drag-and-pinch.js +2 -0
  60. package/2x/es/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  61. package/2x/es/utils/use-isomorphic-update-layout-effect.js +3 -0
  62. package/2x/package.json +1 -1
  63. package/README.md +3 -6
  64. package/cjs/components/floating-panel/floating-panel.css +2 -1
  65. package/cjs/components/floating-panel/floating-panel.d.ts +2 -2
  66. package/cjs/components/floating-panel/floating-panel.js +6 -5
  67. package/cjs/components/form/form-subscribe.d.ts +11 -0
  68. package/cjs/components/form/form-subscribe.js +27 -0
  69. package/cjs/components/form/index.d.ts +2 -0
  70. package/cjs/components/form/index.js +3 -0
  71. package/cjs/components/image/image.js +2 -2
  72. package/cjs/components/image-uploader/image-uploader.d.ts +1 -0
  73. package/cjs/components/image-uploader/image-uploader.js +16 -9
  74. package/cjs/components/image-viewer/slide.js +59 -19
  75. package/cjs/components/index-bar/index-bar.d.ts +1 -1
  76. package/cjs/components/index-bar/index-bar.js +12 -4
  77. package/cjs/components/index-bar/index.d.ts +2 -1
  78. package/cjs/components/index-bar/panel.d.ts +5 -4
  79. package/cjs/components/index-bar/sidebar.d.ts +6 -3
  80. package/cjs/components/index-bar/sidebar.js +6 -3
  81. package/cjs/components/picker/picker.css +3 -0
  82. package/cjs/components/picker/picker.d.ts +1 -1
  83. package/cjs/components/picker-view/picker-view.css +13 -3
  84. package/cjs/components/picker-view/picker-view.d.ts +1 -1
  85. package/cjs/components/picker-view/wheel.js +23 -9
  86. package/cjs/components/slider/slider.css +2 -1
  87. package/cjs/components/toast/index.d.ts +1 -1
  88. package/cjs/components/toast/methods.d.ts +4 -1
  89. package/cjs/components/toast/methods.js +17 -4
  90. package/cjs/utils/use-drag-and-pinch.d.ts +2 -0
  91. package/cjs/utils/use-drag-and-pinch.js +11 -0
  92. package/cjs/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  93. package/cjs/utils/use-isomorphic-update-layout-effect.js +13 -0
  94. package/es/components/floating-panel/floating-panel.css +2 -1
  95. package/es/components/floating-panel/floating-panel.d.ts +2 -2
  96. package/es/components/floating-panel/floating-panel.js +5 -5
  97. package/es/components/form/form-subscribe.d.ts +11 -0
  98. package/es/components/form/form-subscribe.js +14 -0
  99. package/es/components/form/index.d.ts +2 -0
  100. package/es/components/form/index.js +2 -0
  101. package/es/components/image/image.js +2 -2
  102. package/es/components/image-uploader/image-uploader.d.ts +1 -0
  103. package/es/components/image-uploader/image-uploader.js +16 -9
  104. package/es/components/image-viewer/slide.js +56 -18
  105. package/es/components/index-bar/index-bar.d.ts +1 -1
  106. package/es/components/index-bar/index-bar.js +12 -4
  107. package/es/components/index-bar/index.d.ts +2 -1
  108. package/es/components/index-bar/panel.d.ts +5 -4
  109. package/es/components/index-bar/sidebar.d.ts +6 -3
  110. package/es/components/index-bar/sidebar.js +6 -3
  111. package/es/components/picker/picker.css +3 -0
  112. package/es/components/picker/picker.d.ts +1 -1
  113. package/es/components/picker-view/picker-view.css +13 -3
  114. package/es/components/picker-view/picker-view.d.ts +1 -1
  115. package/es/components/picker-view/wheel.js +22 -8
  116. package/es/components/slider/slider.css +2 -1
  117. package/es/components/toast/index.d.ts +1 -1
  118. package/es/components/toast/methods.d.ts +4 -1
  119. package/es/components/toast/methods.js +16 -5
  120. package/es/utils/use-drag-and-pinch.d.ts +2 -0
  121. package/es/utils/use-drag-and-pinch.js +2 -0
  122. package/es/utils/use-isomorphic-update-layout-effect.d.ts +2 -0
  123. package/es/utils/use-isomorphic-update-layout-effect.js +3 -0
  124. package/package.json +1 -1
  125. package/umd/antd-mobile.js +1 -1
@@ -1,12 +1,15 @@
1
1
  import React, { useRef } from 'react';
2
- import { useGesture } from '@use-gesture/react';
3
2
  import { useSpring, animated } from '@react-spring/web';
3
+ import { rubberbandIfOutOfBounds } from '../../utils/rubberband';
4
+ import { useDragAndPinch } from '../../utils/use-drag-and-pinch';
5
+ import { bound } from '../../utils/bound';
4
6
  const classPrefix = `adm-image-viewer`;
5
7
  export const Slide = props => {
6
8
  const {
7
9
  dragLockRef
8
10
  } = props;
9
11
  const controlRef = useRef(null);
12
+ const imgRef = useRef(null);
10
13
  const [{
11
14
  zoom,
12
15
  x,
@@ -16,11 +19,38 @@ export const Slide = props => {
16
19
  x: 0,
17
20
  y: 0,
18
21
  config: {
19
- tension: 300
22
+ tension: 200
20
23
  }
21
24
  }));
22
25
  const pinchLockRef = useRef(false);
23
- useGesture({
26
+
27
+ function boundXY([x, y], rubberband) {
28
+ const currentZoom = zoom.get();
29
+ let xOffset = 0,
30
+ yOffset = 0;
31
+
32
+ if (imgRef.current && controlRef.current) {
33
+ xOffset = ((currentZoom * imgRef.current.width || 0) - controlRef.current.clientWidth) / 2;
34
+ yOffset = ((currentZoom * imgRef.current.height || 0) - controlRef.current.clientHeight) / 2;
35
+ }
36
+
37
+ xOffset = xOffset > 0 ? xOffset : 0;
38
+ yOffset = yOffset > 0 ? yOffset : 0;
39
+ const bounds = {
40
+ left: -xOffset,
41
+ right: xOffset,
42
+ top: -yOffset,
43
+ bottom: yOffset
44
+ };
45
+
46
+ if (rubberband) {
47
+ return [rubberbandIfOutOfBounds(x, bounds.left, bounds.right, currentZoom * 50), rubberbandIfOutOfBounds(y, bounds.top, bounds.bottom, currentZoom * 50)];
48
+ } else {
49
+ return [bound(x, bounds.left, bounds.right), bound(y, bounds.top, bounds.bottom)];
50
+ }
51
+ }
52
+
53
+ useDragAndPinch({
24
54
  onDrag: state => {
25
55
  if (state.tap && state.elapsedTime > 0 && state.elapsedTime < 1000) {
26
56
  // 判断点击时间>0是为了过滤掉非正常操作,例如用户长按选择图片之后的取消操作(也是一次点击)
@@ -40,12 +70,20 @@ export const Slide = props => {
40
70
  y: 0
41
71
  });
42
72
  } else {
43
- const [x, y] = state.offset;
44
- api.start({
45
- x,
46
- y,
47
- immediate: true
48
- });
73
+ if (state.last) {
74
+ const [x, y] = boundXY([state.offset[0] + state.velocity[0] * state.direction[0] * 200, state.offset[1] + state.velocity[1] * state.direction[1] * 200], false);
75
+ api.start({
76
+ x,
77
+ y
78
+ });
79
+ } else {
80
+ const [x, y] = boundXY(state.offset, true);
81
+ api.start({
82
+ x,
83
+ y,
84
+ immediate: true
85
+ });
86
+ }
49
87
  }
50
88
  },
51
89
  onPinch: state => {
@@ -53,16 +91,15 @@ export const Slide = props => {
53
91
 
54
92
  pinchLockRef.current = !state.last;
55
93
  const [d] = state.offset;
56
- if (d < 0) return; // pinch的rubberband不会自动弹回bound,这里手动实现了
57
-
58
- const zoom = state.last ? Math.max(Math.min(d, props.maxZoom), 1) : d;
94
+ if (d < 0) return;
95
+ const nextZoom = state.last ? bound(d, 1, props.maxZoom) : d;
59
96
  api.start({
60
- zoom,
97
+ zoom: nextZoom,
61
98
  immediate: !state.last
62
99
  });
63
- (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, zoom);
100
+ (_a = props.onZoomChange) === null || _a === void 0 ? void 0 : _a.call(props, nextZoom);
64
101
 
65
- if (state.last && zoom <= 1) {
102
+ if (state.last && nextZoom <= 1) {
66
103
  api.start({
67
104
  x: 0,
68
105
  y: 0
@@ -106,11 +143,12 @@ export const Slide = props => {
106
143
  }, React.createElement(animated.div, {
107
144
  className: `${classPrefix}-image-wrapper`,
108
145
  style: {
109
- scale: zoom,
110
- x,
111
- y
146
+ translateX: x,
147
+ translateY: y,
148
+ scale: zoom
112
149
  }
113
150
  }, React.createElement("img", {
151
+ ref: imgRef,
114
152
  src: props.image,
115
153
  draggable: false,
116
154
  alt: props.image
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { NativeProps } from '../../utils/native-props';
3
3
  export declare type IndexBarProps = {
4
4
  sticky?: boolean;
@@ -15,9 +15,11 @@ export const IndexBar = forwardRef((p, ref) => {
15
15
  const props = mergeProps(defaultProps, p);
16
16
  const titleHeight = convertPx(35);
17
17
  const bodyRef = useRef(null);
18
- const indexes = [];
18
+ const indexItems = [];
19
19
  const panels = [];
20
20
  React.Children.forEach(props.children, child => {
21
+ var _a;
22
+
21
23
  if (!React.isValidElement(child)) return;
22
24
 
23
25
  if (child.type !== Panel) {
@@ -25,7 +27,10 @@ export const IndexBar = forwardRef((p, ref) => {
25
27
  return;
26
28
  }
27
29
 
28
- indexes.push(child.props.index);
30
+ indexItems.push({
31
+ index: child.props.index,
32
+ brief: (_a = child.props.brief) !== null && _a !== void 0 ? _a : child.props.index.charAt(0)
33
+ });
29
34
  panels.push(withNativeProps(child.props, React.createElement("div", {
30
35
  key: child.props.index,
31
36
  "data-index": child.props.index,
@@ -34,7 +39,10 @@ export const IndexBar = forwardRef((p, ref) => {
34
39
  className: `${classPrefix}-anchor-title`
35
40
  }, child.props.title || child.props.index), child.props.children)));
36
41
  });
37
- const [activeIndex, setActiveIndex] = useState(indexes[0]);
42
+ const [activeIndex, setActiveIndex] = useState(() => {
43
+ const firstItem = indexItems[0];
44
+ return firstItem ? firstItem.index : null;
45
+ });
38
46
  useImperativeHandle(ref, () => ({
39
47
  scrollTo
40
48
  }));
@@ -86,7 +94,7 @@ export const IndexBar = forwardRef((p, ref) => {
86
94
  [`${classPrefix}-sticky`]: props.sticky
87
95
  })
88
96
  }, React.createElement(Sidebar, {
89
- indexes: indexes,
97
+ indexItems: indexItems,
90
98
  activeIndex: activeIndex,
91
99
  onActive: index => {
92
100
  scrollTo(index);
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import './index-bar.less';
3
3
  export type { IndexBarProps, IndexBarRef } from './index-bar';
4
+ export type { IndexBarPanelProps } from './panel';
4
5
  declare const _default: import("react").ForwardRefExoticComponent<{
5
6
  sticky?: boolean | undefined;
6
7
  children?: import("react").ReactNode;
7
8
  } & import("../../utils/native-props").NativeProps<"--sticky-offset-top"> & import("react").RefAttributes<import("./index-bar").IndexBarRef>> & {
8
- Panel: import("react").FC<import("./panel").IndexBarAnchorProps>;
9
+ Panel: import("react").FC<import("./panel").IndexBarPanelProps>;
9
10
  };
10
11
  export default _default;
@@ -1,7 +1,8 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  import { NativeProps } from '../../utils/native-props';
3
- export declare type IndexBarAnchorProps = {
3
+ export declare type IndexBarPanelProps = {
4
4
  index: string;
5
- title?: string;
5
+ title?: ReactNode;
6
+ brief?: ReactNode;
6
7
  } & NativeProps;
7
- export declare const Panel: FC<IndexBarAnchorProps>;
8
+ export declare const Panel: FC<IndexBarPanelProps>;
@@ -1,7 +1,10 @@
1
- import { FC } from 'react';
1
+ import { FC, ReactNode } from 'react';
2
2
  declare type SidebarProps = {
3
- indexes: string[];
4
- activeIndex: string;
3
+ indexItems: {
4
+ index: string;
5
+ brief: ReactNode;
6
+ }[];
7
+ activeIndex: string | null;
5
8
  onActive: (index: string) => void;
6
9
  };
7
10
  export declare const Sidebar: FC<SidebarProps>;
@@ -33,7 +33,10 @@ export const Sidebar = props => {
33
33
  props.onActive(index);
34
34
  }
35
35
  }
36
- }, props.indexes.map(index => {
36
+ }, props.indexItems.map(({
37
+ index,
38
+ brief
39
+ }) => {
37
40
  const active = index === props.activeIndex;
38
41
  return React.createElement("div", {
39
42
  className: `${classPrefix}-sidebar-row`,
@@ -52,11 +55,11 @@ export const Sidebar = props => {
52
55
  key: index
53
56
  }, interacting && active && React.createElement("div", {
54
57
  className: `${classPrefix}-sidebar-bubble`
55
- }, index), React.createElement("div", {
58
+ }, brief), React.createElement("div", {
56
59
  className: classNames(`${classPrefix}-sidebar-item`, {
57
60
  [`${classPrefix}-sidebar-item-active`]: active
58
61
  }),
59
62
  "data-index": index
60
- }, React.createElement("div", null, index)));
63
+ }, React.createElement("div", null, brief)));
61
64
  }));
62
65
  };
@@ -2,6 +2,7 @@
2
2
  --header-button-font-size: 15px;
3
3
  --title-font-size: 15px;
4
4
  --item-font-size: 16px;
5
+ --item-height: 34px;
5
6
  width: 100%;
6
7
  height: 300px;
7
8
  overflow: hidden;
@@ -9,9 +10,11 @@
9
10
  display: flex;
10
11
  flex-direction: column;
11
12
  ---item-font-size: var(--item-font-size);
13
+ ---item-height: var(--item-height);
12
14
  }
13
15
  .adm-picker .adm-picker-view.adm-picker-view {
14
16
  --item-font-size: var(---item-font-size);
17
+ --item-height: var(---item-height);
15
18
  }
16
19
  .adm-picker-header {
17
20
  flex: none;
@@ -16,5 +16,5 @@ export declare type PickerProps = {
16
16
  confirmText?: ReactNode;
17
17
  cancelText?: ReactNode;
18
18
  children?: (items: (PickerColumnItem | null)[]) => ReactNode;
19
- } & Pick<PopupProps, 'getContainer' | 'afterShow' | 'afterClose' | 'onClick' | 'stopPropagation'> & NativeProps<'--header-button-font-size' | '--title-font-size' | '--item-font-size'>;
19
+ } & Pick<PopupProps, 'getContainer' | 'afterShow' | 'afterClose' | 'onClick' | 'stopPropagation'> & NativeProps<'--header-button-font-size' | '--title-font-size' | '--item-font-size' | '--item-height'>;
20
20
  export declare const Picker: React.NamedExoticComponent<PickerProps>;
@@ -1,5 +1,6 @@
1
1
  .adm-picker-view {
2
2
  --height: 240px;
3
+ --item-height: 34px;
3
4
  --item-font-size: 16px;
4
5
  height: var(--height);
5
6
  width: 100%;
@@ -20,7 +21,7 @@
20
21
  width: 100%;
21
22
  cursor: grab;
22
23
  position: absolute;
23
- top: calc(50% - 17px);
24
+ top: calc(50% - var(--item-height) / 2);
24
25
  left: 0;
25
26
  }
26
27
  .adm-picker-view-column-wheel::before {
@@ -42,7 +43,7 @@
42
43
  .adm-picker-view-column-item {
43
44
  font-size: var(--item-font-size);
44
45
  padding: 0 6px;
45
- height: 34px;
46
+ height: var(--item-height);
46
47
  display: flex;
47
48
  justify-content: center;
48
49
  align-items: center;
@@ -52,6 +53,15 @@
52
53
  text-overflow: ellipsis;
53
54
  white-space: nowrap;
54
55
  }
56
+ .adm-picker-view-column-item.adm-picker-view-column-item-dummy {
57
+ position: fixed;
58
+ left: 0;
59
+ bottom: 0;
60
+ padding: 0;
61
+ opacity: 0;
62
+ user-select: none;
63
+ pointer-events: none;
64
+ }
55
65
  .adm-picker-view-column-accessible {
56
66
  width: 100%;
57
67
  height: 100%;
@@ -91,7 +101,7 @@
91
101
  flex: auto;
92
102
  }
93
103
  .adm-picker-view-mask-middle {
94
- height: 34px;
104
+ height: var(--item-height);
95
105
  box-sizing: border-box;
96
106
  flex: none;
97
107
  border-top: solid 1px var(--adm-border-color);
@@ -14,5 +14,5 @@ export declare type PickerViewProps = {
14
14
  value?: PickerValue[];
15
15
  defaultValue?: PickerValue[];
16
16
  onChange?: (value: PickerValue[], extend: PickerValueExtend) => void;
17
- } & NativeProps<'--height' | '--item-font-size'>;
17
+ } & NativeProps<'--height' | '--item-height' | '--item-font-size'>;
18
18
  export declare const PickerView: React.NamedExoticComponent<PickerViewProps>;
@@ -1,14 +1,13 @@
1
1
  import React, { memo, useRef } from 'react';
2
2
  import { useSpring, animated } from '@react-spring/web';
3
3
  import { useDrag } from '@use-gesture/react';
4
- import { convertPx } from '../../utils/convert-px';
5
4
  import { rubberbandIfOutOfBounds } from '../../utils/rubberband';
6
5
  import { bound } from '../../utils/bound';
7
6
  import isEqual from 'lodash/isEqual';
8
7
  import { useIsomorphicLayoutEffect } from 'ahooks';
8
+ import classNames from 'classnames';
9
9
  const classPrefix = `adm-picker-view`;
10
10
  export const Wheel = memo(props => {
11
- const itemHeight = convertPx(34);
12
11
  const {
13
12
  value,
14
13
  column
@@ -30,12 +29,23 @@ export const Wheel = memo(props => {
30
29
  }
31
30
  }));
32
31
  const draggingRef = useRef(false);
32
+ const dummyItemRef = useRef(null);
33
+ const itemHeight = useRef(34);
34
+ useIsomorphicLayoutEffect(() => {
35
+ const dummyItem = dummyItemRef.current;
36
+ if (!dummyItem) return;
37
+ const rect = dummyItem.getBoundingClientRect();
38
+
39
+ if (rect.height > 0) {
40
+ itemHeight.current = rect.height;
41
+ }
42
+ });
33
43
  useIsomorphicLayoutEffect(() => {
34
44
  if (draggingRef.current) return;
35
45
  if (!value) return;
36
46
  const targetIndex = column.findIndex(item => item.value === value);
37
47
  if (targetIndex < 0) return;
38
- const finalPosition = targetIndex * -itemHeight;
48
+ const finalPosition = targetIndex * -itemHeight.current;
39
49
  api.start({
40
50
  y: finalPosition,
41
51
  immediate: y.goal !== finalPosition
@@ -55,7 +65,7 @@ export const Wheel = memo(props => {
55
65
  }, [column, value]);
56
66
 
57
67
  function scrollSelect(index) {
58
- const finalPosition = index * -itemHeight;
68
+ const finalPosition = index * -itemHeight.current;
59
69
  api.start({
60
70
  y: finalPosition
61
71
  });
@@ -66,18 +76,18 @@ export const Wheel = memo(props => {
66
76
 
67
77
  const bind = useDrag(state => {
68
78
  draggingRef.current = true;
69
- const min = -((column.length - 1) * itemHeight);
79
+ const min = -((column.length - 1) * itemHeight.current);
70
80
  const max = 0;
71
81
 
72
82
  if (state.last) {
73
83
  draggingRef.current = false;
74
84
  const position = state.offset[1] + state.velocity[1] * state.direction[1] * 50;
75
- const targetIndex = min < max ? -Math.round(bound(position, min, max) / itemHeight) : 0;
85
+ const targetIndex = min < max ? -Math.round(bound(position, min, max) / itemHeight.current) : 0;
76
86
  scrollSelect(targetIndex);
77
87
  } else {
78
88
  const position = state.offset[1];
79
89
  api.start({
80
- y: rubberbandIfOutOfBounds(position, min, max, itemHeight * 50, 0.2)
90
+ y: rubberbandIfOutOfBounds(position, min, max, itemHeight.current * 50, 0.2)
81
91
  });
82
92
  }
83
93
  }, {
@@ -125,7 +135,11 @@ export const Wheel = memo(props => {
125
135
 
126
136
  return React.createElement("div", Object.assign({
127
137
  className: `${classPrefix}-column`
128
- }, bind()), React.createElement(animated.div, {
138
+ }, bind()), React.createElement("div", {
139
+ ref: dummyItemRef,
140
+ className: classNames(`${classPrefix}-column-item`, `${classPrefix}-column-item-dummy`),
141
+ "aria-hidden": true
142
+ }), React.createElement(animated.div, {
129
143
  style: {
130
144
  translateY: y
131
145
  },
@@ -27,12 +27,13 @@
27
27
  }
28
28
  .adm-slider-tick {
29
29
  position: absolute;
30
- top: -3.5px;
30
+ top: 50%;
31
31
  width: 11px;
32
32
  height: 11px;
33
33
  margin-left: -5px;
34
34
  background-color: #f5f5f5;
35
35
  border-radius: 50%;
36
+ transform: translate(0, -50%);
36
37
  }
37
38
  .adm-slider-tick-active {
38
39
  background-color: var(--fill-color);
@@ -1,6 +1,6 @@
1
1
  import './toast.less';
2
2
  import { clear, show, config } from './methods';
3
- export type { ToastShowProps } from './methods';
3
+ export type { ToastShowProps, ToastHandler } from './methods';
4
4
  declare const Toast: {
5
5
  show: typeof show;
6
6
  clear: typeof clear;
@@ -1,5 +1,8 @@
1
1
  import { ToastProps } from './toast';
2
2
  export declare type ToastShowProps = Omit<ToastProps, 'visible'>;
3
- export declare function show(p: ToastShowProps | string): void;
3
+ export declare type ToastHandler = {
4
+ close: () => void;
5
+ };
6
+ export declare function show(p: ToastShowProps | string): ToastHandler;
4
7
  export declare function clear(): void;
5
8
  export declare function config(val: Pick<ToastProps, 'duration' | 'position' | 'maskClickable'>): void;
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { createRef, forwardRef, useEffect, useImperativeHandle, useState } from 'react';
2
2
  import { resolveContainer } from '../../utils/get-container';
3
3
  import ReactDOM from 'react-dom';
4
4
  import { InternalToast } from './toast';
@@ -31,8 +31,7 @@ export function show(p) {
31
31
  bodyContainer.appendChild(container);
32
32
  clear();
33
33
  containers.push(container);
34
-
35
- const TempToast = () => {
34
+ const TempToast = forwardRef((_, ref) => {
36
35
  const [visible, setVisible] = useState(true);
37
36
  useEffect(() => {
38
37
  return () => {
@@ -53,6 +52,9 @@ export function show(p) {
53
52
  window.clearTimeout(timer);
54
53
  };
55
54
  }, []);
55
+ useImperativeHandle(ref, () => ({
56
+ close: () => setVisible(false)
57
+ }));
56
58
  return React.createElement(InternalToast, Object.assign({}, props, {
57
59
  getContainer: () => container,
58
60
  visible: visible,
@@ -60,9 +62,18 @@ export function show(p) {
60
62
  unmount(container);
61
63
  }
62
64
  }));
63
- };
65
+ });
66
+ const ref = createRef();
67
+ ReactDOM.render(React.createElement(TempToast, {
68
+ ref: ref
69
+ }), container);
70
+ return {
71
+ close: () => {
72
+ var _a;
64
73
 
65
- ReactDOM.render(React.createElement(TempToast, null), container);
74
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.close();
75
+ }
76
+ };
66
77
  }
67
78
  export function clear() {
68
79
  while (true) {
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useDragAndPinch: <Config extends import("@use-gesture/react").UserGestureConfig = import("@use-gesture/react").UserGestureConfig>(_handlers: Partial<import("@use-gesture/react").NativeHandlers<import("@use-gesture/react").EventTypes> & import("@use-gesture/react").UserHandlers<import("@use-gesture/react").EventTypes>>, _config?: {} | Config | undefined) => Config["target"] extends object ? void : (...args: any[]) => Pick<import("react").DOMAttributes<EventTarget>, "onClick" | "onChange" | "onPause" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScrollCapture" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture">;
@@ -0,0 +1,2 @@
1
+ import { createUseGesture, dragAction, pinchAction } from '@use-gesture/react';
2
+ export const useDragAndPinch = createUseGesture([dragAction, pinchAction]);
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const useIsomorphicUpdateLayoutEffect: typeof import("react").useEffect | typeof import("react").useLayoutEffect;
@@ -0,0 +1,3 @@
1
+ import { createUpdateEffect } from 'ahooks/lib/createUpdateEffect';
2
+ import { useIsomorphicLayoutEffect } from 'ahooks';
3
+ export const useIsomorphicUpdateLayoutEffect = createUpdateEffect(useIsomorphicLayoutEffect);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "dependencies": {
5
5
  "@react-spring/web": "^9.4.3",
6
6
  "@types/resize-observer-browser": "^0.1.7",