Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-calendars",
"version": "1.22.0",
"name": "@unifyapps/react-native-calendars",
"version": "1.22.0-ua",
"main": "src/index.ts",
"types": "src/index.d.ts",
"description": "React Native Calendar Components",
Expand Down Expand Up @@ -79,6 +79,8 @@
"lint-staged": "^10.2.11",
"metro-react-native-babel-preset": "0.73.7",
"mocha": "^7.1.0",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "2.8.8",
"prettier-eslint": "^16.3.0",
"react": "18.2.0",
Expand Down
10,752 changes: 10,752 additions & 0 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

144 changes: 44 additions & 100 deletions src/calendar/day/basic/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {Fragment, useCallback, useRef} from 'react';
import {TouchableOpacity, Text, View, ViewProps} from 'react-native';
import {xdateToData} from '../../../interface';
import {Theme, DayState, MarkingTypes, DateData} from '../../../types';
import Marking, {MarkingProps} from '../marking';
import React, { Fragment, useCallback, useRef } from 'react';
import { TouchableOpacity, Text, View, ViewProps } from 'react-native';
import { xdateToData } from '../../../interface';
import { Theme, DayState, MarkingTypes, DateData } from '../../../types';
import Marking, { MarkingProps } from '../marking';
import styleConstructor from './style';


Expand Down Expand Up @@ -31,24 +31,10 @@ export interface BasicDayProps extends ViewProps {
testID?: string;
}

