import React, { useState } from 'react'; import { Calendar, LocaleConfig } from 'react-native-calendars'; import * as Colors from './utils/Colors'; import { DefaultCalendarTheme } from './utils/Constants'; import { Icon } from 'react-native-elements'; import { Text, StyleSheet, View, TouchableOpacity, Image } from 'react-native'; import type { DateTimePickerProperties } from './properties/Properties'; import * as Style from './utils/Style'; import { parseDateToCalendarFormat, parseDateOrUndefined, parseDate, } from './utils/DateUtils'; LocaleConfig.locales['en'] = { monthNames: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ], monthNamesShort: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ], dayNames: [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', ], dayNamesShort: ['S', 'M', 'T', 'W', 'T', 'F', 'S'], today: 'Today', }; LocaleConfig.defaultLocale = 'en'; const CalendarWithTimer = ( props: DateTimePickerProperties = { startDate: '', endDate: '', startTime: { hour: 0, minutes: 0, amPm: '' }, endTime: { hour: 0, minutes: 0, amPm: '' }, setStartTime: () => {}, setEndTime: () => {}, currentDate: '', onDateSelect: () => {}, onDoneSelect: () => {}, onStartEndChanged: () => {}, openBottomSheet: true, selectedDate: '', calendarTheme: DefaultCalendarTheme, onStartDateSelect: () => {}, onEndDateSelect: () => {}, onStartTimeSelect: () => {}, onEndTimeSelect: () => {}, } ) => { const [startDate, setStartDate] = useState( parseDateToCalendarFormat(props.startDate) ); const [selected, setSelected] = useState( parseDateToCalendarFormat(props.selectedDate) ); const [endDate, setEndDate] = useState( parseDateToCalendarFormat(props.endDate) ); const [isStartDateSelected, setIsStartDateSelected] = useState(true); const [isEndDateSelected, setIsEndDateSelected] = useState(false); const Arrow = () => { return ; }; const onDayPress = (day: any) => { if (isStartDateSelected) { setStartDate(day.dateString); props.onStartDateSelect(day.dateString); } else { setEndDate(day.dateString); props.onEndDateSelect(day.dateString); } setSelected(day.dateString); props.onDateSelect(day); }; function renderCustomHeader(date: any) { const header = date.toString('yyyy-MMMM'); const [month] = header.split(' '); return ( {`${month}`} ); } function SelectDate() { return ( { setIsStartDateSelected(true); setIsEndDateSelected(false); props.onStartEndChanged(1); let parsed = parseDateToCalendarFormat(startDate); setSelected(parsed); }} > {parseDate(startDate)} { setIsStartDateSelected(false); setIsEndDateSelected(true); props.onStartEndChanged(2); setSelected(endDate); }} > {parseDate(endDate)} ); } return ( { // console.log('selected day', day); }} // Month format in calendar title. Formatting values: http://arshaw.com/xdate/#Formatting monthFormat={'yyyy- MMM'} // Handler which gets executed when visible month changes in calendar. Default = undefined onMonthChange={(_month: any) => { // console.log('month changed', month); }} // Hide month navigation arrows. Default = false hideArrows={true} // Replace default arrows with custom ones (direction can be 'left' or 'right') renderArrow={(_direction: any) => } // Do not show days of other months in month page. Default = false hideExtraDays={true} // If hideArrows=false and hideExtraDays=false do not switch month when tapping on greyed out // day from another month that is visible in calendar page. Default = false disableMonthChange={false} // If firstDay=1 week starts from Monday. Note that dayNames and dayNamesShort should still start from Sunday. firstDay={1} // Hide day names. Default = false hideDayNames={false} // Show week numbers to the left. Default = false showWeekNumbers={false} // Handler which gets executed when press arrow icon left. It receive a callback can go back month onPressArrowLeft={(subtractMonth: any) => subtractMonth()} // Handler which gets executed when press arrow icon right. It receive a callback can go next month onPressArrowRight={(addMonth: any) => addMonth()} // Disable left arrow. Default = false disableArrowLeft={true} // Disable right arrow. Default = false disableArrowRight={true} // Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates /* disableAllTouchEventsForDisabledDays={true} */ // Replace default month and year title with custom one. the function receive a date as parameter. renderHeader={renderCustomHeader} // Enable the option to swipe between months. Default = false enableSwipeMonths={true} markedDates={{ [selected]: { selected: true, disableTouchEvent: true, selectedColor: Colors.PrimaryColor, }, }} /> ); }; export default CalendarWithTimer; const styles = StyleSheet.create({ header: { flexDirection: 'row', width: '100%', justifyContent: 'flex-start', marginTop: 10, marginBottom: 10, }, month: { marginLeft: 5, }, year: { marginRight: 5, }, });