11import XDate from 'xdate' ;
2- import React , { useCallback , useEffect , useRef , useState , useMemo } from 'react' ;
3- import { View , ScrollViewProps , ScrollView } from 'react-native' ;
2+ import React , { useCallback , useEffect , useRef , useState , useMemo } from 'react' ;
3+ import { View , ScrollViewProps , ScrollView } from 'react-native' ;
44import constants from '../commons/constants' ;
5- import { toMarkingFormat } from '../interface' ;
6- import { extractHeaderProps } from '../componentUpdater' ;
7- import Calendar , { CalendarProps } from '../calendar' ;
5+ import { toMarkingFormat } from '../interface' ;
6+ import { extractHeaderProps } from '../componentUpdater' ;
7+ import Calendar , { CalendarProps } from '../calendar' ;
88import CalendarHeader from '../calendar/header' ;
99import InfiniteList from '../infinite-list' ;
1010import styleConstructor from './style' ;
@@ -24,6 +24,9 @@ export interface CalendarListProps {
2424 calendarProps ?: CalendarProps ;
2525 /** Identifier for testing */
2626 testID ?: string ;
27+ calendarHeight ?: number ;
28+ numberOfPages ?: number ;
29+
2730}
2831
2932const NUMBER_OF_PAGES = 50 ;
@@ -32,9 +35,9 @@ const CALENDAR_HEIGHT = 360;
3235const CalendarList = ( props : CalendarListProps ) => {
3336 const {
3437 initialDate,
35- horizontal,
38+ horizontal,
3639 scrollRange = NUMBER_OF_PAGES ,
37- staticHeader,
40+ staticHeader,
3841 scrollViewProps,
3942 calendarProps,
4043 testID
@@ -45,10 +48,9 @@ const CalendarList = (props: CalendarListProps) => {
4548 const [ positionIndex , setPositionIndex ] = useState ( scrollRange ) ;
4649
4750 /** Static Header */
48-
4951 const [ currentMonth , setCurrentMonth ] = useState ( initialDate || items [ scrollRange ] ) ;
5052 const shouldRenderStaticHeader = staticHeader && horizontal ;
51- const headerProps = extractHeaderProps ( props ) ;
53+ const headerProps = extractHeaderProps ( calendarProps || { } ) ;
5254 const staticHeaderStyle = useMemo ( ( ) => {
5355 return [ style . current . staticHeader , calendarProps ?. headerStyle ] ;
5456 } , [ calendarProps ?. headerStyle ] ) ;
@@ -102,7 +104,7 @@ const CalendarList = (props: CalendarListProps) => {
102104 }
103105 } , [ updateMonth ] ) ;
104106
105- const onPageChange = useCallback ( ( pageIndex : number , _ : number , info : { scrolledByUser : boolean } ) => {
107+ const onPageChange = useCallback ( ( pageIndex : number , _ : number , info : { scrolledByUser : boolean } ) => {
106108 if ( shouldRenderStaticHeader && info . scrolledByUser ) {
107109 setCurrentMonth ( items [ pageIndex ] ) ;
108110 }
@@ -143,7 +145,7 @@ const CalendarList = (props: CalendarListProps) => {
143145 const array : string [ ] = [ ...items ] ;
144146 const startingDate = items [ index ] ;
145147 const shouldAppend = index > scrollRange ;
146-
148+
147149 if ( startingDate ) {
148150 if ( shouldAppend ) {
149151 for ( let i = 2 ; i <= scrollRange ; i ++ ) {
@@ -165,7 +167,7 @@ const CalendarList = (props: CalendarListProps) => {
165167 /** List */
166168
167169 const listContainerStyle = useMemo ( ( ) => {
168- return [ style . current . flatListContainer , { flex : horizontal ? undefined : 1 } ] ;
170+ return [ style . current . flatListContainer , { flex : horizontal ? undefined : 1 } ] ;
169171 } , [ style , horizontal ] ) ;
170172
171173 const scrollProps = useMemo ( ( ) => {
@@ -180,17 +182,16 @@ const CalendarList = (props: CalendarListProps) => {
180182 return (
181183 < Calendar
182184 { ...calendarProps }
183- { ...headerProps }
184185 initialDate = { item }
185186 disableMonthChange
186187 hideArrows = { ! horizontal }
187188 onPressArrowRight = { scrollToNextMonth }
188- onPressArrowLeft = { scrollToPreviousMonth }
189+ onPressArrowLeft = { scrollToPreviousMonth }
189190 hideExtraDays = { calendarProps ?. hideExtraDays || true }
190191 style = { [ style . current . calendar , calendarProps ?. style ] }
191192 headerStyle = { horizontal ? calendarProps ?. headerStyle : undefined }
192- testID = { `${ testID } _${ item } ` }
193- // context={context}
193+ testID = { `${ testID } _${ item } ` }
194+ // context={context}
194195 />
195196 ) ;
196197 } , [ calendarProps , scrollToNextMonth , scrollToPreviousMonth ] ) ;
@@ -203,13 +204,13 @@ const CalendarList = (props: CalendarListProps) => {
203204 data = { items }
204205 renderItem = { renderItem }
205206 reloadPages = { reloadPages }
206- onReachNearEdgeThreshold = { Math . round ( NUMBER_OF_PAGES * 0.4 ) }
207+ onReachNearEdgeThreshold = { props . numberOfPages ?? Math . round ( NUMBER_OF_PAGES * 0.4 ) }
207208 extendedState = { calendarProps ?. markedDates }
208209 isHorizontal = { horizontal }
209210 style = { style . current . container }
210211 initialPageIndex = { scrollRange }
211212 positionIndex = { positionIndex }
212- pageHeight = { CALENDAR_HEIGHT }
213+ pageHeight = { props . calendarHeight ?? CALENDAR_HEIGHT }
213214 pageWidth = { constants . screenWidth }
214215 onPageChange = { onPageChange }
215216 scrollViewProps = { scrollProps }
@@ -224,10 +225,10 @@ export default CalendarList;
224225function getDate ( date : string , index : number ) {
225226 const d = new XDate ( date ) ;
226227 d . addMonths ( index , true ) ;
227-
228+
228229 // if (index !== 0) {
229- d . setDate ( 1 ) ;
230- // }
230+ d . setDate ( 1 ) ;
231+ // }
231232 return toMarkingFormat ( d ) ;
232233}
233234
0 commit comments