|
1 | 1 | import type {
|
| 2 | + CalendarMonth, |
2 | 3 | CalendarOnDayPress,
|
3 | 4 | CalendarTheme,
|
4 | 5 | } from "@marceloterreiro/flash-calendar";
|
5 | 6 | import { Calendar, toDateId } from "@marceloterreiro/flash-calendar";
|
| 7 | +import type { FlashListProps } from "@shopify/flash-list"; |
6 | 8 | import type { Meta } from "@storybook/react";
|
7 |
| -import React, { useCallback, useMemo, useState } from "react"; |
| 9 | +import { useCallback, useMemo, useState } from "react"; |
8 | 10 | import { Alert, Text, View } from "react-native";
|
9 | 11 | import { useTheme } from "@/hooks/useTheme";
|
| 12 | +import { VStack } from "@/components/VStack"; |
10 | 13 |
|
11 | 14 | const CalendarMeta: Meta<typeof Calendar> = {
|
12 | 15 | title: "Calendar.List/Github Issues",
|
@@ -124,3 +127,34 @@ export const Issue38 = () => {
|
124 | 127 | </View>
|
125 | 128 | );
|
126 | 129 | };
|
| 130 | + |
| 131 | +// See more at: https://github.com/MarceloPrado/flash-calendar/issues/65 |
| 132 | +export const ListenToVisibleMonth = () => { |
| 133 | + const [selectedDate, setSelectedDate] = useState(today); |
| 134 | + const [visibleMonth, setVisibleMonth] = useState(today); |
| 135 | + |
| 136 | + const handleViewableItemsChanged = useCallback< |
| 137 | + NonNullable<FlashListProps<CalendarMonth>["onViewableItemsChanged"]> |
| 138 | + >(({ viewableItems }) => { |
| 139 | + const firstVisibleItem = viewableItems.find((item) => item.isViewable); |
| 140 | + |
| 141 | + if (firstVisibleItem) { |
| 142 | + setVisibleMonth(firstVisibleItem.item.id); |
| 143 | + } |
| 144 | + }, []); |
| 145 | + |
| 146 | + return ( |
| 147 | + <View style={{ flex: 1, gap: 24 }}> |
| 148 | + <View style={{ gap: 12 }}> |
| 149 | + <Text>Selected date: {selectedDate}</Text> |
| 150 | + <Text>Visible month: {visibleMonth}</Text> |
| 151 | + </View> |
| 152 | + <Calendar.List |
| 153 | + calendarActiveDateRanges={[{ startId: today, endId: today }]} |
| 154 | + calendarInitialMonthId="2024-06-01" |
| 155 | + onCalendarDayPress={setSelectedDate} |
| 156 | + onViewableItemsChanged={handleViewableItemsChanged} |
| 157 | + /> |
| 158 | + </View> |
| 159 | + ); |
| 160 | +}; |
0 commit comments