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

Week calendar refactor #1961

Merged
merged 44 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
505caa0
return to master state
yuvalsho Aug 7, 2022
2edf636
week-calendar-refactor
yuvalsho Aug 7, 2022
41d5a44
week-calendar-refactor
yuvalsho Aug 7, 2022
1e123da
week-calendar-refactor
yuvalsho Aug 7, 2022
af073c6
merge from master
yuvalsho Aug 10, 2022
3a74977
merge from master
yuvalsho Aug 10, 2022
69d0f87
PR comments fixes
yuvalsho Aug 10, 2022
d7b095e
add missing import
yuvalsho Aug 10, 2022
ada6ebf
fix build
yuvalsho Aug 10, 2022
3c96a32
merge from master
yuvalsho Aug 14, 2022
f9134e9
WIP
yuvalsho Aug 15, 2022
37e5f0d
merge from master
yuvalsho Aug 15, 2022
0f8e0e2
fix tsc
yuvalsho Aug 15, 2022
d0bc949
WIP:
yuvalsho Aug 16, 2022
e17e9ab
WIP
yuvalsho Aug 17, 2022
47cc50b
improve rendering time
yuvalsho Aug 18, 2022
2b3918c
render multiple weeks in same time
yuvalsho Aug 18, 2022
943c7c7
merge from master
yuvalsho Aug 18, 2022
6729ba8
fix rendering flicker
yuvalsho Aug 18, 2022
55d056d
week-calendar-refactor
yuvalsho Aug 21, 2022
f942667
WIP
yuvalsho Aug 21, 2022
a45fc91
week - fix lagging and issues
yuvalsho Aug 22, 2022
ac06b3b
Merge branch 'master' of github.com:wix/react-native-calendars into w…
yuvalsho Aug 22, 2022
eed0ba4
WIP
yuvalsho Aug 24, 2022
64637ae
WIP
yuvalsho Aug 24, 2022
205f132
merge from master
yuvalsho Aug 24, 2022
25d55da
WIP - handle RTL issues
yuvalsho Aug 24, 2022
a7c6458
WIP
yuvalsho Aug 25, 2022
07ed07d
fix tsc
yuvalsho Aug 25, 2022
923b4df
fix found issues
yuvalsho Aug 25, 2022
f808175
Merge branch 'master' of github.com:wix/react-native-calendars into w…
yuvalsho Aug 25, 2022
2060959
fix bugs and issues with RTL
yuvalsho Aug 25, 2022
8455f08
Merge branch 'master' into week-calendar-refactor
yuvalsho Aug 25, 2022
38e0503
Merge branch 'master' of github.com:wix/react-native-calendars into w…
yuvalsho Sep 6, 2022
7a5048c
PR fixes
yuvalsho Sep 6, 2022
b0cad5a
fix spacings
yuvalsho Sep 6, 2022
1e95f07
bug fixes
yuvalsho Sep 6, 2022
4f3d1fe
PR fixes
yuvalsho Sep 7, 2022
98bd386
Merge branch 'master' of github.com:wix/react-native-calendars into w…
yuvalsho Sep 7, 2022
a5e9670
PR fixes
yuvalsho Sep 7, 2022
3e89745
fix tests
yuvalsho Sep 7, 2022
203cec1
PR fix
yuvalsho Sep 12, 2022
c8c09a8
PR fix
yuvalsho Sep 12, 2022
2e718a1
merge from master
yuvalsho Sep 18, 2022
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ An advanced `Agenda` component that can display interactive listings for calenda
return <View />;
}}
// Override inner list with a custom implemented component
renderList={(listProps) => {
return <MyCustomList {...listProps} />
renderList={listProps => {
return <MyCustomList {...listProps} />;
}}
// Specify what should be rendered instead of ActivityIndicator
renderEmptyData={() => {
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/calendarListScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const CalendarListScreen = (props: Props) => {
}
};
}, [selected]);

const onDayPress = useCallback((day: DateData) => {
setSelected(day.dateString);
}, []);
Expand Down
8 changes: 4 additions & 4 deletions example/src/screens/calendarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ const CalendarScreen = () => {
},
[getNewSelectedDate]
);

