1
+ /* eslint-disable arrow-body-style */
2
+
1
3
import * as React from 'react' ;
2
4
// @ts -ignore
3
5
import CSSMotion from 'rc-animate/lib/CSSMotion' ;
4
6
import classNames from 'classnames' ;
5
- import List from '../src/List' ;
7
+ import List , { ListRef } from '../src/List' ;
6
8
import './animate.less' ;
7
9
8
10
let uuid = 0 ;
@@ -41,58 +43,69 @@ const getMaxHeight = (node: HTMLElement) => {
41
43
} ;
42
44
const getCollapsedHeight = ( ) => ( { height : 0 , opacity : 0 } ) ;
43
45
44
- const MyItem : React . FC < MyItemProps > = (
45
- { id, uuid, visible, onClose, onLeave, onAppear, onInsertBefore, onInsertAfter, motionAppear } ,
46
+ const MyItem : React . ForwardRefRenderFunction < any , MyItemProps > = (
47
+ {
48
+ id,
49
+ uuid : itemUuid ,
50
+ visible,
51
+ onClose,
52
+ onLeave,
53
+ onAppear,
54
+ onInsertBefore,
55
+ onInsertAfter,
56
+ motionAppear,
57
+ } ,
46
58
ref ,
47
- ) => {
48
- return (
49
- < CSSMotion
50
- visible = { visible }
51
- ref = { ref }
52
- motionName = "motion"
53
- motionAppear = { motionAppear }
54
- onAppearStart = { getCollapsedHeight }
55
- onAppearActive = { getMaxHeight }
56
- onAppearEnd = { onAppear }
57
- onLeaveStart = { getCurrentHeight }
58
- onLeaveActive = { getCollapsedHeight }
59
- onLeaveEnd = { ( ) => {
60
- onLeave ( id ) ;
61
- } }
62
- >
63
- { ( { className, style } , motionRef ) => {
64
- return (
65
- < div ref = { motionRef } className = { classNames ( 'item' , className ) } style = { style } data-id = { id } >
66
- < div style = { { height : uuid % 2 ? 100 : undefined } } >
67
- < button
68
- onClick = { ( ) => {
69
- onClose ( id ) ;
70
- } }
71
- >
72
- Close
73
- </ button >
74
- < button
75
- onClick = { ( ) => {
76
- onInsertBefore ( id ) ;
77
- } }
78
- >
79
- Insert Before
80
- </ button >
81
- < button
82
- onClick = { ( ) => {
83
- onInsertAfter ( id ) ;
84
- } }
85
- >
86
- Insert After
87
- </ button >
88
- { id }
89
- </ div >
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 }
90
103
</ div >
91
- ) ;
92
- } }
93
- </ CSSMotion >
94
- ) ;
95
- } ;
104
+ </ div >
105
+ ) ;
106
+ } }
107
+ </ CSSMotion >
108
+ ) ;
96
109
97
110
const ForwardMyItem = React . forwardRef ( MyItem ) ;
98
111
@@ -102,7 +115,7 @@ const Demo = () => {
102
115
const [ animating , setAnimating ] = React . useState ( false ) ;
103
116
const [ insertIndex , setInsertIndex ] = React . useState < number > ( ) ;
104
117
105
- const listRef = React . useRef < List < Item > > ( ) ;
118
+ const listRef = React . useRef < ListRef > ( ) ;
106
119
107
120
const onClose = ( id : string ) => {
108
121
setCloseMap ( {
@@ -117,6 +130,7 @@ const Demo = () => {
117
130
} ;
118
131
119
132
const onAppear = ( ...args : any [ ] ) => {
133
+ console . log ( 'Appear:' , args ) ;
120
134
setAnimating ( false ) ;
121
135
} ;
122
136
@@ -157,8 +171,8 @@ const Demo = () => {
157
171
border : '1px solid red' ,
158
172
boxSizing : 'border-box' ,
159
173
} }
160
-
161
174
onSkipRender = { onAppear }
175
+ // onItemRemove={onAppear}
162
176
>
163
177
{ ( item , index ) => (
164
178
< ForwardMyItem
0 commit comments