1- import { useWindowDimensions , type ViewStyle } from 'react-native' ;
1+ import { useWindowDimensions } from 'react-native' ;
22import { Gesture } from 'react-native-gesture-handler' ;
33import {
44 Easing ,
@@ -12,7 +12,6 @@ import {
1212 withDecay ,
1313 withSpring ,
1414 withTiming ,
15- type SharedValue ,
1615} from 'react-native-reanimated' ;
1716import { scheduleOnRN } from 'react-native-worklets' ;
1817import {
@@ -22,7 +21,7 @@ import {
2221 getStyleProperties ,
2322 getStyleTransform ,
2423} from '../../helpers/utils/animation' ;
25- import type { ToastPlacement , ToastRootAnimation } from './toast.types' ;
24+ import type { UseToastRootAnimationOptions } from './toast.types' ;
2625
2726// --------------------------------------------------
2827
@@ -71,17 +70,7 @@ export const exitingBottom = new Keyframe({
7170 * Handles opacity, translateY, and scale animations based on toast index and placement
7271 * Also handles gesture-based swipe to dismiss and rubber-band drag effects
7372 */
74- export function useToastRootAnimation ( options : {
75- animation : ToastRootAnimation | undefined ;
76- style : ViewStyle | undefined ;
77- index : number ;
78- total : SharedValue < number > ;
79- heights : SharedValue < Record < string , number > > ;
80- placement : ToastPlacement ;
81- hide ?: ( ( ids ?: string | string [ ] ) => void ) | undefined ;
82- id ?: string | undefined ;
83- isSwipable ?: boolean ;
84- } ) {
73+ export function useToastRootAnimation ( options : UseToastRootAnimationOptions ) {
8574 const {
8675 animation,
8776 style,
@@ -92,6 +81,7 @@ export function useToastRootAnimation(options: {
9281 hide,
9382 id,
9483 isSwipable = true ,
84+ maxVisibleToasts = 3 ,
9585 } = options ;
9686
9787 const { height : screenHeight } = useWindowDimensions ( ) ;
@@ -240,7 +230,7 @@ export function useToastRootAnimation(options: {
240230
241231 if ( placement === 'top' ) {
242232 // Top placement: dismiss if swiped up (negative Y)
243- if ( shouldDismiss && translationY < 0 && id && hide ) {
233+ if ( shouldDismiss && translationY < 0 && id ) {
244234 // Use withDecay to continue motion with velocity
245235 gestureTranslateY . set (
246236 withDecay (
@@ -265,7 +255,7 @@ export function useToastRootAnimation(options: {
265255 }
266256 } else {
267257 // Bottom placement: dismiss if swiped down (positive Y)
268- if ( shouldDismiss && translationY > 0 && id && hide ) {
258+ if ( shouldDismiss && translationY > 0 && id ) {
269259 // Use withDecay to continue motion with velocity
270260 gestureTranslateY . set (
271261 withDecay (
@@ -304,7 +294,10 @@ export function useToastRootAnimation(options: {
304294 const totalValue = total . get ( ) ;
305295
306296 const inputRange = [ totalValue - 1 , totalValue - 2 ] ;
307- const opacityInputRange = [ totalValue - 3 , totalValue - 4 ] ;
297+ const opacityInputRange = [
298+ totalValue - maxVisibleToasts ,
299+ totalValue - maxVisibleToasts - 1 ,
300+ ] ;
308301
309302 const opacity = interpolate ( index , opacityInputRange , opacityValue ) ;
310303 const scale = interpolate ( index , inputRange , scaleValue ) ;
0 commit comments