diff --git a/src/components/Day.tsx b/src/components/Day.tsx index 6fa26a1..f0fb16b 100644 --- a/src/components/Day.tsx +++ b/src/components/Day.tsx @@ -15,12 +15,9 @@ interface Props extends Omit { height?: number; } -function EmptyDayPure({ height }: { height?: number }) { - const style = styles(height || CALENDAR_HEIGHT); - return ; -} - -export const EmptyDay = React.memo(EmptyDayPure); +export const EmptyDay = React.memo(({ height }: { height?: number }) => ( + +)); function Day({ date, @@ -36,103 +33,83 @@ function Day({ theme, height, }: Props) { - const onPress = React.useCallback(() => { - onSelectDate(date); - }, [onSelectDate, date]); + const onPress = React.useCallback( + () => onSelectDate(date), + [onSelectDate, date] + ); const { calendarTextStyle, dayContainerStyle, - selectedItemColor, + selectedItemColor = '#0047FF', selectedTextStyle, todayContainerStyle, todayTextStyle, selectedRangeBackgroundColor, } = theme; - //const bothWays = inRange && leftCrop && rightCrop; + const style = styles(height || CALENDAR_HEIGHT); + const rangeBackground = + selectedRangeBackgroundColor ?? addColorAlpha(selectedItemColor, 0.15); const isCrop = inRange && (leftCrop || rightCrop) && !(leftCrop && rightCrop); - const containerStyle = isCurrentMonth ? dayContainerStyle : { opacity: 0.3 }; - - const todayItemStyle = isToday - ? { - borderWidth: 2, - borderColor: selectedItemColor || '#0047FF', - ...todayContainerStyle, - } - : null; - - const activeItemStyle = isSelected - ? { - borderColor: selectedItemColor || '#0047FF', - backgroundColor: selectedItemColor || '#0047FF', - } - : null; - - const textStyle = isSelected - ? { color: '#fff', ...selectedTextStyle } - : isToday - ? { - ...calendarTextStyle, - color: selectedItemColor || '#0047FF', - ...todayTextStyle, - } - : calendarTextStyle; - - const rangeRootBackground = - selectedRangeBackgroundColor ?? addColorAlpha(selectedItemColor, 0.15); + const containerStyle = StyleSheet.flatten([ + style.dayContainer, + isCurrentMonth || isCrop ? dayContainerStyle : style.disabledDay, + isToday && { + borderWidth: 2, + borderColor: selectedItemColor, + ...todayContainerStyle, + }, + isSelected && { + borderColor: selectedItemColor, + backgroundColor: selectedItemColor, + }, + ]); - const style = styles(height || CALENDAR_HEIGHT); + const textStyle = StyleSheet.flatten([ + isSelected + ? { color: '#fff', ...selectedTextStyle } + : isToday + ? { ...calendarTextStyle, color: selectedItemColor, ...todayTextStyle } + : calendarTextStyle, + ]); return ( - {inRange && !isCrop ? ( - - ) : null} - - {isCrop && leftCrop ? ( - - ) : null} - - {isCrop && rightCrop ? ( - - ) : null} - + {inRange && !isCrop && ( + + )} + {isCrop && ( + <> + {leftCrop && ( + + )} + {rightCrop && ( + + )} + + )} - - {text} + + {text} @@ -143,7 +120,7 @@ const styles = (height: number) => StyleSheet.create({ dayCell: { position: 'relative', - width: '14.2%', + width: '14.25%', height: height / 7, }, dayContainer: { @@ -172,21 +149,18 @@ const styles = (height: number) => const customComparator = ( prevProps: Readonly, nextProps: Readonly -) => { - return ( - prevProps.date === nextProps.date && - prevProps.text === nextProps.text && - prevProps.disabled === nextProps.disabled && - prevProps.isCurrentMonth === nextProps.isCurrentMonth && - prevProps.isToday === nextProps.isToday && - prevProps.isSelected === nextProps.isSelected && - prevProps.inRange === nextProps.inRange && - prevProps.leftCrop === nextProps.leftCrop && - prevProps.rightCrop === nextProps.rightCrop && - prevProps.onSelectDate === nextProps.onSelectDate && - prevProps.height === nextProps.height && - isEqual(prevProps.theme, nextProps.theme) - ); -}; +) => + Object.is(prevProps.date, nextProps.date) && + Object.is(prevProps.text, nextProps.text) && + prevProps.disabled === nextProps.disabled && + prevProps.isCurrentMonth === nextProps.isCurrentMonth && + prevProps.isToday === nextProps.isToday && + prevProps.isSelected === nextProps.isSelected && + prevProps.inRange === nextProps.inRange && + prevProps.leftCrop === nextProps.leftCrop && + prevProps.rightCrop === nextProps.rightCrop && + prevProps.onSelectDate === nextProps.onSelectDate && + prevProps.height === nextProps.height && + isEqual(prevProps.theme, nextProps.theme); export default React.memo(Day, customComparator);