Skip to content

Commit 054f8ca

Browse files
committed
chore: Remove legacy api
1 parent 4ac2221 commit 054f8ca

File tree

5 files changed

+70
-86
lines changed

5 files changed

+70
-86
lines changed

examples/animate.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.motion {
2-
transition: all .3s;
2+
transition: all 5s;
33
}
44

55
.item {

examples/animate.tsx

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,56 +56,70 @@ const MyItem: React.ForwardRefRenderFunction<any, MyItemProps> = (
5656
motionAppear,
5757
},
5858
ref,
59-
) => (
60-
<CSSMotion
61-
visible={visible}
62-
ref={ref}
63-
motionName="motion"
64-
motionAppear={motionAppear}
65-
onAppearStart={getCollapsedHeight}
66-
onAppearActive={getMaxHeight}
67-
onAppearEnd={onAppear}
68-
onLeaveStart={getCurrentHeight}
69-
onLeaveActive={getCollapsedHeight}
70-
onLeaveEnd={() => {
71-
onLeave(id);
72-
}}
73-
>
74-
{({ className, style }, motionRef) => {
75-
return (
76-
<div ref={motionRef} className={classNames('item', className)} style={style} data-id={id}>
77-
<div style={{ height: itemUuid % 2 ? 100 : undefined }}>
78-
<button
79-
type="button"
80-
onClick={() => {
81-
onClose(id);
82-
}}
83-
>
84-
Close
85-
</button>
86-
<button
87-
type="button"
88-
onClick={() => {
89-
onInsertBefore(id);
90-
}}
91-
>
92-
Insert Before
93-
</button>
94-
<button
95-
type="button"
96-
onClick={() => {
97-
onInsertAfter(id);
98-
}}
99-
>
100-
Insert After
101-
</button>
102-
{id}
59+
) => {
60+
const motionRef = React.useRef(false);
61+
React.useEffect(() => {
62+
return () => {
63+
if (motionRef.current) {
64+
onAppear();
65+
}
66+
};
67+
}, []);
68+
69+
return (
70+
<CSSMotion
71+
visible={visible}
72+
ref={ref}
73+
motionName="motion"
74+
motionAppear={motionAppear}
75+
onAppearStart={getCollapsedHeight}
76+
onAppearActive={node => {
77+
motionRef.current = true;
78+
return getMaxHeight(node);
79+
}}
80+
onAppearEnd={onAppear}
81+
onLeaveStart={getCurrentHeight}
82+
onLeaveActive={getCollapsedHeight}
83+
onLeaveEnd={() => {
84+
onLeave(id);
85+
}}
86+
>
87+
{({ className, style }, motionRef) => {
88+
return (
89+
<div ref={motionRef} className={classNames('item', className)} style={style} data-id={id}>
90+
<div style={{ height: itemUuid % 2 ? 100 : undefined }}>
91+
<button
92+
type="button"
93+
onClick={() => {
94+
onClose(id);
95+
}}
96+
>
97+
Close
98+
</button>
99+
<button
100+
type="button"
101+
onClick={() => {
102+
onInsertBefore(id);
103+
}}
104+
>
105+
Insert Before
106+
</button>
107+
<button
108+
type="button"
109+
onClick={() => {
110+
onInsertAfter(id);
111+
}}
112+
>
113+
Insert After
114+
</button>
115+
{id}
116+
</div>
103117
</div>
104-
</div>
105-
);
106-
}}
107-
</CSSMotion>
108-
);
118+
);
119+
}}
120+
</CSSMotion>
121+
);
122+
};
109123

110124
const ForwardMyItem = React.forwardRef(MyItem);
111125

@@ -165,13 +179,13 @@ const Demo = () => {
165179
height={200}
166180
itemHeight={20}
167181
itemKey="id"
168-
disabled={animating}
182+
// disabled={animating}
169183
ref={listRef}
170184
style={{
171185
border: '1px solid red',
172186
boxSizing: 'border-box',
173187
}}
174-
onSkipRender={onAppear}
188+
// onSkipRender={onAppear}
175189
// onItemRemove={onAppear}
176190
>
177191
{(item, index) => (

src/List.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ export interface ListProps<T> extends React.HTMLAttributes<any> {
4545
virtual?: boolean;
4646

4747
onScroll?: React.UIEventHandler<HTMLElement>;
48-
49-
/** @deprecated only compatible for old usage */
50-
disabled?: boolean;
51-
52-
/** When `disabled`, trigger if changed item not render. */
53-
onSkipRender?: () => void;
5448
}
5549

5650
function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
@@ -65,8 +59,6 @@ function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
6559
children,
6660
itemKey,
6761
virtual,
68-
disabled,
69-
onSkipRender,
7062
component: Component = 'div',
7163
...restProps
7264
} = props;
@@ -101,22 +93,14 @@ function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
10193
const rangeRef = useRef({ start: 0, end: mergedData.length });
10294

10395
const diffItemRef = useRef<T>();
104-
const [diffItem] = useDiffItem(mergedData, getKey, diffIndex => {
105-
if (disabled && (diffIndex < rangeRef.current.start || diffIndex > rangeRef.current.end)) {
106-
onSkipRender?.();
107-
}
108-
});
96+
const [diffItem] = useDiffItem(mergedData, getKey);
10997
diffItemRef.current = diffItem;
11098

11199
// ================================ Height ================================
112100
const [getInstanceRefFunc, collectHeight, heights, heightUpdatedMark] = useHeights(
113101
getKey,
114102
null,
115-
item => {
116-
if (disabled && diffItemRef.current === item) {
117-
onSkipRender?.();
118-
}
119-
},
103+
null,
120104
);
121105

122106
// ========================== Visible Calculation =========================

src/hooks/useDiffItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { GetKey } from '../interface';
55
export default function useDiffItem<T>(
66
data: T[],
77
getKey: GetKey<T>,
8-
onDiff: (diffIndex: number) => void,
8+
onDiff?: (diffIndex: number) => void,
99
): [T] {
1010
const [prevData, setPrevData] = React.useState(data);
1111
const [diffItem, setDiffItem] = React.useState(null);
1212

1313
React.useEffect(() => {
1414
const diff = findListDiffIndex(prevData || [], data || [], getKey);
1515
if (diff?.index !== undefined) {
16-
onDiff(diff.index);
16+
onDiff?.(diff.index);
1717
setDiffItem(data[diff.index]);
1818
}
1919
setPrevData(data);

tests/list.test.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,4 @@ describe('List.Basic', () => {
208208
expect(collected).toBeTruthy();
209209
});
210210
});
211-
212-
it('legacy onSkipRender', () => {
213-
const onSkipRender = jest.fn();
214-
let data = genData(10);
215-
const wrapper = genList({ itemHeight: 20, height: 40, data, disabled: true, onSkipRender });
216-
data = [{ id: 'test' }, ...data];
217-
wrapper.setProps({ data });
218-
wrapper.update();
219-
wrapper.find('ul').simulate('scroll', {
220-
target: { scrollTop: 400 },
221-
});
222-
wrapper.update();
223-
expect(onSkipRender).toHaveBeenCalled();
224-
});
225211
});

0 commit comments

Comments
 (0)