@@ -47,6 +47,7 @@ import {
47
47
usePropsValidator ,
48
48
useReactiveSharedValue ,
49
49
useScrollable ,
50
+ useStableCallback ,
50
51
} from '../../hooks' ;
51
52
import type { BottomSheetMethods } from '../../types' ;
52
53
import {
@@ -1022,68 +1023,56 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1022
1023
//#endregion
1023
1024
1024
1025
//#region public methods
1025
- // biome-ignore lint/correctness/useExhaustiveDependencies(BottomSheet.name): used for debug only
1026
- const handleSnapToIndex = useCallback (
1027
- function handleSnapToIndex (
1028
- index : number ,
1029
- animationConfigs ?: WithSpringConfig | WithTimingConfig
1030
- ) {
1031
- const snapPoints = animatedSnapPoints . value ;
1032
- invariant (
1033
- index >= - 1 && index <= snapPoints . length - 1 ,
1034
- `'index' was provided but out of the provided snap points range! expected value to be between -1, ${
1035
- snapPoints . length - 1
1036
- } `
1037
- ) ;
1038
- if ( __DEV__ ) {
1039
- print ( {
1040
- component : BottomSheet . name ,
1041
- method : handleSnapToIndex . name ,
1042
- params : {
1043
- index,
1044
- } ,
1045
- } ) ;
1046
- }
1026
+ const handleSnapToIndex = useStableCallback ( function handleSnapToIndex (
1027
+ index : number ,
1028
+ animationConfigs ?: WithSpringConfig | WithTimingConfig
1029
+ ) {
1030
+ const snapPoints = animatedSnapPoints . value ;
1031
+ invariant (
1032
+ index >= - 1 && index <= snapPoints . length - 1 ,
1033
+ `'index' was provided but out of the provided snap points range! expected value to be between -1, ${
1034
+ snapPoints . length - 1
1035
+ } `
1036
+ ) ;
1037
+ if ( __DEV__ ) {
1038
+ print ( {
1039
+ component : BottomSheet . name ,
1040
+ method : handleSnapToIndex . name ,
1041
+ params : {
1042
+ index,
1043
+ } ,
1044
+ } ) ;
1045
+ }
1047
1046
1048
- const nextPosition = snapPoints [ index ] ;
1047
+ const nextPosition = snapPoints [ index ] ;
1049
1048
1050
- /**
1051
- * exit method if :
1052
- * - layout is not calculated.
1053
- * - already animating to next position.
1054
- * - sheet is forced closing.
1055
- */
1056
- if (
1057
- ! isLayoutCalculated . value ||
1058
- index === animatedNextPositionIndex . value ||
1059
- nextPosition === animatedNextPosition . value ||
1060
- isForcedClosing . value
1061
- ) {
1062
- return ;
1063
- }
1049
+ /**
1050
+ * exit method if :
1051
+ * - layout is not calculated.
1052
+ * - already animating to next position.
1053
+ * - sheet is forced closing.
1054
+ */
1055
+ if (
1056
+ ! isLayoutCalculated . value ||
1057
+ index === animatedNextPositionIndex . value ||
1058
+ nextPosition === animatedNextPosition . value ||
1059
+ isForcedClosing . value
1060
+ ) {
1061
+ return ;
1062
+ }
1064
1063
1065
- /**
1066
- * reset temporary position boolean.
1067
- */
1068
- isInTemporaryPosition . value = false ;
1064
+ /**
1065
+ * reset temporary position boolean.
1066
+ */
1067
+ isInTemporaryPosition . value = false ;
1069
1068
1070
- runOnUI ( animateToPosition ) (
1071
- nextPosition ,
1072
- ANIMATION_SOURCE . USER ,
1073
- 0 ,
1074
- animationConfigs
1075
- ) ;
1076
- } ,
1077
- [
1078
- animateToPosition ,
1079
- isLayoutCalculated ,
1080
- isInTemporaryPosition ,
1081
- isForcedClosing ,
1082
- animatedSnapPoints ,
1083
- animatedNextPosition ,
1084
- animatedNextPositionIndex ,
1085
- ]
1086
- ) ;
1069
+ runOnUI ( animateToPosition ) (
1070
+ nextPosition ,
1071
+ ANIMATION_SOURCE . USER ,
1072
+ 0 ,
1073
+ animationConfigs
1074
+ ) ;
1075
+ } ) ;
1087
1076
const handleSnapToPosition = useWorkletCallback (
1088
1077
function handleSnapToPosition (
1089
1078
position : number | string ,
@@ -1867,10 +1856,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1867
1856
* @alias onIndexChange
1868
1857
*/
1869
1858
useEffect ( ( ) => {
1870
- if ( isAnimatedOnMount . value ) {
1871
- handleSnapToIndex ( _providedIndex ) ;
1859
+ // early exit, if animate on mount is set and it did not animate yet.
1860
+ if ( animateOnMount && ! isAnimatedOnMount . value ) {
1861
+ return ;
1872
1862
}
1873
- } , [ _providedIndex , isAnimatedOnMount , handleSnapToIndex ] ) ;
1863
+
1864
+ handleSnapToIndex ( _providedIndex ) ;
1865
+ } , [ animateOnMount , _providedIndex , isAnimatedOnMount , handleSnapToIndex ] ) ;
1874
1866
//#endregion
1875
1867
1876
1868
// render
0 commit comments