@@ -16,8 +16,7 @@ const GUTTER = 24;
1616// Translate the node so he can't be seen on the screen.
1717// Later, we gonna translate back the node to his original location
1818// with `translate3d(0, 0, 0)`.`
19- function getTranslateValue ( props , node ) {
20- const { direction } = props ;
19+ function getTranslateValue ( direction , node ) {
2120 const rect = node . getBoundingClientRect ( ) ;
2221
2322 let transform ;
@@ -59,8 +58,8 @@ function getTranslateValue(props, node) {
5958 return `translateY(-${ rect . top + rect . height + GUTTER - offsetY } px)` ;
6059}
6160
62- export function setTranslateValue ( props , node ) {
63- const transform = getTranslateValue ( props , node ) ;
61+ export function setTranslateValue ( direction , node ) {
62+ const transform = getTranslateValue ( direction , node ) ;
6463
6564 if ( transform ) {
6665 node . style . webkitTransform = transform ;
@@ -83,12 +82,12 @@ function Slide(props) {
8382 onExited,
8483 style,
8584 theme,
85+ timeout,
8686 ...other
8787 } = props ;
8888
8989 const mountedRef = React . useRef ( false ) ;
9090 const childrenRef = React . useRef ( ) ;
91- const [ prevDirection , setPrevDirection ] = React . useState ( ) ;
9291 /**
9392 * used in cloneElement(children, { ref: handleRef })
9493 */
@@ -98,19 +97,24 @@ function Slide(props) {
9897 } ;
9998 const handleRef = useForkRef ( children . ref , handleOwnRef ) ;
10099
101- const handleEnter = node => {
102- setTranslateValue ( props , node ) ;
100+ const handleEnter = ( ) => {
101+ const node = childrenRef . current ;
102+ setTranslateValue ( direction , node ) ;
103103 reflow ( node ) ;
104104
105105 if ( onEnter ) {
106106 onEnter ( node ) ;
107107 }
108108 } ;
109109
110- const handleEntering = node => {
111- const transitionProps = getTransitionProps ( props , {
112- mode : 'enter' ,
113- } ) ;
110+ const handleEntering = ( ) => {
111+ const node = childrenRef . current ;
112+ const transitionProps = getTransitionProps (
113+ { timeout, style } ,
114+ {
115+ mode : 'enter' ,
116+ } ,
117+ ) ;
114118 node . style . webkitTransition = theme . transitions . create ( '-webkit-transform' , {
115119 ...transitionProps ,
116120 easing : theme . transitions . easing . easeOut ,
@@ -126,10 +130,14 @@ function Slide(props) {
126130 }
127131 } ;
128132
129- const handleExit = node => {
130- const transitionProps = getTransitionProps ( props , {
131- mode : 'exit' ,
132- } ) ;
133+ const handleExit = ( ) => {
134+ const node = childrenRef . current ;
135+ const transitionProps = getTransitionProps (
136+ { timeout, style } ,
137+ {
138+ mode : 'exit' ,
139+ } ,
140+ ) ;
133141 node . style . webkitTransition = theme . transitions . create ( '-webkit-transform' , {
134142 ...transitionProps ,
135143 easing : theme . transitions . easing . sharp ,
@@ -138,14 +146,15 @@ function Slide(props) {
138146 ...transitionProps ,
139147 easing : theme . transitions . easing . sharp ,
140148 } ) ;
141- setTranslateValue ( props , node ) ;
149+ setTranslateValue ( direction , node ) ;
142150
143151 if ( onExit ) {
144152 onExit ( node ) ;
145153 }
146154 } ;
147155
148- const handleExited = node => {
156+ const handleExited = ( ) => {
157+ const node = childrenRef . current ;
149158 // No need for transitions when the component is hidden
150159 node . style . webkitTransition = '' ;
151160 node . style . transition = '' ;
@@ -157,9 +166,9 @@ function Slide(props) {
157166
158167 const updatePosition = React . useCallback ( ( ) => {
159168 if ( childrenRef . current ) {
160- setTranslateValue ( props , childrenRef . current ) ;
169+ setTranslateValue ( direction , childrenRef . current ) ;
161170 }
162- } , [ props ] ) ;
171+ } , [ direction ] ) ;
163172
164173 React . useEffect ( ( ) => {
165174 const handleResize = debounce ( ( ) => {
@@ -169,7 +178,7 @@ function Slide(props) {
169178 }
170179
171180 if ( childrenRef . current ) {
172- setTranslateValue ( props , childrenRef . current ) ;
181+ setTranslateValue ( direction , childrenRef . current ) ;
173182 }
174183 } , 166 ) ; // Corresponds to 10 frames at 60 Hz.
175184
@@ -179,7 +188,7 @@ function Slide(props) {
179188 handleResize . clear ( ) ;
180189 window . removeEventListener ( 'resize' , handleResize ) ;
181190 } ;
182- } , [ direction , inProp , props ] ) ;
191+ } , [ direction , inProp ] ) ;
183192
184193 React . useEffect ( ( ) => {
185194 // state.mounted handle SSR, once the component is mounted, we need
@@ -193,13 +202,12 @@ function Slide(props) {
193202 } , [ inProp , updatePosition ] ) ;
194203
195204 React . useEffect ( ( ) => {
196- if ( prevDirection !== direction && ! inProp ) {
205+ if ( ! inProp ) {
197206 // We need to update the position of the drawer when the direction change and
198207 // when it's hidden.
199208 updatePosition ( ) ;
200209 }
201- setPrevDirection ( direction ) ;
202- } , [ direction , inProp , prevDirection , updatePosition ] ) ;
210+ } , [ inProp , updatePosition ] ) ;
203211
204212 return (
205213 < Transition
@@ -209,6 +217,7 @@ function Slide(props) {
209217 onExited = { handleExited }
210218 appear
211219 in = { inProp }
220+ timeout = { timeout }
212221 { ...other }
213222 >
214223 { ( state , childProps ) => {
@@ -228,8 +237,9 @@ function Slide(props) {
228237
229238Slide . propTypes = {
230239 /**
231- * A single child content element. The component used as a child must be able
232- * to hold a ref.
240+ * A single child content element.
241+ *
242+ * ⚠️The component used as a child [must be able to hold a ref](/guides/composition/#children).
233243 */
234244 children : PropTypes . element ,
235245 /**
0 commit comments