-
Notifications
You must be signed in to change notification settings - Fork 31
/
PerfTestCalendarList.stories.tsx
114 lines (103 loc) · 3.23 KB
/
PerfTestCalendarList.stories.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {
Calendar,
toDateId,
useDateRange,
} from "@marceloterreiro/flash-calendar";
import type { Meta } from "@storybook/react";
import { addDays, startOfMonth } from "date-fns";
import { useState } from "react";
import { View, StyleSheet, Text } from "react-native";
import { paddingDecorator } from "@/developer/decorators";
import { PerfTestCalendar } from "./PerfTestCalendar";
const PerfTestCalendarMeta: Meta<typeof PerfTestCalendar> = {
title: "Performance Test/Calendar.List",
component: PerfTestCalendar,
decorators: [paddingDecorator],
};
export default PerfTestCalendarMeta;
const startOfThisMonth = startOfMonth(new Date());
export const DatePicker = () => {
const [activeDateId, setActiveDateId] = useState<string | undefined>(
toDateId(addDays(startOfThisMonth, 3))
);
return (
<Calendar.List
calendarActiveDateRanges={[
{ startId: activeDateId, endId: activeDateId },
]}
calendarDayHeight={48}
calendarInitialMonthId={toDateId(startOfThisMonth)}
calendarSpacing={20}
onCalendarDayPress={setActiveDateId}
renderItem={({ item }) => (
<View style={{ paddingBottom: 20 }}>
<PerfTestCalendar calendarMonthId={item.id} {...item.calendarProps} />
</View>
)}
/>
);
};
export const DateRangePicker = () => {
const { calendarActiveDateRanges, onCalendarDayPress } = useDateRange({
startId: toDateId(addDays(startOfThisMonth, 3)),
endId: toDateId(addDays(startOfThisMonth, 8)),
});
return (
<Calendar.List
calendarActiveDateRanges={calendarActiveDateRanges}
calendarDayHeight={48}
calendarInitialMonthId={toDateId(startOfThisMonth)}
calendarSpacing={20}
onCalendarDayPress={onCalendarDayPress}
renderItem={({ item }) => (
<View style={{ paddingBottom: 20 }}>
<PerfTestCalendar calendarMonthId={item.id} {...item.calendarProps} />
</View>
)}
/>
);
};
export const LenghtyDateRangePicker = () => {
const { calendarActiveDateRanges, onCalendarDayPress } = useDateRange({
startId: toDateId(addDays(startOfThisMonth, 3)),
endId: toDateId(addDays(startOfThisMonth, 8)),
});
return (
<View style={styles.container}>
<Text style={styles.text}>
This renders a list of 2.000 calendars at once, to stress-test
Calendar.List's performance.
</Text>
<View style={{ flex: 1, width: "100%" }}>
<Calendar.List
calendarActiveDateRanges={calendarActiveDateRanges}
calendarDayHeight={48}
calendarFutureScrollRangeInMonths={999}
calendarInitialMonthId={toDateId(startOfThisMonth)}
calendarPastScrollRangeInMonths={1000}
calendarSpacing={20}
onCalendarDayPress={onCalendarDayPress}
renderItem={({ item }) => (
<View style={{ paddingBottom: 20 }}>
<PerfTestCalendar
calendarMonthId={item.id}
{...item.calendarProps}
/>
</View>
)}
/>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
text: {
fontWeight: "bold",
},
});