How to set date on scrolling the Week Calendar in react-native-calendars package - react-native

I am trying to use WeekCalendar from react-native-calendars package. I am able to view the WeekCalendar and scroll it. However, I want that on horizontal scroll - the currentDate should be updated to date in that current week and should be updated on the UI. How do I go about this?
I was able to find a solution for onclick but I want on scrolling the current date should be a date from that current week.
<WeekCalendar
firstDay={1}
current={selectedDateOfTheWeek}
onDayPress={(day, localDay) => {
changeSelectedDateFromCalendar(day.dateString, false);
}}
hideExtraDays={false}
pastScrollRange={24}
futureScrollRange={24}
markedDates={{
[selectedDateOfTheWeek]: {
selected: true,
selectedColor: "#8660ce"
}
}}
/>
selectedDateOfTheWeek stores the date in 'YYYY-MM-DD' format. I am using Redux to manage the state.

wrap your week calendar with <CalendarProvide and use onDateChanged event
<CalendarProvider
date={this.state.selectedDate.dateString}
onDateChanged={this.onDateChanged}
markedDates={{
...this.state.markedDates,
[this.state.selectedDate.dateString]: {
selected: true,
},
}}
>
<WeekCalendar
testID={testIDs.weekCalendar.CONTAINER}
hideDayNames={true}
firstDay={1}
dayComponent={this.renderDateWeek}
theme={calendarThemes}
calendarWidth={screenWidth}
allowShadow={false}
markedDates={{
...this.state.markedDates,
[this.state.selectedDate.dateString]: {
selected: true,
},
}}
pastScrollRange={(new Date().getFullYear() - 1900) * 12}
futureScrollRange={(2099 - new Date().getFullYear()) * 12}
style={[styles.calendar, { paddingBottom: 20, paddingLeft: 0, paddingRight: 0 }]}
onDayPress={(date) => this.changeDate(date.dateString)}
/>
</CalendarProvider>

Related

Calendar Object not updating when useState value that supplied markedDates gets changed

I am using the Calendar Object from react-native-calendars and one of the props for its supplied <Calendar> component is markedDates
It is supposed to have a format like the following...
"2022-09-12": {"activeOpacity": 0.5, "color": "white", "dots": [[Object]], "marked": true, "selected": false},
"2022-09-14": {"activeOpacity": 0.5, "color": "white", "dots": [[Object]], "marked": true, "selected": false},
"2022-09-16": {"activeOpacity": 0.5, "color": "white", "dots": [[Object]], "marked": true, "selected": false},
"2022-9-17": {"selected": true},
"2022-9-19": {"selected": false},
wherein selected if true, activates the selectedStyle on the date, and where dots is an array of dot objects that indicate the presence of dots beneath the date value.
The issue is, notice how '2022-9-17' is set to {selected: true} yet the Calendar does not reflect that. I am console.log-ing the value displayed above in a useEffect, but it does not reflect what is shown in the Calendar. Does anyone aware of Calendar know if there's a way to get around this, or if I'm doing something improperly? The Calendar is called like so...
return(
<View style={{height: maxHeight * 0.43}}>
<CalendarProvider date={selectedDay} onDateChanged={() => handleSetSelectedDay(selectedDay)}>
<Calendar
markingType={`multi-dot`}
markedDates={markedDateObjects}
hideExtraDays={true}
onDayPress={day => { handleDateClick(day) }}
// Other stuff irrelevant for the issue
/>
</CalendarProvider>
</View>
)

How to get ride of extra white space below control panel in react google charts

