@@ -27,10 +27,6 @@ interface IState {
27
27
}
28
28
29
29
class DrawerChild extends React . Component < IDrawerChildProps , IState > {
30
- static defaultProps = {
31
- switchScrollingEffect : ( ) => { } ,
32
- } ;
33
-
34
30
public static getDerivedStateFromProps (
35
31
props : IDrawerChildProps ,
36
32
{ prevProps, _self } : { prevProps : IDrawerChildProps ; _self : DrawerChild } ,
@@ -115,35 +111,35 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
115
111
this . forceUpdate ( ( ) => {
116
112
this . domFocus ( ) ;
117
113
} ) ;
114
+ this . props . scrollLocker ?. lock ( ) ;
118
115
}
119
116
}
120
117
121
118
public componentDidUpdate ( prevProps : IDrawerChildProps ) {
122
- const { open, getContainer } = this . props ;
119
+ const { open, getContainer, scrollLocker } = this . props ;
123
120
const container = getContainer && getContainer ( ) ;
124
121
if ( open !== prevProps . open ) {
125
- if ( open ) {
126
- this . domFocus ( ) ;
127
- }
128
122
if ( container && container . parentNode === document . body ) {
129
123
currentDrawer [ this . drawerId ] = ! ! open ;
130
124
}
131
125
this . openLevelTransition ( ) ;
126
+ if ( open ) {
127
+ this . domFocus ( ) ;
128
+ scrollLocker ?. lock ( ) ;
129
+ } else {
130
+ scrollLocker ?. unLock ( ) ;
131
+ }
132
132
}
133
133
}
134
134
135
135
public componentWillUnmount ( ) {
136
- const { getOpenCount, open, switchScrollingEffect } = this . props ;
137
- const openCount = typeof getOpenCount === 'function' && getOpenCount ( ) ;
136
+ const { open, scrollLocker } = this . props ;
138
137
delete currentDrawer [ this . drawerId ] ;
139
138
if ( open ) {
140
139
this . setLevelTransform ( false ) ;
141
140
document . body . style . touchAction = '' ;
142
141
}
143
- if ( ! openCount ) {
144
- document . body . style . overflow = '' ;
145
- switchScrollingEffect ( true ) ;
146
- }
142
+ scrollLocker ?. unLock ( ) ;
147
143
}
148
144
149
145
private domFocus = ( ) => {
@@ -346,17 +342,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
346
342
} ;
347
343
348
344
private addScrollingEffect = ( right : number ) => {
349
- const {
350
- placement,
351
- duration,
352
- ease,
353
- getOpenCount,
354
- switchScrollingEffect,
355
- } = this . props ;
356
- const openCount = getOpenCount && getOpenCount ( ) ;
357
- if ( openCount === 1 ) {
358
- switchScrollingEffect ( ) ;
359
- }
345
+ const { placement, duration, ease } = this . props ;
360
346
const widthTransition = `width ${ duration } ${ ease } ` ;
361
347
const transformTransition = `transform ${ duration } ${ ease } ` ;
362
348
this . dom . style . transition = 'none' ;
@@ -383,17 +369,8 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
383
369
} ;
384
370
385
371
private remScrollingEffect = ( right : number ) => {
386
- const {
387
- placement,
388
- duration,
389
- ease,
390
- getOpenCount,
391
- switchScrollingEffect,
392
- } = this . props ;
393
- const openCount = getOpenCount && getOpenCount ( ) ;
394
- if ( ! openCount ) {
395
- switchScrollingEffect ( true ) ;
396
- }
372
+ const { placement, duration, ease } = this . props ;
373
+
397
374
if ( transitionStr ) {
398
375
document . body . style . overflowX = 'hidden' ;
399
376
}
@@ -511,7 +488,7 @@ class DrawerChild extends React.Component<IDrawerChildProps, IState> {
511
488
onHandleClick,
512
489
keyboard,
513
490
getOpenCount,
514
- switchScrollingEffect ,
491
+ scrollLocker ,
515
492
...props
516
493
} = this . props ;
517
494
// 首次渲染都将是关闭状态。
0 commit comments