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

Docs: horizontal swiping #24

Open
MarceloPrado opened this issue Mar 6, 2024 · 7 comments
Open

Docs: horizontal swiping #24

MarceloPrado opened this issue Mar 6, 2024 · 7 comments

Comments

@MarceloPrado
Copy link
Owner

We should have an example demoing how to implement horizontal swipe.

@Acetyld
Copy link

Acetyld commented Mar 18, 2024

Agree, would be lovely! =)

@guyijie1211
Copy link

looking forward to it!!

@kostas64
Copy link

kostas64 commented Aug 5, 2024

Guys, any news about horizontal swipe?
When i try to render an horizontal Calendar.List it disappears from the screen.

@kostas64
Copy link

kostas64 commented Sep 9, 2024

Is it possible to implement horizontal swiping with this library?

@kostas64
Copy link

Finally, after some inspiration from your WindowsXP calendar, i figured out how to build a performant horizontal calendar!

@AndreyBernardoni
Copy link

@kostas64 can you share with us?

@kostas64
Copy link

kostas64 commented Dec 2, 2024

@AndreyBernardoni Sorry mate, never saw your comment.

I dont know if this is the best way to implement the horizontal, it works for me. I tried to extract as much logic as i could from the library it self in order to understand how it works behinds the scenes. In this way you can construct many types of calendars. I have replicated the same logic to build a strip calendar.

First, you have to calculate the calendarMonthId's for the months you want to render the calendar

  import { toDateId } from "@marceloterreiro/flash-calendar";

  const monthsList = useMemo(() => {
    const temp = [];
    for (let i = 0; i <= monthsToRender; i++) {
      const calendarMonthId = toDateId(addMonths(minDate || new Date(), i));
      temp.push(calendarMonthId);
    }
    return temp;
  }, [monthsToRender, minDate]);

Then you have to calculate the data for the calendar

 import { buildCalendar } from "@marceloterreiro/flash-calendar";

 const calendarData = useMemo(
    () =>
      monthsList.map((calendarMonthId) => {
        const { calendarRowMonth, weekDaysList, weeksList } = buildCalendar({
          calendarMonthId,
          calendarFirstDayOfWeek: "monday",
        });

        return {
          calendarRowMonth,
          weekDaysList,
          weeksList,
        };
      }),
    [monthsList],
  );

Render the calendarData to a FlatList or a Flashlist, whatever fits your needs better. In my case FlatList works

     import { CalendarDayMetadata } from "@marceloterreiro/flash-calendar";
     
     type TCalendarItem = {
        calendarRowMonth: string;
        weekDaysList: string[];
        weeksList: CalendarDayMetadata[][];
      };


     const renderItem = ({item}: {item: TCalendarItem}) => {
           return <CalendarMonthItem item={item} otherProps />
     }
     
     return <FlatList
        horizontal
        pagingEnabled
        bounces={false}
        windowSize={3}
        data={calendarData}
        renderItem={renderItem}
        getItemLayout={getItemLayout}
        showsHorizontalScrollIndicator={false}
        {...otherProps}
      />

Last but not least, we have to render the items.

   <View style={{width: WIDTH}}>
        {item.weeksList.map(week, i) => {
              <Calendar.Row.Week 
                  theme={{
                      //play around
                  }}>
                 {week.map((day, nestedI) => {
                  <Calendar.Item.Day.Container 
                    //manyProps to play here
                  >
                      {Your Day Tile component}
                 </Calendar.Item.Day.Container>
                 }}
              </Calendar.Row.Week>
        }}
   </View>

I hope this helps! Apologies for the lengthy response—I wanted to provide enough detail for clarity and avoid leaving anything unclear.

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