From fd869ec47812f313b3b8ba587c9209db94277c8e Mon Sep 17 00:00:00 2001 From: Jack Gill Date: Fri, 3 May 2024 14:59:51 +0100 Subject: [PATCH] Updates period day to disable touch events properly based on Calendar props. Takes the same approach as basic day with it's 'shouldDisableTouchEvent' function. --- src/calendar/day/period/index.tsx | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/calendar/day/period/index.tsx b/src/calendar/day/period/index.tsx index 0b2b216278..9de4280649 100644 --- a/src/calendar/day/period/index.tsx +++ b/src/calendar/day/period/index.tsx @@ -18,6 +18,8 @@ export interface PeriodDayProps extends ViewProps { onLongPress?: (date?: DateData) => void; accessibilityLabel?: string; testID?: string; + disableAllTouchEventsForDisabledDays?: boolean; + disableAllTouchEventsForInactiveDays?: boolean; } type MarkingStyle = { @@ -29,10 +31,26 @@ type MarkingStyle = { } const PeriodDay = (props: PeriodDayProps) => { - const {theme, marking, date, onPress, onLongPress, state, accessibilityLabel, testID, children} = props; + const {theme, marking, date, onPress, onLongPress, state, disableAllTouchEventsForDisabledDays, disableAllTouchEventsForInactiveDays, accessibilityLabel, testID, children} = props; + const _marking = marking || {}; + const {disableTouchEvent, disabled, inactive} = _marking; const dateData = date ? xdateToData(date) : undefined; const style = useRef(styleConstructor(theme)); + const touchEventIsDisabled = useMemo(() => { + let disableTouch = false; + const isDisabled = typeof disabled !== 'undefined' ? disabled : state === 'disabled'; + const isInactive = inactive; + if (typeof disableAllTouchEventsForDisabledDays === 'boolean' && isDisabled) { + disableTouch = disableAllTouchEventsForDisabledDays; + } else if (typeof disableAllTouchEventsForInactiveDays === 'boolean' && isInactive) { + disableTouch = disableAllTouchEventsForInactiveDays; + } else if(typeof disableTouchEvent === 'boolean') { + disableTouch = disableTouchEvent; + } + return disableTouch; + }, [inactive, disabled, disableTouchEvent, disableAllTouchEventsForDisabledDays, disableAllTouchEventsForInactiveDays ]); + const markingStyle = useMemo(() => { const defaultStyle: MarkingStyle = {textStyle: {}, containerStyle: {}}; @@ -166,9 +184,9 @@ const PeriodDay = (props: PeriodDayProps) => { testID={testID} onPress={_onPress} onLongPress={_onLongPress} - disabled={marking?.disableTouchEvent} + disabled={touchEventIsDisabled} accessible - accessibilityRole={marking?.disableTouchEvent ? undefined : 'button'} + accessibilityRole={touchEventIsDisabled ? undefined : 'button'} accessibilityLabel={accessibilityLabel} >