const BasicDay = (props: BasicDayProps) => {
const {
theme,
date,
onPress,
onLongPress,
markingType,
marking,
state,
disableAllTouchEventsForDisabledDays,
disableAllTouchEventsForInactiveDays,
accessibilityLabel,
children,
testID
} = props;
const BasicDay = (props) => {
const { theme, date, onPress, onLongPress, markingType, marking, state, disableAllTouchEventsForDisabledDays, disableAllTouchEventsForInactiveDays, accessibilityLabel, children, testID } = props;
const dateData = date ? xdateToData(date) : undefined;
const style = useRef(styleConstructor(theme));

const _marking = marking || {};
const isSelected = _marking.selected || state === 'selected';
const isDisabled = typeof _marking.disabled !== 'undefined' ? _marking.disabled : state === 'disabled';
Expand All @@ -57,143 +43,101 @@ const BasicDay = (props: BasicDayProps) => {
const isMultiDot = markingType === Marking.markings.MULTI_DOT;
const isMultiPeriod = markingType === Marking.markings.MULTI_PERIOD;
const isCustom = markingType === Marking.markings.CUSTOM;

const shouldDisableTouchEvent = () => {
const {disableTouchEvent} = _marking;
const { disableTouchEvent } = _marking;
let disableTouch = false;

if (typeof disableTouchEvent === 'boolean') {
disableTouch = disableTouchEvent;
} else if (typeof disableAllTouchEventsForDisabledDays === 'boolean' && isDisabled) {
}
else if (typeof disableAllTouchEventsForDisabledDays === 'boolean' && isDisabled) {
disableTouch = disableAllTouchEventsForDisabledDays;
} else if (typeof disableAllTouchEventsForInactiveDays === 'boolean' && isInactive) {
}
else if (typeof disableAllTouchEventsForInactiveDays === 'boolean' && isInactive) {
disableTouch = disableAllTouchEventsForInactiveDays;
}
return disableTouch;
};

const getContainerStyle = () => {
const {customStyles, selectedColor} = _marking;
const { customStyles, selectedColor } = _marking;
const styles = [style.current.base];

if (isSelected) {
styles.push(style.current.selected);
if (selectedColor) {
styles.push({backgroundColor: selectedColor});
styles.push({ backgroundColor: selectedColor });
}
} else if (isToday) {
}
else if (isToday) {
styles.push(style.current.today);
}

//Custom marking type
if (isCustom && customStyles && customStyles.container) {
if (customStyles.container.borderRadius === undefined) {
customStyles.container.borderRadius = 16;
}
styles.push(customStyles.container);
}

return styles;
};

const getTextStyle = () => {
const {customStyles, selectedTextColor} = _marking;
const { customStyles, selectedTextColor } = _marking;
const styles = [style.current.text];

if (isSelected) {
styles.push(style.current.selectedText);
if (selectedTextColor) {
styles.push({color: selectedTextColor});
styles.push({ color: selectedTextColor });
}
} else if (isDisabled) {
}
else if (isDisabled) {
styles.push(style.current.disabledText);
} else if (isToday) {
}
else if (isToday) {
styles.push(style.current.todayText);
} else if (isInactive) {
}
else if (isInactive) {
styles.push(style.current.inactiveText);
}

// Custom marking type
if (isCustom && customStyles && customStyles.text) {
styles.push(customStyles.text);
}

return styles;
};

const _onPress = useCallback(() => {
onPress?.(dateData);
}, [onPress, date]);

const _onLongPress = useCallback(() => {
onLongPress?.(dateData);
}, [onLongPress, date]);

const renderMarking = () => {
const {marked, dotColor, dots, periods} = _marking;

return (
<Marking
type={markingType}
theme={theme}
marked={isMultiDot ? true : marked}
selected={isSelected}
disabled={isDisabled}
inactive={isInactive}
today={isToday}
dotColor={dotColor}
dots={dots}
periods={periods}
/>
);
const { marked, dotColor, dots, periods } = _marking;
// if marking is not set or is multi dot, return null
// we are doing this as it takes the space in bottom of day making text move upwards.
if (!marked || isMultiDot) return null;
return (<Marking type={markingType} theme={theme} marked={isMultiDot ? true : marked} selected={isSelected} disabled={isDisabled} inactive={isInactive} today={isToday} dotColor={dotColor} dots={dots} periods={periods} />);
};

const renderText = () => {
return (
<Text allowFontScaling={false} style={getTextStyle()} testID={`${testID}.text`}>
{String(children)}
</Text>
);
return (<Text allowFontScaling={false} style={getTextStyle()} testID={`${testID}.text`}>
{String(children)}
</Text>);
};

const renderContent = () => {
return (
<Fragment>
{renderText()}
{renderMarking()}
</Fragment>
);
return (<Fragment>
{renderText()}
{renderMarking()}
</Fragment>);
};

const renderContainer = () => {
const {activeOpacity} = _marking;

return (
<TouchableOpacity
testID={testID}
style={getContainerStyle()}
activeOpacity={activeOpacity}
disabled={shouldDisableTouchEvent()}
onPress={!shouldDisableTouchEvent() ? _onPress : undefined}
onLongPress={!shouldDisableTouchEvent() ? _onLongPress : undefined}
accessible
accessibilityRole={isDisabled ? undefined : 'button'}
accessibilityLabel={accessibilityLabel}
>
{isMultiPeriod ? renderText() : renderContent()}
</TouchableOpacity>
);
const { activeOpacity } = _marking;
return (<TouchableOpacity testID={testID} style={getContainerStyle()} activeOpacity={activeOpacity} disabled={shouldDisableTouchEvent()} onPress={!shouldDisableTouchEvent() ? _onPress : undefined} onLongPress={!shouldDisableTouchEvent() ? _onLongPress : undefined} accessible accessibilityRole={isDisabled ? undefined : 'button'} accessibilityLabel={accessibilityLabel}>
{isMultiPeriod ? renderText() : renderContent()}
</TouchableOpacity>);
};

const renderPeriodsContainer = () => {
return (
<View style={style.current.container}>
{renderContainer()}
{renderMarking()}
</View>
);
return (<View style={style.current.container}>
{renderContainer()}
{renderMarking()}
</View>);
};

return isMultiPeriod ? renderPeriodsContainer() : renderContainer();
};

Expand Down
Loading