@@ -4,6 +4,7 @@ import Animated, {
44 useAnimatedReaction ,
55 runOnJS ,
66 AnimatedProps ,
7+ useSharedValue ,
78} from 'react-native-reanimated'
89import { interpolateInsideCarousel } from '../../utils'
910import { useState } from 'react'
@@ -17,6 +18,7 @@ type SlideAnimatedViewProps = {
1718 enteringThreshold ?: number
1819 exitingThreshold ?: number
1920 style ?: AnimatedProps < ViewProps > [ 'style' ]
21+ keepVisibleAfterExiting ?: boolean
2022}
2123
2224export const SlideAnimatedView = ( {
@@ -26,11 +28,13 @@ export const SlideAnimatedView = ({
2628 layout,
2729 enteringThreshold = 0.99 ,
2830 exitingThreshold = 0.01 ,
31+ keepVisibleAfterExiting = false ,
2932 style,
3033} : SlideAnimatedViewProps ) => {
3134 const { index, total } = useAutoCarouselSlideIndex ( )
3235 const { scrollValue } = useCarouselContext ( )
3336 const [ shouldShow , setShouldShow ] = useState ( false )
37+ const exited = useSharedValue < boolean > ( false )
3438
3539 const value = useDerivedValue ( ( ) => {
3640 return interpolateInsideCarousel ( scrollValue . value , index , total , {
@@ -56,7 +60,11 @@ export const SlideAnimatedView = ({
5660 currentValue <= exitingThreshold &&
5761 ( previousValue === null || previousValue > exitingThreshold )
5862 ) {
63+ if ( keepVisibleAfterExiting && exited . value ) {
64+ return
65+ }
5966 runOnJS ( setShouldShow ) ( false )
67+ exited . value = true
6068 }
6169 } ,
6270 [ enteringThreshold , exitingThreshold ] ,
0 commit comments