const onPressArrowRight = useCallback(
(add, month) => {
const newDate = getNewSelectedDate(month, true);
Expand Down Expand Up @@ -445,7 +445,7 @@ const CalendarScreen = () => {
const renderCalendarWithCustomHeader = () => {
const CustomHeader = React.forwardRef((props, ref) => {
customHeaderProps.current = props;

return (
// @ts-expect-error
<View ref={ref} {...props} style={styles.customHeader}>
Expand Down Expand Up @@ -565,8 +565,8 @@ const styles = StyleSheet.create({
padding: 8
},
customTitleContainer: {
flexDirection: 'row',
alignItems: 'center',
flexDirection: 'row',
alignItems: 'center',
padding: 10
},
customTitle: {
Expand Down
12 changes: 6 additions & 6 deletions src/agenda/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class Agenda extends Component<AgendaProps, State> {

componentDidUpdate(prevProps: AgendaProps, prevState: State) {
const newSelectedDate = this.getSelectedDate(this.props.selected);

if (!sameDate(newSelectedDate, prevState.selectedDay)) {
const prevSelectedDate = this.getSelectedDate(prevProps.selected);
if (!sameDate(newSelectedDate, prevSelectedDate)) {
Expand Down Expand Up @@ -188,7 +188,7 @@ export default class Agenda extends Component<AgendaProps, State> {

enableCalendarScrolling(enable = true) {
this.setState({calendarScrollable: enable});

this.props.onCalendarToggled?.(enable);

// Enlarge calendarOffset here as a workaround on iOS to force repaint.
Expand Down Expand Up @@ -325,7 +325,7 @@ export default class Agenda extends Component<AgendaProps, State> {
onDayChange = (day: XDate) => {
const withAnimation = sameMonth(day, this.state.selectedDay);
this.calendar?.current?.scrollToDay(day, this.calendarOffset(), withAnimation);

this.setState({selectedDay: day});

this.props.onDayChange?.(xdateToData(day));
Expand Down Expand Up @@ -391,9 +391,9 @@ export default class Agenda extends Component<AgendaProps, State> {

renderWeekDaysNames = () => {
return (
<WeekDaysNames
firstDay={this.props.firstDay}
style={this.style.dayHeader}
<WeekDaysNames
firstDay={this.props.firstDay}
style={this.style.dayHeader}
/>
);
};
Expand Down
16 changes: 8 additions & 8 deletions src/calendar-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
onEndReachedThreshold,
onEndReached
} = props;

const calendarProps = extractCalendarProps(props);
const headerProps = extractHeaderProps(props);
const calendarSize = horizontal ? calendarWidth : calendarHeight;
Expand Down Expand Up @@ -133,8 +133,8 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
}, [propsStyle]);

const initialDateIndex = useMemo(() => {
return findIndex(items, function(item) {
return item.toString() === initialDate.current?.toString();
return findIndex(items, function(item) {
return item.toString() === initialDate.current?.toString();
});
}, [items]);

Expand Down Expand Up @@ -177,7 +177,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
const scrollTo = parseDate(date);
const diffMonths = Math.round(initialDate?.current?.clone().setDate(1).diffMonths(scrollTo?.clone().setDate(1)));
const scrollAmount = calendarSize * pastScrollRange + diffMonths * calendarSize;

if (scrollAmount !== 0) {
// @ts-expect-error
list?.current?.scrollToOffset({offset: scrollAmount, animated: animateScroll});
Expand All @@ -193,8 +193,8 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
setCurrentMonth(day);
}, [currentMonth, scrollToMonth]);

const getMarkedDatesForItem = useCallback((item?: XDate) => {
if (markedDates && item) {
const getMarkedDatesForItem = useCallback((item?: XDate) => {
if (markedDates && item) {
for (const [key, _] of Object.entries(markedDates)) {
if (sameMonth(new XDate(key), new XDate(item))) {
return markedDates;
Expand Down Expand Up @@ -270,7 +270,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
}, []);

const viewabilityConfigCallbackPairs = useRef([
{
{
viewabilityConfig: viewabilityConfig.current,
onViewableItemsChanged
},
Expand All @@ -288,7 +288,7 @@ const CalendarList = (props: CalendarListProps, ref: any) => {
renderItem={renderItem}
getItemLayout={getItemLayout}
initialNumToRender={range.current}
initialScrollIndex={initialDateIndex}
initialScrollIndex={initialDateIndex}
viewabilityConfigCallbackPairs={viewabilityConfigCallbackPairs.current}
testID={testID}
onLayout={onLayout}
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/day/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function areEqual(prevProps: DayProps, nextProps: DayProps) {
const nextPropsWithoutMarkDates = omit(nextProps, 'marking');
const didPropsChange = some(prevPropsWithoutMarkDates, function(value, key) {
//@ts-expect-error
return value !== nextPropsWithoutMarkDates[key];
return value !== nextPropsWithoutMarkDates[key];
});
const isMarkingEqual = isEqual(prevProps.marking, nextProps.marking);
return !didPropsChange && isMarkingEqual;
Expand Down Expand Up @@ -69,7 +69,7 @@ const Day = React.memo((props: DayProps) => {

return `${_isToday ? today : ''} ${_date?.toString(formatAccessibilityLabel)} ${markingAccessibilityLabel}`;
}, [_date, marking, _isToday]);

const Component = dayComponent || (markingType === 'period' ? PeriodDay : BasicDay);
const dayComponentProps = dayComponent ? {date: xdateToData(date || new XDate())} : undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const Calendar = (props: CalendarProps) => {
const style = useRef(styleConstructor(theme));
const header = useRef();
const weekNumberMarking = useRef({disabled: true, disableTouchEvent: true});

useEffect(() => {
if (initialDate) {
setCurrentMonth(parseDate(initialDate));
Expand Down Expand Up @@ -258,7 +258,7 @@ const Calendar = (props: CalendarProps) => {
const ref = customHeader ? undefined : header;
const CustomHeader = customHeader;
const HeaderComponent = customHeader ? CustomHeader : CalendarHeader;

return (
<HeaderComponent
{...headerProps}
Expand Down
5 changes: 3 additions & 2 deletions src/day-state-manager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {DayState} from './types';
const {isToday, isDateNotInRange, sameMonth} = require('./dateutils');
const {toMarkingFormat} = require('./interface');


export function getState(day: XDate, current: XDate, props: any) {
export function getState(day: XDate, current: XDate, props: any): DayState {
yuvalsho marked this conversation as resolved.
Show resolved Hide resolved
const {minDate, maxDate, disabledByDefault, context} = props;
let state = '';
let state: DayState = '';

if (context?.date === toMarkingFormat(day)) {
state = 'selected';
Expand Down