react-native-reanimated-carousel icon indicating copy to clipboard operation
react-native-reanimated-carousel copied to clipboard

Change width for pagination dot current index

Open Splicer97 opened this issue 3 years ago • 3 comments

Hello! I use this example for pagination dots https://github.com/dohooo/react-native-reanimated-carousel/blob/fae0fb7d8e8d6afb03247e55f12fe57dacc57859/exampleExpo/src/parallax/index.tsx#L56 but I don't know, how can I change size (width or height) slowly for my pagination dots with current index. This is a picture to understand my problem. example

Splicer97 avatar Nov 03 '22 09:11 Splicer97

I found only this solution:

const PaginationItem: FC<{ index: number; length: number; animValue: Animated.SharedValue; }> = ({animValue, index, length}) => { const width = 28; const animatedWidth = useAnimatedStyle(() => { let dotWidth = withTiming( Math.round(animValue.value) === index ? 28 : 14, ); if (index === 0 && Math.round(animValue.value) > length - 1) { dotWidth = 28; } return { width: dotWidth, }; }); const animStyle = useAnimatedStyle(() => { let inputRange = [index - 1, index, index + 1]; let outputRange = [-width, 0, width]; if (index === 0 && animValue?.value > length - 1) { inputRange = [length - 1, length, length + 1]; outputRange = [-width, 0, width]; } return { transform: [ { translateX: interpolate( animValue?.value, inputRange, outputRange, Extrapolate.CLAMP, ), }, ], }; }, [animValue, index, length]); return ( <Animated.View style={[styles.animDot, animatedWidth]}> <Animated.View style={[styles.animView, animStyle]} /> </Animated.View> ); };

Splicer97 avatar Nov 03 '22 11:11 Splicer97

@dohooo can you please implement this.

NadeemKhanFh avatar Feb 17 '23 11:02 NadeemKhanFh

@NadeemKhanFh you can check my PR https://github.com/dohooo/react-native-reanimated-carousel/pull/164/files I don't know why Dohooo (owner) don't accept it to this lib

minhchienwikipedia avatar Dec 08 '23 07:12 minhchienwikipedia

See this example for more details: https://reanimated-carousel.dev/usage

dohooo avatar May 05 '24 14:05 dohooo