Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates period day to disable touch events properly based on Calendar… #2461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/calendar/day/period/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface PeriodDayProps extends ViewProps {
onLongPress?: (date?: DateData) => void;
accessibilityLabel?: string;
testID?: string;
disableAllTouchEventsForDisabledDays?: boolean;
disableAllTouchEventsForInactiveDays?: boolean;
}

type MarkingStyle = {
Expand All @@ -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: {}};

Expand Down Expand Up @@ -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}
>
<View style={style.current.wrapper}>
Expand Down