11import PropTypes from 'prop-types' ;
22import XDate from 'xdate' ;
3- import memoize from 'memoize-one' ;
43
54import React , { useRef , useState , useEffect , useCallback } from 'react' ;
65import { View , ViewStyle , StyleProp } from 'react-native' ;
@@ -113,9 +112,7 @@ const Calendar = (props: CalendarProps) => {
113112 const max = parseDate ( maxDate ) ;
114113
115114 if ( allowSelectionOutOfRange || ! ( min && ! isGTE ( day , min ) ) && ! ( max && ! isLTE ( day , max ) ) ) {
116- const shouldUpdateMonth = disableMonthChange === undefined || ! disableMonthChange ;
117-
118- if ( shouldUpdateMonth ) {
115+ if ( ! disableMonthChange ) {
119116 updateMonth ( day ) ;
120117 }
121118 if ( interaction ) {
@@ -124,17 +121,27 @@ const Calendar = (props: CalendarProps) => {
124121 }
125122 } ;
126123
127- const pressDay = useCallback ( ( date ?: DateData ) => {
124+ const onPressDay = useCallback ( ( date ?: DateData ) => {
128125 if ( date )
129126 handleDayInteraction ( date , onDayPress ) ;
130- } , [ onDayPress ] ) ;
127+ } , [ ] ) ;
131128
132- const longPressDay = useCallback ( ( date ?: DateData ) => {
129+ const onLongPressDay = useCallback ( ( date ?: DateData ) => {
133130 if ( date )
134131 handleDayInteraction ( date , onDayLongPress ) ;
135- } , [ onDayLongPress ] ) ;
132+ } , [ ] ) ;
136133
137- const onSwipe = ( gestureName : string ) => {
134+ const onSwipeLeft = useCallback ( ( ) => {
135+ // @ts -expect-error
136+ header . current ?. onPressRight ( ) ;
137+ } , [ header ] ) ;
138+
139+ const onSwipeRight = useCallback ( ( ) => {
140+ // @ts -expect-error
141+ header . current ?. onPressLeft ( ) ;
142+ } , [ header ] ) ;
143+
144+ const onSwipe = useCallback ( ( gestureName : string ) => {
138145 const { SWIPE_UP , SWIPE_DOWN , SWIPE_LEFT , SWIPE_RIGHT } = swipeDirections ;
139146
140147 switch ( gestureName ) {
@@ -148,19 +155,9 @@ const Calendar = (props: CalendarProps) => {
148155 onSwipeRight ( ) ;
149156 break ;
150157 }
151- } ;
152-
153- const onSwipeLeft = ( ) => {
154- // @ts -expect-error
155- header . current ?. onPressRight ( ) ;
156- } ;
158+ } , [ onSwipeLeft , onSwipeRight ] ) ;
157159
158- const onSwipeRight = ( ) => {
159- // @ts -expect-error
160- header . current ?. onPressLeft ( ) ;
161- } ;
162-
163- const renderWeekNumber = memoize ( weekNumber => {
160+ const renderWeekNumber = ( weekNumber : number ) => {
164161 return (
165162 < View style = { style . current . dayContainer } key = { `week-container-${ weekNumber } ` } >
166163 < BasicDay
@@ -174,7 +171,7 @@ const Calendar = (props: CalendarProps) => {
174171 </ BasicDay >
175172 </ View >
176173 ) ;
177- } ) ;
174+ } ;
178175
179176 const renderDay = ( day : XDate , id : number ) => {
180177 const dayProps = extractComponentProps ( Day , props ) ;
@@ -190,8 +187,8 @@ const Calendar = (props: CalendarProps) => {
190187 date = { toMarkingFormat ( day ) }
191188 state = { getState ( day , currentMonth , props ) }
192189 marking = { markedDates ?. [ toMarkingFormat ( day ) ] }
193- onPress = { pressDay }
194- onLongPress = { longPressDay }
190+ onPress = { onPressDay }
191+ onLongPress = { onLongPressDay }
195192 />
196193 </ View >
197194 ) ;
@@ -256,7 +253,9 @@ const Calendar = (props: CalendarProps) => {
256253 } ;
257254
258255 const GestureComponent = enableSwipeMonths ? GestureRecognizer : View ;
259- const swipeProps = { onSwipe : ( direction : string ) => onSwipe ( direction ) } ;
256+ const swipeProps = {
257+ onSwipe : ( direction : string ) => onSwipe ( direction )
258+ } ;
260259 const gestureProps = enableSwipeMonths ? swipeProps : undefined ;
261260
262261 return (
0 commit comments