|
| 1 | +import React, {useRef, useCallback} from 'react'; |
| 2 | +import {StyleSheet, View} from 'react-native'; |
| 3 | +import {ExpandableCalendar, AgendaList, CalendarProvider, WeekCalendar} from 'react-native-calendars'; |
| 4 | +import testIDs from '../testIDs'; |
| 5 | +import {agendaItems, getMarkedDates} from '../mocks/agendaItems'; |
| 6 | +import AgendaItem from '../mocks/AgendaItem'; |
| 7 | +import {getTheme, themeColor, lightThemeColor} from '../mocks/theme'; |
| 8 | + |
| 9 | +const leftArrowIcon = require('../img/previous.png'); |
| 10 | +const rightArrowIcon = require('../img/next.png'); |
| 11 | +const ITEMS: any[] = agendaItems; |
| 12 | + |
| 13 | +interface Props { |
| 14 | + weekView?: boolean; |
| 15 | +} |
| 16 | + |
| 17 | +const AgendaInfiniteListScreen = (props: Props) => { |
| 18 | + const {weekView} = props; |
| 19 | + const marked = useRef(getMarkedDates()); |
| 20 | + const theme = useRef(getTheme()); |
| 21 | + const todayBtnTheme = useRef({ |
| 22 | + todayButtonTextColor: themeColor |
| 23 | + }); |
| 24 | + |
| 25 | + const renderItem = useCallback(({item}: any) => { |
| 26 | + const isLongItem = item.itemCustomHeightType === 'LongEvent'; |
| 27 | + return <View style={{paddingTop: isLongItem ? 40 : 0}}><AgendaItem item={item}/></View>; |
| 28 | + }, []); |
| 29 | + |
| 30 | + return ( |
| 31 | + <CalendarProvider |
| 32 | + date={ITEMS[1]?.title} |
| 33 | + showTodayButton |
| 34 | + theme={todayBtnTheme.current} |
| 35 | + > |
| 36 | + {weekView ? ( |
| 37 | + <WeekCalendar testID={testIDs.weekCalendar.CONTAINER} firstDay={1} markedDates={marked.current}/> |
| 38 | + ) : ( |
| 39 | + <ExpandableCalendar |
| 40 | + testID={testIDs.expandableCalendar.CONTAINER} |
| 41 | + theme={theme.current} |
| 42 | + firstDay={1} |
| 43 | + markedDates={marked.current} |
| 44 | + leftArrowImageSource={leftArrowIcon} |
| 45 | + rightArrowImageSource={rightArrowIcon} |
| 46 | + /> |
| 47 | + )} |
| 48 | + <AgendaList |
| 49 | + sections={ITEMS} |
| 50 | + renderItem={renderItem} |
| 51 | + sectionStyle={styles.section} |
| 52 | + infiniteListProps={ |
| 53 | + { |
| 54 | + itemHeight: 80, |
| 55 | + titleHeight: 50, |
| 56 | + itemHeightByType: { |
| 57 | + LongEvent: 120, |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + /> |
| 62 | + </CalendarProvider> |
| 63 | + ); |
| 64 | +}; |
| 65 | + |
| 66 | +export default AgendaInfiniteListScreen; |
| 67 | + |
| 68 | +const styles = StyleSheet.create({ |
| 69 | + calendar: { |
| 70 | + paddingLeft: 20, |
| 71 | + paddingRight: 20 |
| 72 | + }, |
| 73 | + header: { |
| 74 | + backgroundColor: 'lightgrey' |
| 75 | + }, |
| 76 | + section: { |
| 77 | + backgroundColor: lightThemeColor, |
| 78 | + color: 'grey', |
| 79 | + textTransform: 'capitalize' |
| 80 | + } |
| 81 | +}); |
0 commit comments