Skip to content

Commit c14eb62

Browse files
author
Petr Konecny
committed
feat: add keepVisibleAfterExiting prop to SlideAnimatedVIew
1 parent f5f85be commit c14eb62

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@
7272
"publishConfig": {
7373
"access": "public"
7474
},
75-
"repository": "https://github.com/strvcom/react-native-hero-carousel"
75+
"repository": "https://github.com/strvcom/react-native-hero-carousel",
76+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
7677
}

src/components/SlideAnimatedView/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Animated, {
44
useAnimatedReaction,
55
runOnJS,
66
AnimatedProps,
7+
useSharedValue,
78
} from 'react-native-reanimated'
89
import { interpolateInsideCarousel } from '../../utils'
910
import { 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

2224
export 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

Comments
 (0)