// template/src/components/PillCarousell/index.tsx import React, { useRef, useEffect } from 'react'; import { View, ScrollView, TouchableOpacity, Animated } from 'react-native'; import { CarouselSection } from '../../modules/core/combined-auth/data/carouselSections'; import { pillCarouselStyles } from './styles'; import { useTheme } from 'theme/ThemeProvider'; import { ThemedText } from '@components/ThemedText'; interface PillCarouselProps { sections: CarouselSection[]; activeSection: number; scrollProgress: number; onSectionPress: (index: number) => void; screenWidth: number; isDragging?: boolean; } const PillCarousel: React.FC = ({ sections, activeSection, scrollProgress, onSectionPress, screenWidth, isDragging = false }) => { // Constants for pill dimensions const PILL_WIDTH = 120; const PILL_SPACING = 16; const TOTAL_PILL_WIDTH = PILL_WIDTH + PILL_SPACING; const PILL_HEIGHT = 32; const PILL_BORDER_RADIUS = 12; const backgroundPosition = useRef(new Animated.Value(0)).current; const pillScrollViewRef = useRef(null); const { theme, themeName } = useTheme(); const styles = pillCarouselStyles(theme); // Use your theme system instead of useColorScheme const isDarkMode = themeName === 'dark'; const movingBackgroundColor = isDarkMode ? theme.colors.accent : '#000000'; const movingTextColor = isDarkMode ? '#000000' : '#ffffff'; // Black text on green accent, white text on black background console.log('PillCarousel - themeName:', themeName, 'isDarkMode:', isDarkMode, 'movingBackgroundColor:', movingBackgroundColor); // Handle background position updates useEffect(() => { if (isDragging) { const targetPosition = scrollProgress * TOTAL_PILL_WIDTH; backgroundPosition.setValue(targetPosition); } else { const targetPosition = activeSection * TOTAL_PILL_WIDTH; Animated.timing(backgroundPosition, { toValue: targetPosition, duration: 0, useNativeDriver: false, }).start(); } }, [scrollProgress, activeSection, isDragging]); // Handle pill scrolling only when activeSection changes and not dragging useEffect(() => { if (!isDragging) { scrollPillsToCenter(activeSection); } }, [activeSection]); // Only watch activeSection changes const scrollPillsToCenter = (index: number) => { console.log('scrollPillsToCenter called for index:', index); const centerOffset = (screenWidth / 2) - (PILL_WIDTH / 2); const scrollToX = Math.max(0, (index * TOTAL_PILL_WIDTH) - centerOffset + 16); console.log('Calculated scrollToX:', scrollToX); console.log('ScrollView ref exists:', !!pillScrollViewRef.current); pillScrollViewRef.current?.scrollTo({ x: scrollToX, animated: true, }); }; return ( {/* Layer 1: Static grey text */} {sections.map((section, index) => ( {/* {section.title} */} {section.title} ))} {/* Pill-shaped mask containers */} {sections.map((section, index) => ( {/* Moving green background and white text */} {section.title} ))} {/* Touch targets */} {sections.map((section, index) => ( onSectionPress(index)} /> ))} ); }; export default PillCarousel;