BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.
MIT License
939 stars 327 forks source link

is it possible to combine two customdatestyles? #194

Closed Vasault closed 4 years ago

Vasault commented 4 years ago

ok so i got two different approaches i'd like to join, one is a custom list of days i have, that i need to color red, (holidays in my country) plus the weekend, tho my custom list comes from an api which i'm unable to customize, so i'd like to know how to sum both in order to pass it on the customDaysStyle={}

here are both of my approaches

//custom dates setBlackList = () => { for (let i=0; i<this.datesBlacklist.length; i++) { this.customDatesStyle.push({ startDate: this.datesBlacklist[i], dateNameStyle: {color: '#f21927'}, dateNumberStyle: {color: '#f21927'}, dateContainerStyle: {color: '#f21927'}, }); } return this.datesBlacklist; }

//weekends datesBlacklistFunc = date => { return date.isoWeekday() === 6 || date.isoWeekday() === 7; // disable Saturdays }

Vasault commented 4 years ago

btw this is only for coloring custom style, not for disabling days, none of these days will be disabled, just on a different color

peacechen commented 4 years ago

I suggest passing a callback to customDatesStyles. https://github.com/BugiDev/react-native-calendar-strip#customdatesstyles

Your callback can check whether the date is within range and return the appropriate style, as well as whether it's on a weekend and return another style.

Vasault commented 4 years ago

that's exactly what i'm doing with setBlackList, i guess is not the best name for this, the thing is, that one is working well, but i need to add the weekends

peacechen commented 4 years ago

Given the current environment bringing racism to light, it's worth a discussion on whether "blacklist" and "whitelist" are racist terms. I never understood it to be racist but can see how the terminology could be interpreted that way. https://www.quora.com/Is-the-term-blacklist-racist

If there is a good reason and strong support to change the names, I would be happy to do so. We would need to deprecate the current ones to avoid breaking current apps using this library.

peacechen commented 4 years ago

Your customDatesStyles callback would look like this:

  customDatesStylesFunc = date => {
    if (date.isoWeekday() === 6 || date.isoWeekday() === 7) {
        // return weekend style
    }

    const matchedDate = this.datesBlacklist.find(d => date.isSame(d, "day"));
    if (matchedDate) {
        // return matched style
    }
    return {};
  }
Vasault commented 4 years ago

Your customDatesStyles callback would look like this:

  customDatesStylesFunc = date => {
    if (date.isoWeekday() === 6 || date.isoWeekday() === 7) {
        // return weekend style
    }

    const matchedDate = this.datesBlacklist.find(d => date.isSame(d, "day"));
    if (matchedDate) {
        // return matched style
    }
    return {};
  }

wouldn't that just display ONLY one of the options? and not combine them?

Vasault commented 4 years ago

Given the current environment bringing racism to light, it's worth a discussion on whether "blacklist" and "whitelist" are racist terms. I never understood it to be racist but can see how the terminology could be interpreted that way. https://www.quora.com/Is-the-term-blacklist-racist

If there is a good reason and strong support to change the names, I would be happy to do so. We would need to deprecate the current ones to avoid breaking current apps using this library.

i think i misinterpreted myself on that LOL, what i meant to say is that blacklist is for disabled dates, while my function name should be something like customDates instead

Vasault commented 4 years ago

my bad @peacechen it worked, thanks a lot