Skip to content

Commit 84b0442

Browse files
committed
chore(package): merge develop
2 parents a63c1a5 + f23758c commit 84b0442

File tree

7 files changed

+75
-90
lines changed

7 files changed

+75
-90
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
"dayjs": "^1.11.13",
169169
"hoist-non-react-statics": "^3.3.2",
170170
"lodash-es": "^4.17.21",
171-
"motion": "^12.6.3",
172171
"react-transition-group": "^4.4.2",
173172
"smoothscroll-polyfill": "^0.4.4",
174173
"tdesign-icons-react": "^0.4.4",

src/picker/PickerItem.tsx

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import React, { FC, useRef, memo, useCallback, useContext, useMemo } from 'react';
1+
import React, { FC, useRef, memo, useCallback, useContext, useMemo, useState } from 'react';
22
import { useDebounceEffect } from 'ahooks';
33
import { isUndefined } from 'lodash-es';
44
import { useDrag } from '@use-gesture/react';
5-
import { useSpring, motion } from 'motion/react';
65
import useDefaultProps from 'tdesign-mobile-react/hooks/useDefaultProps';
76
import useConfig from '../hooks/useConfig';
87
import nearest from '../_util/nearest';
@@ -52,35 +51,20 @@ const PickerItem: FC<PickerItemProps> = memo((props) => {
5251
.map((_, index) => index * itemHeight - yCompensation);
5352
}, [count, getControlItemHeight, getControlYCompensation]);
5453

55-
// const [{ y }, api] = useSpring(() => ({
56-
// from: { y: 0 },
57-
// config: {
58-
// tension: 400,
59-
// mass: 0.8,
60-
// },
61-
// }));
54+
const [y, setY] = useState(0);
6255

63-
const y = useSpring(0, {
64-
stiffness: 5,
65-
});
66-
67-
const srollTo = useCallback(
68-
(index: number, immediate = false) => {
56+
const scrollTo = useCallback(
57+
(index: number) => {
6958
const offsetYList = getOffsetYList();
7059
let nextIndex = index;
7160
if (index < 0) {
7261
nextIndex = 0;
7362
} else if (index >= offsetYList.length) {
7463
nextIndex = offsetYList.length - 1;
7564
}
76-
const offsetY = offsetYList[nextIndex];
77-
if (immediate) {
78-
y.jump(-offsetY);
79-
} else {
80-
y.set(-offsetY);
81-
}
65+
setY(offsetYList[nextIndex]);
8266
},
83-
[getOffsetYList, y],
67+
[getOffsetYList],
8468
);
8569

8670
const handleChange = (value: number | string) => {
@@ -94,13 +78,13 @@ const PickerItem: FC<PickerItemProps> = memo((props) => {
9478
() => {
9579
if (currentIndex === lastIndexRef.current) return;
9680
if (currentIndex >= 0) {
97-
srollTo(currentIndex, isUndefined(lastIndexRef.current));
81+
scrollTo(currentIndex);
9882
} else {
99-
y.set(0);
83+
setY(0);
10084
}
10185
lastIndexRef.current = currentIndex;
10286
},
103-
[y, currentIndex, srollTo],
87+
[currentIndex, scrollTo],
10488
{ wait: 100 },
10589
);
10690

@@ -118,25 +102,25 @@ const PickerItem: FC<PickerItemProps> = memo((props) => {
118102
const nextIndex = offsetYList.findIndex((item) => item === nextOffsetY);
119103
if (isUndefined(value)) {
120104
lastIndexRef.current = nextIndex;
121-
y.set(-nextOffsetY);
105+
setY(nextOffsetY);
122106
handleChange(options[nextIndex].value);
123107
} else {
124108
// 受控模式,onChange回调后等待value更新,如果不更新回退到原处
125109
handleChange(options[nextIndex].value);
126110
setTimeout(() => {
127111
if (lastIndex === lastIndexRef.current) {
128-
y.set(-offsetYList[lastIndex] || 0);
112+
setY(offsetYList[lastIndex] || 0);
129113
}
130114
}, 100);
131115
}
132116
} else {
133-
y.set(-offsetY);
117+
setY(offsetY);
134118
}
135119
},
136120
{
137121
target: rootRef,
138122
axis: 'y',
139-
from: () => [0, y.get()],
123+
from: () => [0, y],
140124
transform: ([x, y]) => [x, -y],
141125
filterTaps: true,
142126
pointer: { touch: true },
@@ -159,13 +143,20 @@ const PickerItem: FC<PickerItemProps> = memo((props) => {
159143
return withNativeProps(
160144
props,
161145
<div className={name} ref={rootRef}>
162-
<motion.div ref={controlRef} className={`${name}__wrapper`} style={{ y }}>
146+
<div
147+
ref={controlRef}
148+
className={`${name}__wrapper`}
149+
style={{
150+
transition: 'transform 0.3s ease-in-out',
151+
transform: `translateY(${-y}px)`,
152+
}}
153+
>
163154
{options.map((item) => (
164155
<div key={item.value} className={`${name}__item`}>
165156
{(formatter && formatter(item)) || item.label}
166157
</div>
167158
))}
168-
</motion.div>
159+
</div>
169160
</div>,
170161
);
171162
});

src/swipe-cell/SwipeCell.tsx

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { isArray, isBoolean } from 'lodash-es';
44
import classNames from 'classnames';
55
import { useClickAway } from 'ahooks';
66
import { useDrag } from '@use-gesture/react';
7-
import { useSpring, motion } from 'motion/react';
87
import parseTNode from 'tdesign-mobile-react/_util/parseTNode';
98
import nearest from '../_util/nearest';
109
import withNativeProps from '../_util/withNativeProps';
@@ -82,17 +81,10 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
8281
return 0;
8382
};
8483

85-
const x = useSpring(0, {
86-
stiffness: 200,
87-
damping: 30,
88-
});
84+
const [x, setX] = useState(0);
8985

90-
const close = (immediate = false) => {
91-
if (immediate) {
92-
x.jump(0);
93-
} else {
94-
x.set(0);
95-
}
86+
const close = () => {
87+
setX(0);
9688
onChange();
9789
if (curSure.content) {
9890
setTimeout(() => {
@@ -105,14 +97,9 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
10597
}
10698
};
10799

108-
const expand = (side: SideType = 'right', immediate = false) => {
109-
const offsetX = getSideOffsetX(side);
110-
if (immediate) {
111-
x.jump(offsetX);
112-
} else {
113-
x.set(offsetX);
114-
}
115-
100+
const expand = (side: SideType = 'right') => {
101+
const x = getSideOffsetX(side);
102+
setX(x);
116103
onChange(side);
117104
};
118105

@@ -148,11 +135,11 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
148135
ctx.dragging = false;
149136
});
150137
} else {
151-
x.jump(offsetX);
138+
setX(offsetX);
152139
}
153140
},
154141
{
155-
from: () => [x.get(), 0],
142+
from: () => [x, 0],
156143
bounds: () => ({
157144
left: getSideOffsetX('right'),
158145
right: getSideOffsetX('left'),
@@ -177,19 +164,18 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
177164
// 初始化 expanded,等待 dom 加载完,获取 left/right 宽度后无动画设置展开状态
178165
// 防止 left/right 为列表时,获取真实宽度有误
179166
setTimeout(() => {
180-
expand(side as SideType, !!ctx.initialExpanded);
167+
expand(side as SideType);
181168
}, 100);
182169
} else {
183170
close();
184171
}
185-
delete ctx.initialExpanded;
186172
// 可以保证expand,close正常执行
187173
// eslint-disable-next-line react-hooks/exhaustive-deps
188174
}, [opened, rootRef.current]);
189175

190176
useClickAway(
191177
() => {
192-
if (x.get() !== 0) {
178+
if (x !== 0) {
193179
close();
194180
}
195181
},
@@ -272,7 +258,7 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
272258
}
273259
}}
274260
>
275-
<motion.div className={`${swipeCellClass}__wrapper`} style={{ x }}>
261+
<div className={`${swipeCellClass}__wrapper`} style={{ transform: `translateX(${x}px)` }}>
276262
{left && (
277263
<div className={`${swipeCellClass}__left`} ref={leftRef}>
278264
{renderSureContent()}
@@ -286,7 +272,7 @@ const SwipeCell = forwardRef<SwipeCellRef, SwipeCellProps>((originProps, ref) =>
286272
{renderActions(right as any, 'right')}
287273
</div>
288274
)}
289-
</motion.div>
275+
</div>
290276
</div>,
291277
);
292278
});

src/swipe-cell/style/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import '../../_common/style/mobile/components/swipe-cell/v2/_index.less';
2+
3+
import './index.less';

src/swipe-cell/style/index.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import '../../_common/style/mobile/base.less';
2+
3+
.@{prefix}-swipe-cell {
4+
&__wrapper {
5+
transition: transform 0.3s ease-in-out;
6+
}
7+
}

0 commit comments

Comments
 (0)