Untitled conversation
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
// components/DateTimePicker.tsx
import React, { useState, useMemo, useRef, useEffect } from 'react'; // Removed useCallback
import { Modal, View, Text, TouchableOpacity, StyleSheet, ScrollView, NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
// --- Constants and Helper functions remain the same ---
const ITEM_HEIGHT = 50;
const VISIBLE_ITEMS = 5;
const PICKER_HEIGHT = ITEM_HEIGHT * VISIBLE_ITEMS;
const isSameDay = (d1: Date, d2: Date) =>
d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate();
// The debounce utility is no longer needed for this component
// function debounce<T extends (...args: any[]) => any>(func: T, waitFor: number) { ... }
const DateTimePicker = ({ visible, onClose, onConfirm, currentDate }: {
visible: boolean;
onClose: () => void;
onConfirm: (date: Date) => void;
currentDate: Date;
}) => {
const [selectedDate, setSelectedDate] = useState(new Date(currentDate));
const [displayDate, setDisplayDate] = useState(new Date(currentDate));
const [mode, setMode] = useState<'date' | 'time'>('date');
const hourScrollViewRef = useRef<ScrollView>(null);
const minuteScrollViewRef = useRef<ScrollView>(null);
// ... (useEffect hooks and other handlers remain the same) ...
useEffect(() => {
if (visible) {
const newDate = new Date(currentDate);
setSelectedDate(newDate);
setDisplayDate(newDate);
setMode('date');
}
}, [visible, currentDate]);
useEffect(() => {
if (visible && mode === 'time') {
setTimeout(() => {
hourScrollViewRef.current?.scrollTo({ y: selectedDate.getHours() * ITEM_HEIGHT, animated: false });
minuteScrollViewRef.current?.scrollTo({ y: (selectedDate.getMinutes() / 5) * ITEM_HEIGHT, animated: false });
}, 50);
}
}, [mode, visible]);
const handleMonthChange = (amount: number) => {
const newDisplayDate = new Date(displayDate);
newDisplayDate.setMonth(newDisplayDate.getMonth() + amount);
setDisplayDate(newDisplayDate);
};
const handleSelectDate = (day: number) => {
const newSelectedDate = new Date(displayDate);
newSelectedDate.setDate(day);
newSelectedDate.setHours(selectedDate.getHours());
newSelectedDate.setMinutes(selectedDate.getMinutes());
setSelectedDate(newSelectedDate);
};
// --- CHANGE 1: Simplified handler. No debounce, no useCallback needed. ---
// This function is now called only when the scroll movement stops.
const handleTimeSelection = (type: 'hour' | 'minute', event: NativeSyntheticEvent<NativeScrollEvent>) => {
const { contentOffset } = event.nativeEvent;
// We can be confident this is the final position because of onMomentumScrollEnd
const index = Math.round(contentOffset.y / ITEM_HEIGHT);
setSelectedDate(prevDate => {
const newSelectedDate = new Date(prevDate);
if (type === 'hour') {
newSelectedDate.setHours(Math.max(0, Math.min(23, index)));
} else if (type === 'minute') {
newSelectedDate.setMinutes(Math.max(0, Math.min(11, index)) * 5);
}
return newSelectedDate;
});
};
const calendarGrid = useMemo(() => {
// ... (calendarGrid logic is unchanged) ...
const year = displayDate.getFullYear();
const month = displayDate.getMonth();
const firstDayOfMonth = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
const grid: (number | null)[] = [];
for (let i = 0; i < firstDayOfMonth; i++) grid.push(null);
for (let i = 1; i <= daysInMonth; i++) grid.push(i);
return grid;
}, [displayDate]);
const renderCalendar = () => (
// ... (renderCalendar JSX is unchanged) ...
<View>
<View style={styles.header}>
<TouchableOpacity onPress={() => handleMonthChange(-1)} style={styles.navButton}><Text style={styles.navButtonText}>‹</Text></TouchableOpacity>
<Text style={styles.headerText}>
{displayDate.toLocaleDateString(undefined, { month: 'long', year: 'numeric' })}
</Text>
<TouchableOpacity onPress={() => handleMonthChange(1)} style={styles.navButton}><Text style={styles.navButtonText}>›</Text></TouchableOpacity>
</View>
<View style={styles.dayLabels}>
{['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((d, i) => <Text key={i} style={styles.dayLabel}>{d}</Text>)}
</View>
<View style={styles.calendarGrid}>
{calendarGrid.map((day, index) => (
<TouchableOpacity
key={index}
style={[
styles.dayCell,
(day && isSameDay(new Date(displayDate.getFullYear(), displayDate.getMonth(), day), selectedDate)) ? styles.selectedDay : null,
(day && isSameDay(new Date(displayDate.getFullYear(), displayDate.getMonth(), day), new Date()) && !isSameDay(selectedDate, new Date())) ? styles.today : null,
]}
onPress={() => day && handleSelectDate(day)}
disabled={!day}
>
<Text style={[
styles.dayText,
(day && isSameDay(new Date(displayDate.getFullYear(), displayDate.getMonth(), day), selectedDate)) ? styles.selectedDayText : null,
]}>
{day}
</Text>
</TouchableOpacity>
))}
</View>
</View>
);
const renderTimePicker = () => {
const padding = { height: (PICKER_HEIGHT - ITEM_HEIGHT) / 2 };
return (
<View style={styles.timePickerContainer}>
<View style={styles.selectionIndicator} />
<View style={styles.wheelsContainer}>
<ScrollView
ref={hourScrollViewRef}
style={styles.timeScrollView}
showsVerticalScrollIndicator={false}
snapToInterval={ITEM_HEIGHT}
decelerationRate="fast"
// --- CHANGE 2: Use the correct event and remove scrollEventThrottle ---
onMomentumScrollEnd={(e) => handleTimeSelection('hour', e)}
>
<View style={padding} />
{Array.from({ length: 24 }).map((_, i) => (
<View key={i} style={styles.timeItem}>
<Text style={styles.timeText}>{String(i).padStart(2, '0')}</Text>
</View>
))}
<View style={padding} />
</ScrollView>
<Text style={styles.timeSeparator}>:</Text>
<ScrollView
ref={minuteScrollViewRef}
style={styles.timeScrollView}
showsVerticalScrollIndicator={false}
snapToInterval={ITEM_HEIGHT}
decelerationRate="fast"
// --- CHANGE 3: Use the correct event and remove scrollEventThrottle ---
onMomentumScrollEnd={(e) => handleTimeSelection('minute', e)}
>
<View style={padding} />
{Array.from({ length: 12 }).map((_, i) => (
<View key={i * 5} style={styles.timeItem}>
<Text style={styles.timeText}>{String(i * 5).padStart(2, '0')}</Text>
</View>
))}
<View style={padding} />
</ScrollView>
</View>
</View>
);
};
return (
// ... (Modal JSX is unchanged) ...
<Modal visible={visible} transparent animationType="fade" onRequestClose={onClose}>
<TouchableOpacity style={styles.modalOverlay} activeOpacity={1} onPress={onClose}>
<TouchableOpacity activeOpacity={1} style={styles.modalContent}>
<View style={styles.modeSelector}>
<TouchableOpacity onPress={() => setMode('date')} style={[styles.modeButton, mode === 'date' && styles.activeMode]}>
<Text style={[styles.modeText, mode === 'date' && styles.activeModeText]}>Select Date</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMode('time')} style={[styles.modeButton, mode === 'time' && styles.activeMode]}>
<Text style={[styles.modeText, mode === 'time' && styles.activeModeText]}>Select Time</Text>
</TouchableOpacity>
</View>
{mode === 'date' ? renderCalendar() : renderTimePicker()}
<View style={styles.footer}>
<Button title="Cancel" onPress={onClose} color="gray" />
<Button title="Confirm" onPress={() => onConfirm(selectedDate)} />
</View>
</TouchableOpacity>
</TouchableOpacity>
</Modal>
);
};
// --- Styles and Button component remain the same ---
const styles = StyleSheet.create({
modalOverlay: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0.5)' , zIndex: 1000,elevation: 10},
modalContent: { backgroundColor: 'white', padding: 15, borderRadius: 15, width: '90%', maxWidth: 350, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, elevation: 5 },
modeSelector: { flexDirection: 'row', justifyContent: 'center', backgroundColor: '#f3f4f6', borderRadius: 8, marginBottom: 15 },
modeButton: { flex: 1, padding: 10, alignItems: 'center' },
activeMode: { backgroundColor: '#4f46e5', borderRadius: 8 },
modeText: { fontWeight: 'bold', color: '#4f46e5' },
activeModeText: { color: 'white' },
header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingBottom: 10 },
navButton: { padding: 10 },
navButtonText: { fontSize: 20, color: '#4f46e5' },
headerText: { fontSize: 16, fontWeight: 'bold' },
dayLabels: { flexDirection: 'row' },
dayLabel: { flex: 1, textAlign: 'center', color: 'gray', fontSize: 12 },
calendarGrid: { flexDirection: 'row', flexWrap: 'wrap' },
dayCell: { width: `${100/7}%`, aspectRatio: 1, justifyContent: 'center', alignItems: 'center', borderRadius: 99 },
today: { borderWidth: 1, borderColor: '#a5b4fc' },
selectedDay: { backgroundColor: '#4f46e5' },
dayText: { fontSize: 14 },
selectedDayText: { color: 'white', fontWeight: 'bold' },
timePickerContainer: {
height: PICKER_HEIGHT,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
},
selectionIndicator: {
height: ITEM_HEIGHT,
width: '75%',
backgroundColor: '#eef2ff',
borderRadius: 10,
position: 'absolute',
zIndex: -1,
},
wheelsContainer: {
height: '100%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timeScrollView: {
height: PICKER_HEIGHT,
width: 80,
},
timeItem: {
height: ITEM_HEIGHT,
justifyContent: 'center',
alignItems: 'center',
},
timeText: {
fontSize: 24,
color: '#374151',
fontWeight: '500',
},
timeSeparator: {
fontSize: 24,
fontWeight: 'bold',
color: '#9ca3af',
marginHorizontal: 5,
},
footer: { flexDirection: 'row', justifyContent: 'space-around', paddingTop: 15, borderTopWidth: 1, borderColor: '#eee' },
});
const Button = ({ title, onPress, color }: { title: string, onPress: () => void, color?: string }) => (
<TouchableOpacity onPress={onPress} style={{ padding: 8 }}>
<Text style={{ color: color || '#4f46e5', fontWeight: 'bold', fontSize: 16 }}>{title}</Text>
</TouchableOpacity>
);
export default DateTimePicker;
It sometimes responds to my scrolling on my phone, but doesn't most of the time... What's going on? Can you please overhaul this component and send me the complete, refurbished code?
Looking at your code, the issue is likely that onMomentumScrollEnd doesn't fire reliably on all devices, especially when users make small scroll adjustments or when the scroll doesn't have enough momentum. Here's a completely overhauled version that should work much more reliably:
// components/DateTimePicker.tsx
import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';
import {
Modal,
View,
Text,
TouchableOpacity,
StyleSheet,
ScrollView,
Platform,
Dimensions
} from 'react-native';
// Constants
const ITEM_HEIGHT = 50;
const VISIBLE_ITEMS = 5;
const PICKER_HEIGHT = ITEM_HEIGHT * VISIBLE_ITEMS;
const SCREEN_WIDTH = Dimensions.get('window').width;
// Helper functions
const isSameDay = (d1: Date, d2: Date) =>
d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate();
interface DateTimePickerProps {
visible: boolean;
onClose: () => void;
onConfirm: (date: Date) => void;
currentDate: Date;
}
const DateTimePicker: React.FC<DateTimePickerProps> = ({
visible,
onClose,
onConfirm,
currentDate
}) => {
const [selectedDate, setSelectedDate] = useState(new Date(currentDate));
const [displayDate, setDisplayDate] = useState(new Date(currentDate));
const [mode, setMode] = useState<'date' | 'time'>('date');
const hourScrollViewRef = useRef<ScrollView>(null);
const minuteScrollViewRef = useRef<ScrollView>(null);
// Track if we're currently scrolling to prevent feedback loops
const isScrollingHour = useRef(false);
const isScrollingMinute = useRef(false);
// Timers for scroll end detection
const hourScrollTimer = useRef<NodeJS.Timeout | null>(null);
const minuteScrollTimer = useRef<NodeJS.Timeout | null>(null);
// Reset state when modal opens
useEffect(() => {
if (visible) {
const newDate = new Date(currentDate);
setSelectedDate(newDate);
setDisplayDate(newDate);
setMode('date');
}
}, [visible, currentDate]);
// Position time pickers when switching to time mode
useEffect(() => {
if (visible && mode === 'time') {
// Delay to ensure ScrollView is rendered
const timer = setTimeout(() => {
const hourPosition = selectedDate.getHours() * ITEM_HEIGHT;
const minutePosition = Math.floor(selectedDate.getMinutes() / 5) * ITEM_HEIGHT;
hourScrollViewRef.current?.scrollTo({
y: hourPosition,
animated: false
});
minuteScrollViewRef.current?.scrollTo({
y: minutePosition,
animated: false
});
}, 100);
return () => clearTimeout(timer);
}
}, [mode, visible, selectedDate]);
const handleMonthChange = (amount: number) => {
const newDisplayDate = new Date(displayDate);
newDisplayDate.setMonth(newDisplayDate.getMonth() + amount);
setDisplayDate(newDisplayDate);
};
const handleSelectDate = (day: number) => {
const newSelectedDate = new Date(displayDate);
newSelectedDate.setDate(day);
newSelectedDate.setHours(selectedDate.getHours());
newSelectedDate.setMinutes(selectedDate.getMinutes());
setSelectedDate(newSelectedDate);
};
// Improved scroll handling with debouncing
const handleScroll = useCallback((type: 'hour' | 'minute', offsetY: number) => {
const index = Math.round(offsetY / ITEM_HEIGHT);
const isHour = type === 'hour';
// Clear existing timer
if (isHour && hourScrollTimer.current) {
clearTimeout(hourScrollTimer.current);
} else if (!isHour && minuteScrollTimer.current) {
clearTimeout(minuteScrollTimer.current);
}
// Set scrolling flag
if (isHour) {
isScrollingHour.current = true;
} else {
isScrollingMinute.current = true;
}
// Debounce the actual state update
const timer = setTimeout(() => {
setSelectedDate(prevDate => {
const newDate = new Date(prevDate);
if (isHour) {
const hours = Math.max(0, Math.min(23, index));
newDate.setHours(hours);
isScrollingHour.current = false;
} else {
const minutes = Math.max(0, Math.min(11, index)) * 5;
newDate.setMinutes(minutes);
isScrollingMinute.current = false;
}
return newDate;
});
}, 50);
if (isHour) {
hourScrollTimer.current = timer;
} else {
minuteScrollTimer.current = timer;
}
}, []);
// Calendar grid generation
const calendarGrid = useMemo(() => {
const year = displayDate.getFullYear();
const month = displayDate.getMonth();
const firstDayOfMonth = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
const grid: (number | null)[] = [];
for (let i = 0; i < firstDayOfMonth; i++) grid.push(null);
for (let i = 1; i <= daysInMonth; i++) grid.push(i);
return grid;
}, [displayDate]);
const renderCalendar = () => (
<View style={styles.calendarContainer}>
<View style={styles.header}>
<TouchableOpacity
onPress={() => handleMonthChange(-1)}
style={styles.navButton}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
>
<Text style={styles.navButtonText}>‹</Text>
</TouchableOpacity>
<Text style={styles.headerText}>
{displayDate.toLocaleDateString(undefined, { month: 'long', year: 'numeric' })}
</Text>
<TouchableOpacity
onPress={() => handleMonthChange(1)}
style={styles.navButton}
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
>
<Text style={styles.navButtonText}>›</Text>
</TouchableOpacity>
</View>
<View style={styles.dayLabels}>
{['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((day, index) => (
<Text key={index} style={styles.dayLabel}>{day}</Text>
))}
</View>
<View style={styles.calendarGrid}>
{calendarGrid.map((day, index) => {
const isSelected = day && isSameDay(
new Date(displayDate.getFullYear(), displayDate.getMonth(), day),
selectedDate
);
const isToday = day && isSameDay(
new Date(displayDate.getFullYear(), displayDate.getMonth(), day),
new Date()
);
return (
<TouchableOpacity
key={index}
style={[
styles.dayCell,
isSelected && styles.selectedDay,
isToday && !isSelected && styles.today,
]}
onPress={() => day && handleSelectDate(day)}
disabled={!day}
activeOpacity={0.6}
>
<Text style={[
styles.dayText,
isSelected && styles.selectedDayText,
!day && styles.emptyDayText,
]}>
{day || ''}
</Text>
</TouchableOpacity>
);
})}
</View>
</View>
);
const renderTimePicker = () => {
const padding = { height: (PICKER_HEIGHT - ITEM_HEIGHT) / 2 };
return (
<View style={styles.timePickerContainer}>
<View style={styles.selectionIndicator} />
<View style={styles.wheelsContainer}>
<ScrollView
ref={hourScrollViewRef}
style={styles.timeScrollView}
showsVerticalScrollIndicator={false}
snapToInterval={ITEM_HEIGHT}
decelerationRate="fast"
scrollEventThrottle={16}
onScroll={(e) => handleScroll('hour', e.nativeEvent.contentOffset.y)}
onScrollEndDrag={(e) => {
const offsetY = e.nativeEvent.contentOffset.y;
const targetY = Math.round(offsetY / ITEM_HEIGHT) * ITEM_HEIGHT;
hourScrollViewRef.current?.scrollTo({ y: targetY, animated: true });
handleScroll('hour', targetY);
}}
onMomentumScrollEnd={(e) => {
handleScroll('hour', e.nativeEvent.contentOffset.y);
}}
>
<View style={padding} />
{Array.from({ length: 24 }, (_, i) => (
<View key={i} style={styles.timeItem}>
<Text style={[
styles.timeText,
selectedDate.getHours() === i && styles.selectedTimeText
]}>
{String(i).padStart(2, '0')}
</Text>
</View>
))}
<View style={padding} />
</ScrollView>
<Text style={styles.timeSeparator}>:</Text>
<ScrollView
ref={minuteScrollViewRef}
style={styles.timeScrollView}
showsVerticalScrollIndicator={false}
snapToInterval={ITEM_HEIGHT}
decelerationRate="fast"
scrollEventThrottle={16}
onScroll={(e) => handleScroll('minute', e.nativeEvent.contentOffset.y)}
onScrollEndDrag={(e) => {
const offsetY = e.nativeEvent.contentOffset.y;
const targetY = Math.round(offsetY / ITEM_HEIGHT) * ITEM_HEIGHT;
minuteScrollViewRef.current?.scrollTo({ y: targetY, animated: true });
handleScroll('minute', targetY);
}}
onMomentumScrollEnd={(e) => {
handleScroll('minute', e.nativeEvent.contentOffset.y);
}}
>
<View style={padding} />
{Array.from({ length: 12 }, (_, i) => (
<View key={i * 5} style={styles.timeItem}>
<Text style={[
styles.timeText,
Math.floor(selectedDate.getMinutes() / 5) === i && styles.selectedTimeText
]}>
{String(i * 5).padStart(2, '0')}
</Text>
</View>
))}
<View style={padding} />
</ScrollView>
</View>
</View>
);
};
return (
<Modal
visible={visible}
transparent
animationType="fade"
onRequestClose={onClose}
statusBarTranslucent
>
<TouchableOpacity
style={styles.modalOverlay}
activeOpacity={1}
onPress={onClose}
>
<TouchableOpacity
activeOpacity={1}
style={styles.modalContent}
onPress={(e) => e.stopPropagation()}
>
<View style={styles.modeSelector}>
<TouchableOpacity
onPress={() => setMode('date')}
style={[styles.modeButton, mode === 'date' && styles.activeMode]}
activeOpacity={0.7}
>
<Text style={[styles.modeText, mode === 'date' && styles.activeModeText]}>
Select Date
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => setMode('time')}
style={[styles.modeButton, mode === 'time' && styles.activeMode]}
activeOpacity={0.7}
>
<Text style={[styles.modeText, mode === 'time' && styles.activeModeText]}>
Select Time
</Text>
</TouchableOpacity>
</View>
<View style={styles.contentContainer}>
{mode === 'date' ? renderCalendar() : renderTimePicker()}
</View>
<View style={styles.selectedDateDisplay}>
<Text style={styles.selectedDateText}>
{selectedDate.toLocaleDateString(undefined, {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric'
})}
{' at '}
{selectedDate.toLocaleTimeString(undefined, {
hour: '2-digit',
minute: '2-digit'
})}
</Text>
</View>
<View style={styles.footer}>
<TouchableOpacity
onPress={onClose}
style={[styles.footerButton, styles.cancelButton]}
activeOpacity={0.7}
>
<Text style={styles.cancelButtonText}>Cancel</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => onConfirm(selectedDate)}
style={[styles.footerButton, styles.confirmButton]}
activeOpacity={0.7}
>
<Text style={styles.confirmButtonText}>Confirm</Text>
</TouchableOpacity>
</View>
</TouchableOpacity>
</TouchableOpacity>
</Modal>
);
};
const styles = StyleSheet.create({
modalOverlay: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0,0,0,0.5)'
},
modalContent: {
backgroundColor: 'white',
borderRadius: 20,
width: Math.min(SCREEN_WIDTH * 0.9, 380),
maxHeight: '80%',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
overflow: 'hidden'
},
modeSelector: {
flexDirection: 'row',
backgroundColor: '#f3f4f6',
borderRadius: 12,
margin: 16,
padding: 4,
},
modeButton: {
flex: 1,
paddingVertical: 12,
paddingHorizontal: 16,
alignItems: 'center',
borderRadius: 8,
},
activeMode: {
backgroundColor: '#4f46e5',
},
modeText: {
fontWeight: '600',
color: '#6b7280',
fontSize: 14,
},
activeModeText: {
color: 'white'
},
contentContainer: {
paddingHorizontal: 16,
minHeight: 300,
},
calendarContainer: {
paddingVertical: 8,
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 16,
},
navButton: {
padding: 12,
},
navButtonText: {
fontSize: 24,
color: '#4f46e5',
fontWeight: '600',
},
headerText: {
fontSize: 16,
fontWeight: '700',
color: '#1f2937',
},
dayLabels: {
flexDirection: 'row',
marginBottom: 8,
},
dayLabel: {
flex: 1,
textAlign: 'center',
color: '#9ca3af',
fontSize: 12,
fontWeight: '600',
},
calendarGrid: {
flexDirection: 'row',
flexWrap: 'wrap'
},
dayCell: {
width: `${100/7}%`,
aspectRatio: 1,
justifyContent: 'center',
alignItems: 'center',
marginVertical: 2,
},
today: {
borderWidth: 2,
borderColor: '#a5b4fc',
borderRadius: 999,
},
selectedDay: {
backgroundColor: '#4f46e5',
borderRadius: 999,
},
dayText: {
fontSize: 14,
color: '#374151',
},
emptyDayText: {
color: 'transparent',
},
selectedDayText: {
color: 'white',
fontWeight: '700'
},
timePickerContainer: {
height: PICKER_HEIGHT,
width: '100%',
justifyContent: 'center',
alignItems: 'center',
paddingVertical: 20,
},
selectionIndicator: {
height: ITEM_HEIGHT,
width: '60%',
backgroundColor: '#eef2ff',
borderRadius: 12,
position: 'absolute',
borderWidth: 2,
borderColor: '#c7d2fe',
},
wheelsContainer: {
height: '100%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
timeScrollView: {
height: PICKER_HEIGHT,
width: 80,
},
timeItem: {
height: ITEM_HEIGHT,
justifyContent: 'center',
alignItems: 'center',
},
timeText: {
fontSize: 22,
color: '#6b7280',
fontWeight: '500',
},
selectedTimeText: {
color: '#1f2937',
fontWeight: '700',
},
timeSeparator: {
fontSize: 24,
fontWeight: '700',
color: '#9ca3af',
marginHorizontal: 10,
},
selectedDateDisplay: {
paddingHorizontal: 16,
paddingVertical: 12,
backgroundColor: '#f9fafb',
marginHorizontal: 16,
marginBottom: 16,
borderRadius: 8,
},
selectedDateText: {
textAlign: 'center',
fontSize: 14,
color: '#374151',
fontWeight: '500',
},
footer: {
flexDirection: 'row',
paddingHorizontal: 16,
paddingBottom: 16,
gap: 12,
},
footerButton: {
flex: 1,
paddingVertical: 14,
borderRadius: 10,
alignItems: 'center',
},
cancelButton: {
backgroundColor: '#f3f4f6',
},
confirmButton: {
backgroundColor: '#4f46e5',
},
cancelButtonText: {
color: '#6b7280',
fontWeight: '600',
fontSize: 16,
},
confirmButtonText: {
color: 'white',
fontWeight: '600',
fontSize: 16,
},
});
export default DateTimePicker;
Key improvements made:
onScroll, onScrollEndDrag, and onMomentumScrollEnd) to ensure scroll position is captured reliablyhitSlop and better activeOpacity for better touch responsivenessThis should resolve the scrolling issues on your phone and provide a more reliable and polished user experience.