BugiDev / react-native-calendar-strip

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

Method getDateNameText() to perform custom format for day name #209

Closed gigby closed 4 years ago

gigby commented 4 years ago

usage

const customNames = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];

const Calendar = () => {
  return (
    <CalendarStrip
      scrollable
      iconContainer={{ flex: 0.1 }}
      getDateNameText={(date) => customNames[new Date(date).getDay()]}
    />
  );
};
peacechen commented 4 years ago

Thanks @gigby for the PR. When I first saw the prop, it sounded like its purpose was for CalendarStrip to return the date name to the caller. It's the other way around -- providing the day of week name to CalendarStrip (e.g. Mon, Tues, etc).

This functionality is provided by using localization. It also enables the caller to configure translations for the month names. https://github.com/BugiDev/react-native-calendar-strip#localization

Is there another use case that isn't covered by localization?

gigby commented 4 years ago

@peacechen Thanks for the quick review! Yee, you are right. This use case has already covered. But, you know, I didn't find this approach because 'localization' means a little bit different thing. It is not clear for first glance why I need to use localization things to perform format output. I seem this library may have "render" props like a "renderDayName(date, ...extra)", "renderDayNumber(date, ...extra)" etc. This will be according react's best practices. This library already has good prop "dayComponent" which covers all I want but I faced with a big problem that such customization will be redundant for most users (bcz I don't want to lose already implemented features like "dots", "lines" etc)

peacechen commented 4 years ago

There are a lot of props and it can be confusing at first glance. Please feel free to submit additional PR's for the code or Readme that would improve extensibility or reusability.