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

Support for custom CalendarHeader #745

Closed
varunon9 opened this issue Feb 22, 2019 · 5 comments
Closed

Support for custom CalendarHeader #745

varunon9 opened this issue Feb 22, 2019 · 5 comments

Comments

@varunon9
Copy link

Description

Feature Request-

We should be able to implement our own Calendar Header, e.g. I want both navigation arrows to be on right side and Today's date in left side.

image

Expected Behavior

It should support custom header.

Observed Behavior

Right now there is no support for custom header.

varunon9 pushed a commit to varunon9/react-native-toggle-calendar that referenced this issue Feb 22, 2019
@IronTony
Copy link

@varunon9 hi, the numbers under the date are a custom mod of this package?

@varunon9
Copy link
Author

That is custom Day component dayComponent={CalendarDayComponent}
If you are interested in implementing something like above mock, read the story here-
https://medium.com/@varunon9/how-i-built-horizontal-as-well-as-grid-calendar-in-react-native-using-react-native-calendars-eb7a2edcc5db

@IronTony
Copy link

you are the man. thank you so much for the answer and the tutorial

@chenei chenei closed this as completed Jun 12, 2020
@hernanif1
Copy link

hernanif1 commented Sep 13, 2023

The way I found of achieving it:

// inside the theme property
'stylesheet.calendar.header': {
      headerContainer: {
        backgroundColor: 'orange',
        position: 'absolute',
        flexDirection: 'row',
        left: 0,
        gap: 20,  // because of the loader spinner 'displayLoadingIndicator' if its active 
      },
      header: {
        backgroundColor: 'purple', 
        flexDirection: 'row',
        justifyContent: 'flex-end',
        paddingLeft: 10,
        paddingRight: 10,
        marginTop: 6,
        alignItems: 'center',
      },
    },

this will make your component header to look like as this:
Screenshot 2023-09-13 at 11 38 12

But, the right arrows will be on top of the left arrow because of the hitslop.
Since the arrow has a touchable component around it, and it doesn't accept a gap, the only way I found was adding a custom icon with some margin/padding:

      <Calendar
        renderArrow={direction =>
          direction === 'right' ? (
            <ScheduleArrow direction="right" />
          ) : (
            <ScheduleArrow direction="left" className="mr-10" />
          )
        }
        ...
Screenshot 2023-09-13 at 11 40 33

Now it works correctly in my case:

// lib version 
"react-native-calendars": "^1.1300.0",

If you are using typescript:
I also had to add a workaround in TS

type HeaderStyleSheet = {
    'stylesheet.calendar.header': Record<
      'headerContainer' | 'header',
      ViewStyle
    >;
  };
  const themeDark: CalendarProps['theme'] & HeaderStyleSheet = {
    calendarBackground: tailwindColors.zinc[900],
    arrowColor: tailwindColors.white,
    dayTextColor: tailwindColors.white,
    textDisabledColor: tailwindColors.zinc[600],
    textSectionTitleColor: tailwindColors.gray[500],
    selectedDayBackgroundColor: tailwindColors.indigo[500],
    selectedDayTextColor: tailwindColors.white,
    textDayFontFamily: 'Roboto',
    textMonthFontFamily: 'Roboto',
    textDayHeaderFontFamily: 'Roboto',
    textDayFontWeight: 'bold',
    textMonthFontWeight: 'bold',
    textDayHeaderFontWeight: 'bold',
    monthTextColor: tailwindColors.white,
    todayTextColor: tailwindColors.indigo[400],
    dotColor: tailwindColors.indigo[600],
    'stylesheet.calendar.header': {
      headerContainer: {
        position: 'absolute',
        flexDirection: 'row',
        left: 0,
        gap: 20,
      },
      header: {
        flexDirection: 'row',
        justifyContent: 'flex-end',  
        paddingLeft: 10,
        paddingRight: 10,
        marginTop: 6,
        alignItems: 'center',
      },
    },
  };
  

@thundron
Copy link

@hernanif1 I tried your solution but absolutely nothing happens, I'm not sure why - version is v1.1301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants