@@ -47,14 +47,14 @@ const ActionSheet = React.forwardRef<
4747 zIndex = 998 ,
4848 closeOnBgTap = true ,
4949 bgTransition = "opacity 0.5s ease-in-out, z-index 0.5s ease-in-out" ,
50- className= "action-sheet" ,
51- sheetTransition = "transform 0.3s ease-in-out " ,
50+ className = "action-sheet" ,
51+ sheetTransition = "transform 0.5s linear " ,
5252 reverse = false ,
5353 } ,
5454 ref
5555 ) : JSX . Element => {
5656 const [ show , setShow ] = useState ( false ) ;
57- const [ pressed , setPressed ] = useState ( false ) ;
57+ const pressed = useRef ( false ) ;
5858 const sheetRef = useRef < HTMLDivElement > ( null ) ;
5959 const animationRef = useRef ( 0 ) ;
6060 const masterOffset = useRef ( 0 ) ;
@@ -76,13 +76,14 @@ const ActionSheet = React.forwardRef<
7676
7777 const requestSheetDown = React . useCallback ( ( ) : boolean => {
7878 if ( null !== sheetRef . current ) {
79+ sheetRef . current . style . transition = sheetTransition ;
7980 sheetRef . current . style . transform = reverse
8081 ? "translate3d(0, -101%, 0)"
8182 : "translate3d(0, 101%, 0)" ;
8283 return true ;
8384 }
8485 return false ;
85- } , [ reverse ] ) ;
86+ } , [ reverse , sheetTransition ] ) ;
8687
8788 const requestSheetUp = React . useCallback ( ( ) : boolean => {
8889 if ( null !== sheetRef . current ) {
@@ -101,8 +102,7 @@ const ActionSheet = React.forwardRef<
101102 } , [ requestSheetDown , requestSheetUp , show ] ) ;
102103
103104 const onSwipeMove = ( event : React . TouchEvent < HTMLDivElement > ) : void => {
104- event . stopPropagation ( ) ;
105- if ( pressed ) {
105+ if ( pressed . current ) {
106106 const offset = event . touches [ 0 ] . clientY - startY . current ;
107107 move ( offset ) ;
108108 }
@@ -112,7 +112,7 @@ const ActionSheet = React.forwardRef<
112112 event : React . MouseEvent < HTMLDivElement , MouseEvent >
113113 ) : void => {
114114 event . stopPropagation ( ) ;
115- if ( pressed ) {
115+ if ( pressed . current ) {
116116 if ( reverse ) {
117117 const offset = event . clientY - startY . current ;
118118 move ( offset ) ;
@@ -148,24 +148,26 @@ const ActionSheet = React.forwardRef<
148148 } ;
149149
150150 const onSwipeStart = ( event : React . TouchEvent < HTMLDivElement > ) : void => {
151+ if ( sheetRef ?. current ) sheetRef . current . style . transition = "none" ;
151152 startY . current = event . touches [ 0 ] . clientY ;
152153 changePressed ( true ) ;
153154 } ;
154155
155156 const onMouseStart = (
156157 event : React . MouseEvent < HTMLDivElement , MouseEvent >
157158 ) : void => {
159+ if ( sheetRef ?. current ) sheetRef . current . style . transition = "none" ;
158160 startY . current = event . clientY ;
159161 changePressed ( true ) ;
160162 } ;
161163
162164 const changePressed = ( x : boolean ) : void => {
163- setPressed ( x ) ;
165+ pressed . current = x ;
164166 } ;
165167
166168 const onSwipeEnd = ( ) : void => {
167169 cancelAnimationFrame ( animationRef . current ) ;
168- setPressed ( false ) ;
170+ changePressed ( false ) ;
169171 if ( Math . abs ( masterOffset . current ) > threshold ) {
170172 setShow ( false ) ;
171173 if ( onClose ) onClose ( ) ;
@@ -186,12 +188,12 @@ const ActionSheet = React.forwardRef<
186188 left : 0 ,
187189 right : 0 ,
188190 bottom : 0 ,
189- background : "rgba(0, 0, 0, 0.8)" ,
191+ backgroundColor : "rgba(0, 0, 0, 0.8)" ,
190192 backfaceVisibility : "hidden" ,
191- ...bgStyle ,
192193 transition : bgTransition ,
193194 opacity : show ? opacity : 0 ,
194195 zIndex : show ? zIndex : - 1 ,
196+ ...bgStyle ,
195197 } }
196198 > </ div >
197199 < div
@@ -217,9 +219,9 @@ const ActionSheet = React.forwardRef<
217219 backgroundColor : "#fbfbfb" ,
218220 borderTopLeftRadius : 16 ,
219221 borderTopRightRadius : 16 ,
220- ... sheetStyle ,
222+ touchAction : "none" ,
221223 zIndex : zIndex + 1 ,
222- transition : pressed ? "transform 0.05s linear" : sheetTransition ,
224+ ... sheetStyle ,
223225 } }
224226 onMouseDown = { mouseEnable ? onMouseStart : ( ) => undefined }
225227 onMouseMove = { mouseEnable ? onMouseMove : ( ) => undefined }
@@ -228,7 +230,7 @@ const ActionSheet = React.forwardRef<
228230 onTouchMove = { touchEnable ? onSwipeMove : ( ) => undefined }
229231 onTouchEnd = { touchEnable ? onSwipeEnd : ( ) => undefined }
230232 >
231- { children ? children : < div style = { { height : 150 } } /> }
233+ { children }
232234 </ div >
233235 </ Fragment >
234236 ) ;
0 commit comments