I'm working on a project, and I'm using react-google-charts to chart my data. The problem that I am having is that no matter what I do, I can't seem to get rid of the extra white space below my control panel. Does anyone know how to get rid of this? I would really appreciate any help or advice on how to correct this. Thank you!
<div>
<h2 className="graphname">Sales</h2>
{summary.dailySales.length === 0 ? (
<MessageBox>No Orders</MessageBox>
) : (
<Chart
width="100%"
height="400px"
chartType="AreaChart"
loader={<div>Loading Chart</div>}
data={[
['Date', 'Sales'],
...summary.dailySales.map((x) => [new Date(x._id), x.sales]),
]}
options={{
chartArea: {
left: '10%',
right: '10%',
}
}}
chartPackages={["corechart", "controls"]}
controls={[
{
controlType: "ChartRangeFilter",
options: {
filterColumnIndex: 0,
ui: {
chartType: "LineChart",
chartOptions: {
chartArea: { width: "90%",
height: "20%"
},
hAxis: { baselineColor: "none" }
}
}
},
controlPosition: "bottom",
}
]}
></Chart>
)}
</div>

Is there any React Native Date Range picker with date blocking

I am building a booking system using react native, but I am not able to find a Date Range Picker that enables me to block the reserved dates as shown in the following picture.
blocking dates on a calendar
Is there any component that does this job ??
I would preferer functional component if there is any
Try react-native-calendars.
Usage:
const school = {key:'school', color: 'orange', selectedDotColor: 'blue'};
const canteen = {key:'canteen', color: 'blue', selectedDotColor: 'blue'};
const rooms = {key:'rooms', color: 'green'};
<Calendar
markedDates={{
'2017-10-25': {dots: [school, canteen, rooms], selected: true, selectedColor: 'red'},
'2017-10-26': {dots: [canteen, rooms], disabled: true}
}}
markingType={'multi-dot'}
/>

React-native-calendars Show previous and next month instead of arrows using renderArrow function

Description
Show previous and next month instead of arrows using renderArrow function
Expected Behavior
Show previous month at left side and next month at right side
Observed Behavior
Both side shows previous month
My Code:
<Calendar
onDayPress={(day) => {this.setDay(day)}}
renderArrow={(left,right) => (left? {this.state.previousMonth}: {this.state.nextMonth})}
pastScrollRange={0}
markedDates={{[this.state.selected]: {selected: true, disableTouchEvent: true, selectedColor: '#C7A985'}}}
firstDay={1}
theme={{
selectedDayTextColor: 'white'
}}
/>
There are two things to note in your code.
The renderArrow function contains direction as a parameter which
subsequently contains the values left and right
The renderArrow function accepts JSX attributes
Therefore you need to modify your code in this way
<Calendar
onDayPress={(day) => {this.setDay(day)}}
renderArrow={this._renderArrow}
pastScrollRange={0}
markedDates={{[this.state.selected]: {selected: true, disableTouchEvent: true, selectedColor: '#C7A985'}}}
firstDay={1}
theme={{
selectedDayTextColor: 'white'
}}
/>
and the function as
_renderArrow = (direction) => {
if(direction === 'left') {
return <Text>{this.state.previousMonth}</Text>
} else {
return <Text>{this.state.nextMonth}</Text>
}
}

How to get the selected date in Calendar Picker on react native?

am using react-native-calendar-picker library.trying to get the selected date but i receive previews date.
onDateChange (date) {
this.setState({ date: date });
}
<CalendarPicker selectedDate={this.state.date}
onDateChange=(date)=>this.onDateChange(date)}}/>
I would recommend to use react-native-calendar
You can get it from here : https://github.com/christopherdro/react-native-calendar
Usage Example :
<Calendar
scrollEnabled={true}
showControls={true}
titleFormat={'MMMM YYYY'}
dayHeadings={['Sun', 'Mon', 'Tue', 'Wed', 'Thu','Fri','Sat']}
monthNames={['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']}
prevButtonText={'Prev'}
nextButtonText={'Next'}
onDateSelect={(date) => this.onDateChange(date)}
onTouchPrev={this.onTouchPrev}
onTouchNext={this.onTouchNext}
onSwipePrev={this.onSwipePrev}
onSwipeNext={this.onSwipeNext}
eventDates={this.state.events}
customStyle={{day: {fontSize: 15, textAlign: 'center', color: '#4c4b4b'}}}
weekStart={1}
/>