@@ -507,14 +507,19 @@ export const Sheet = forwardRef<any, SheetProps>(
507507 const initialSnapPoint =
508508 initialSnap !== undefined ? getSnapPoint ( initialSnap ) : null ;
509509
510+ const onAnimationComplete = makeCallableSingleTime ( ( ) => {
511+ clearYListeners ( ) ;
512+ handleOpenEnd ( ) ;
513+ resolve ( ) ;
514+ } ) ;
515+
510516 if ( ! initialSnapPoint ) {
511517 console . warn (
512518 'No initial snap point found' ,
513519 initialSnap ,
514520 snapPoints
515521 ) ;
516- handleOpenEnd ( ) ;
517- resolve ( ) ;
522+ onAnimationComplete ( ) ;
518523 return ;
519524 }
520525
@@ -527,20 +532,17 @@ export const Sheet = forwardRef<any, SheetProps>(
527532 y . on ( 'animationCancel' , ( ) => {
528533 clearYListeners ( ) ;
529534 if ( openStateRef . current === 'opening' ) {
530- handleOpenEnd ( ) ;
531- resolve ( ) ;
535+ onAnimationComplete ( ) ;
532536 } else {
533537 reject ( 'stopped opening' ) ;
534538 }
535539 } ) ,
536- y . on ( 'animationComplete' , ( ) => {
537- clearYListeners ( ) ;
538- handleOpenEnd ( ) ;
539- resolve ( ) ;
540- } )
540+ y . on ( 'animationComplete' , onAnimationComplete )
541541 ) ;
542542
543- animate ( y , initialSnapPoint . snapValueY , animationOptions ) ;
543+ animate ( y , initialSnapPoint . snapValueY , animationOptions ) . then (
544+ onAnimationComplete
545+ ) ;
544546 }
545547 } ;
546548
@@ -575,30 +577,36 @@ export const Sheet = forwardRef<any, SheetProps>(
575577 openStateRef . current = 'closed' ;
576578 } ;
577579
580+ const onAnimationComplete = makeCallableSingleTime ( ( ) => {
581+ clearYListeners ( ) ;
582+ handleCloseEnd ( ) ;
583+ resolve ( ) ;
584+ } ) ;
585+
578586 yListenersRef . current . push (
579587 y . on ( 'animationCancel' , ( ) => {
580588 clearYListeners ( ) ;
581589
582590 if ( openStateRef . current === 'closing' ) {
583- handleCloseEnd ( ) ;
584- resolve ( ) ;
591+ onAnimationComplete ( ) ;
585592 } else {
586593 reject ( 'stopped closing' ) ;
587594 }
588595 } ) ,
589596 y . on ( 'animationComplete' , ( ) => {
590- clearYListeners ( ) ;
591-
592- handleCloseEnd ( ) ;
593- resolve ( ) ;
597+ onAnimationComplete ( ) ;
594598 } )
595599 ) ;
596600
597- animate ( y , closedY , animationOptions ) ;
601+ animate ( y , closedY , animationOptions ) . then ( ( ) => {
602+ onAnimationComplete ( ) ;
603+ } ) ;
598604 } ) ;
599605 } ,
600606 } ) ;
601607
608+ console . log ( rest . id , 'isOpen' , isOpen , 'state' , state ) ;
609+
602610 const dragProps : SheetContextType [ 'dragProps' ] = {
603611 drag : 'y' ,
604612 dragElastic : 0 ,
@@ -668,3 +676,12 @@ function linear(
668676 ) ;
669677 return outputMin + ( outputMax - outputMin ) * t ;
670678}
679+
680+ function makeCallableSingleTime < T > ( fn : ( ) => T ) {
681+ let called = false ;
682+ return ( ) => {
683+ if ( called ) return ;
684+ called = true ;
685+ fn ( ) ;
686+ } ;
687+ }
0 commit comments