Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added renderDay #375

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
51 changes: 37 additions & 14 deletions CalendarPicker/Day.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { memo } from 'react';
import {
View,
Text,
Expand All @@ -13,6 +13,14 @@ import { isSameDay } from 'date-fns/isSameDay';
import { isWithinInterval } from 'date-fns/isWithinInterval';
import { startOfDay } from 'date-fns/startOfDay';

const DayComponent = memo(({ style, year, month, date, day, renderDay }) => {
if (renderDay) {
return renderDay({ year, month, day, date, style });
}

return <Text style={style}>{day}</Text>;
});

export default function Day(props) {
const {
day,
Expand Down Expand Up @@ -42,6 +50,7 @@ export default function Day(props) {
minRangeDuration,
maxRangeDuration,
enableDateChange,
renderDay,
} = props;

const thisDay = new Date(year, month, day, 12);
Expand Down Expand Up @@ -193,13 +202,17 @@ export default function Day(props) {
return (
<View style={[styles.dayWrapper, custom.containerStyle]}>
<View style={[custom.style, computedSelectedDayStyle, selectedDayStyle]}>
<Text style={[styles.dayLabel, textStyle,
styles.disabledText, disabledDatesTextStyle,
styles.selectedDisabledText, selectedDisabledDatesTextStyle,
overrideOutOfRangeTextStyle
]}>
{day}
</Text>
<DayComponent style={[styles.dayLabel, textStyle,
styles.disabledText, disabledDatesTextStyle,
styles.selectedDisabledText, selectedDisabledDatesTextStyle,
overrideOutOfRangeTextStyle,
]}
day={day}
year={year}
month={month}
date={thisDay}
andrewmcd1 marked this conversation as resolved.
Show resolved Hide resolved
renderDay={renderDay}
/>
</View>
</View>
);
Expand All @@ -210,9 +223,14 @@ export default function Day(props) {
disabled={!enableDateChange}
style={[custom.style, computedSelectedDayStyle, selectedDayStyle]}
onPress={() => onPressDay({ year, month, day })}>
<Text style={[styles.dayLabel, textStyle, custom.textStyle, selectedDayTextStyle]}>
{day}
</Text>
<DayComponent
style={[styles.dayLabel, textStyle, custom.textStyle, selectedDayTextStyle]}
day={day}
year={year}
month={month}
date={thisDay}
renderDay={renderDay}
/>
</TouchableOpacity>
</View>
);
Expand All @@ -229,9 +247,14 @@ export default function Day(props) {
return (
<View style={[styles.dayWrapper, custom.containerStyle]}>
<View style={[styles.dayButton, custom.style]}>
<Text style={[textStyle, styles.disabledText, disabledDatesTextStyle, custom.textStyle]}>
{day}
</Text>
<DayComponent
style={[textStyle, styles.disabledText, disabledDatesTextStyle, custom.textStyle]}
day={day}
year={year}
month={month}
date={thisDay}
renderDay={renderDay}
/>
</View>
</View>
);
Expand Down
1 change: 1 addition & 0 deletions CalendarPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ export default class CalendarPicker extends Component {
selectedRangeEndStyle: this.props.selectedRangeEndStyle,
customDatesStyles: this.props.customDatesStyles,
fontScaling: this.props.fontScaling,
renderDay: this.props.renderDay,
};
}

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ const styles = StyleSheet.create({
| **`headerWrapperStyle`** | `ViewStyle` | Optional. Style for entire header controls wrapper. This contains the previous / next controls plus month & year. |
| **`monthTitleStyle`** | `TextStyle` | Optional. Text styling for header's month text. |
| **`yearTitleStyle`** | `TextStyle` | Optional. Text styling for header's year text. |
| **`initialView`** | `String` | Optional. The view that the calendar opens to. Default is `days`. Available options are `years`, `months`, and `days`. |
| **`fontScaling`** | `Boolean` | Optional. To enable fontScaling. Default is `true` |
| **`initialView`** | `String` | Optional. The view that the calendar opens to. Default is `days`. Available options are `years`, `months`, and `days`.
| **`renderDay`** | `Function` | Optional. Allows customization of day rendering by accepting a custom render prop that receives `{date: Date/DateFn, day: number, month: number, year: number, style: TextStyle}` and returns JSX Element. |
| **`fontScaling`** | `Boolean` | Optional. To enable fontScaling. Default is `true`
|

# Styles

Expand Down