Skip to content

Commit 8826ec4

Browse files
committed
Merge branches 'feat/Calendar_initialDate' and 'master' of github.com:wix/react-native-calendars into feat/Calendar_initialDate
# Conflicts: # src/calendar/index.tsx
2 parents dc40453 + 9a6bc36 commit 8826ec4

37 files changed

+289
-203
lines changed

CHANGELOG.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,14 +759,35 @@
759759
- CalendarConsumer - fix passed ref (PR #1674).
760760
- Agenda - fix style Typo (animatedContainer -> animatedContainer) (PR #1670).
761761

762-
## changed
762+
## Changed
763763
- Migrating internal tools to TS.
764764
- Migrating demo files to TS.
765765

766766
## [1.1270.0] - 2021-11-29
767767
- testIDs - reverting to js file with module.exports.
768768

769-
## [1.1271.0] - 2021-xx-xx
769+
## [1.1271.0] - 2021-12-7
770770

771771
## Fixed
772-
- ContextProvider - 'onDateChanged' return type.
772+
- ContextProvider - 'onDateChanged' return type (should be 'string' and not 'Date').
773+
774+
775+
## [1.1272.0] - xx-xx-xx
776+
777+
## Added
778+
- ExpandableCalendar - Add 'closeOnDayPress' prop (PR #1673).
779+
- new theme prop - 'weekVerticalMargin' to control week row margin (PR #1682).
780+
781+
## Fixed
782+
- README - 'try it out' section missing steps (PR #1624).
783+
- Day - fix accessibility label localization (PR #1694).
784+
- Agenda - renders only for the first item of the day (PR #1699).
785+
- ExpandableCalendar - Only hide extra days when vertical and open (PR #1705).
786+
- ts configuration.
787+
788+
## Changed
789+
- Replacing lodash 'invoke' with optional chaining.
790+
- Removing JS 'Date' as a type.
791+
- Calendar and CalendarList - removing unused parameter 'doNotTriggerListeners' from updateMonth().
792+
- 'input.js' - renaming 'velocityTracker'.
793+
- 'test.js' - renaming 'testUtils' and removing from folder.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ You can run example module by performing these steps:
1212

1313
```
1414
$ git clone [email protected]:wix/react-native-calendars.git
15+
$ cd react-native-calendars
1516
$ npm install
17+
$ cd ios && pod install && cd ..
1618
$ react-native run-ios
1719
```
1820

example/src/screens/calendars.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {useState, Fragment} from 'react';
22
import {StyleSheet, View, ScrollView, Text, TouchableOpacity, Switch} from 'react-native';
3-
// @ts-expect-error
4-
import {Calendar} from 'react-native-calendars';
3+
import {Calendar, CalendarProps} from 'react-native-calendars';
54
import testIDs from '../testIDs';
65

76
const INITIAL_DATE = '2020-02-02';
@@ -14,7 +13,7 @@ const CalendarsScreen = () => {
1413
setShowMarkedDatesExamples(!showMarkedDatesExamples);
1514
};
1615

17-
const onDayPress = day => {
16+
const onDayPress: CalendarProps['onDayPress'] = day => {
1817
setSelected(day.dateString);
1918
};
2019

@@ -349,7 +348,7 @@ const CalendarsScreen = () => {
349348
return (
350349
<View>
351350
<Text style={[styles.customDay, state === 'disabled' ? styles.disabledText : styles.defaultText]}>
352-
{date.day}
351+
{date?.day}
353352
</Text>
354353
</View>
355354
);
@@ -362,6 +361,7 @@ const CalendarsScreen = () => {
362361
const renderCalendarWithCustomHeader = () => {
363362
const CustomHeader = React.forwardRef((props, ref) => {
364363
return (
364+
// @ts-expect-error
365365
<View ref={ref} {...props} style={styles.customHeader}>
366366
<Text>This is a custom header!</Text>
367367
<TouchableOpacity onPress={() => console.warn('Tapped!')}>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@babel/eslint-parser": "^7.13.4",
4444
"@babel/runtime": "^7.12.5",
4545
"@types/lodash": "^4.14.170",
46-
"@types/react-native": "^0.63.52",
46+
"@types/react-native": "^0.64.19",
4747
"@types/xdate": "^0.8.32",
4848
"@typescript-eslint/eslint-plugin": "^2.13.0",
4949
"@typescript-eslint/parser": "^2.13.0",

src/agenda/index.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import invoke from 'lodash/invoke';
21
import PropTypes from 'prop-types';
32
import XDate from 'xdate';
43
import memoize from 'memoize-one';
@@ -20,7 +19,7 @@ import {parseDate, xdateToData, toMarkingFormat} from '../interface';
2019
import {weekDayNames, sameDate, sameMonth} from '../dateutils';
2120
// @ts-expect-error
2221
import {AGENDA_CALENDAR_KNOB} from '../testIDs';
23-
import {VelocityTracker} from '../input';
22+
import {VelocityTracker} from '../velocityTracker';
2423
import {DateData} from '../types';
2524
import styleConstructor from './style';
2625
import CalendarList, {CalendarListProps} from '../calendar-list';
@@ -203,7 +202,7 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
203202
calendarScrollable: enable
204203
});
205204

206-
invoke(this.props, 'onCalendarToggled', enable);
205+
this.props.onCalendarToggled?.(enable);
207206

208207
// Enlarge calendarOffset here as a workaround on iOS to force repaint.
209208
// Otherwise the month after current one or before current one remains invisible.
@@ -223,7 +222,7 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
223222
firstReservationLoad: true
224223
},
225224
() => {
226-
invoke(this.props, 'loadItemsForMonth', xdateToData(this.state.selectedDay));
225+
this.props.loadItemsForMonth?.(xdateToData(this.state.selectedDay));
227226
}
228227
);
229228
}
@@ -241,7 +240,7 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
241240
selectedDay: day.clone()
242241
});
243242

244-
invoke(this.props, 'onCalendarToggled', false);
243+
this.props.onCalendarToggled?.(false);
245244

246245
if (!optimisticScroll) {
247246
this.setState({
@@ -252,8 +251,8 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
252251
this.setScrollPadPosition(this.initialScrollPadPosition(), true);
253252
this.calendar?.current?.scrollToDay(day, this.calendarOffset(), true);
254253

255-
invoke(this.props, 'loadItemsForMonth', xdateToData(day));
256-
invoke(this.props, 'onDayPress', xdateToData(day));
254+
this.props.loadItemsForMonth?.(xdateToData(day));
255+
this.props.onDayPress?.(xdateToData(day));
257256
}
258257

259258
generateMarkings = memoize((selectedDay, markedDates, items = {}) => {
@@ -324,14 +323,14 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
324323
};
325324

326325
onVisibleMonthsChange = (months: DateData[]) => {
327-
invoke(this.props, 'onVisibleMonthsChange', months);
326+
this.props.onVisibleMonthsChange?.(months);
328327

329328
if (this.props.items && !this.state.firstReservationLoad) {
330329
clearTimeout(this.scrollTimeout);
331330

332331
this.scrollTimeout = setTimeout(() => {
333332
if (this._isMounted) {
334-
invoke(this.props, 'loadItemsForMonth', months[0]);
333+
this.props.loadItemsForMonth?.(months[0]);
335334
}
336335
}, 200);
337336
}
@@ -346,7 +345,7 @@ export default class Agenda extends Component<AgendaProps, AgendaState> {
346345
selectedDay: newDate
347346
});
348347

349-
invoke(this.props, 'onDayChange', xdateToData(newDate));
348+
this.props.onDayChange?.(xdateToData(newDate));
350349
};
351350

352351
renderReservations() {

src/agenda/reservation-list/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import invoke from 'lodash/invoke';
21
import isFunction from 'lodash/isFunction';
32
import PropTypes from 'prop-types';
43
import XDate from 'xdate';
@@ -11,7 +10,7 @@ import {sameDate} from '../../dateutils';
1110
import {toMarkingFormat} from '../../interface';
1211
import styleConstructor from './style';
1312
import Reservation, {ReservationProps} from './reservation';
14-
import {ReservationItemType, ReservationsType} from 'agenda';
13+
import {ReservationItemType, ReservationsType} from '../../agenda';
1514

1615

1716
export interface DayReservations {
@@ -30,7 +29,7 @@ export type ReservationListProps = ReservationProps & {
3029
/** Show items only for the selected day. Default = false */
3130
showOnlySelectedDayItems: boolean;
3231
/** callback that gets called when day changes while scrolling agenda list */
33-
onDayChange?: (day: Date) => void;
32+
onDayChange?: (day: XDate) => void;
3433
/** specify what should be rendered instead of ActivityIndicator */
3534
renderEmptyData: () => JSX.Element;
3635
style?: StyleProp<ViewStyle>;
@@ -228,7 +227,7 @@ class ReservationList extends Component<ReservationListProps, ReservationsListSt
228227

229228
onScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
230229
const yOffset = event.nativeEvent.contentOffset.y;
231-
invoke(this.props, 'onScroll', yOffset);
230+
this.props.onScroll?.(yOffset);
232231

233232
let topRowOffset = 0;
234233
let topRow;
@@ -246,7 +245,7 @@ class ReservationList extends Component<ReservationListProps, ReservationsListSt
246245
const dateIsSame = sameDate(day, this.selectedDay);
247246
if (!dateIsSame && this.scrollOver) {
248247
this.selectedDay = day.clone();
249-
invoke(this.props, 'onDayChange', day.clone());
248+
this.props.onDayChange?.(day.clone());
250249
}
251250
};
252251

@@ -279,7 +278,7 @@ class ReservationList extends Component<ReservationListProps, ReservationsListSt
279278
const {reservations, selectedDay, theme, style} = this.props;
280279
if (!reservations || !reservations[toMarkingFormat(selectedDay)]) {
281280
if (isFunction(this.props.renderEmptyData)) {
282-
return invoke(this.props, 'renderEmptyData');
281+
return this.props.renderEmptyData?.();
283282
}
284283

285284
return <ActivityIndicator style={this.style.indicator} color={theme?.indicatorColor} />;

src/agenda/reservation-list/reservation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export interface ReservationProps {
1919
theme: Theme;
2020
/** specify your item comparison function for increased performance */
2121
rowHasChanged?: (a: any, b: any) => boolean;
22-
/** specify how each date should be rendered. day can be undefined if the item is not first in that day */
23-
renderDay?: (date: XDate, item?: DayReservations) => React.Component;
22+
/** specify how each date should be rendered. date can be undefined if the item is not first in that day */
23+
renderDay?: (date?: XDate, item?: DayReservations) => React.Component;
2424
/** specify how each item should be rendered in agenda */
2525
renderItem?: (reservation: any, isFirst: boolean) => React.Component;
2626
/** specify how empty date content with no items should be rendered */
@@ -75,7 +75,7 @@ class Reservation extends Component<ReservationProps> {
7575
}
7676

7777
renderDate(date?: XDate, item?: DayReservations) {
78-
if (isFunction(this.props.renderDay) && date) {
78+
if (isFunction(this.props.renderDay)) {
7979
return this.props.renderDay(date, item);
8080
}
8181

src/calendar-list/index.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import invoke from 'lodash/invoke';
21
import PropTypes from 'prop-types';
32
import XDate from 'xdate';
43

@@ -250,20 +249,17 @@ class CalendarList extends Component<Props, State> {
250249
this.updateMonth(this.state.currentMonth.clone().addMonths(count, true));
251250
};
252251

253-
updateMonth(day: XDate, doNotTriggerListeners = false) {
252+
updateMonth(day: XDate) {
254253
if (day.toString('yyyy MM') === this.state.currentMonth.toString('yyyy MM')) {
255254
return;
256255
}
257256

258257
this.setState({currentMonth: day.clone()}, () => {
259258
this.scrollToMonth(this.state.currentMonth);
260259

261-
if (!doNotTriggerListeners) {
262-
const currMont = this.state.currentMonth.clone();
263-
264-
invoke(this.props, 'onMonthChange', xdateToData(currMont));
265-
invoke(this.props, 'onVisibleMonthsChange', [xdateToData(currMont)]);
266-
}
260+
const currMont = this.state.currentMonth.clone();
261+
this.props.onMonthChange?.(xdateToData(currMont));
262+
this.props.onVisibleMonthsChange?.([xdateToData(currMont)]);
267263
});
268264
}
269265

@@ -298,7 +294,7 @@ class CalendarList extends Component<Props, State> {
298294
}
299295
}
300296

301-
invoke(this.props, 'onVisibleMonthsChange', visibleMonths);
297+
this.props.onVisibleMonthsChange?.(visibleMonths);
302298

303299
this.setState({
304300
// @ts-expect-error

src/calendar/day/basic/driver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ComponentDriver} from 'react-component-driver';
22
import Day from '.';
3-
import {extractStyles} from '../../../../test';
3+
import {extractStyles} from '../../../testUtils';
44

55
export class BasicDayDriver extends ComponentDriver {
66
constructor() {

src/calendar/day/basic/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import invoke from 'lodash/invoke';
21
import values from 'lodash/values';
32
import PropTypes from 'prop-types';
43

54
import React, {Component, Fragment} from 'react';
65
import {TouchableOpacity, Text, View} from 'react-native';
76

8-
import {Theme, DateData, DayState, MarkingTypes} from '../../../types';
7+
import {Theme, DayState, MarkingTypes, DateData} from '../../../types';
98
import {shouldUpdate} from '../../../componentUpdater';
109
import styleConstructor from './style';
1110
import Marking, {MarkingProps} from '../marking';
@@ -19,11 +18,11 @@ export interface BasicDayProps {
1918
/** Theme object */
2019
theme?: Theme;
2120
/** onPress callback */
22-
onPress?: (date: DateData) => void;
21+
onPress?: (date?: DateData) => void;
2322
/** onLongPress callback */
24-
onLongPress?: (date: Date) => void;
23+
onLongPress?: (date?: DateData) => void;
2524
/** The date to return from press callbacks */
26-
date?: Date;
25+
date?: DateData;
2726
/** Disable all touch events for disabled days. can be override with disableTouchEvent in markedDates*/
2827
disableAllTouchEventsForDisabledDays?: boolean;
2928
/** Disable all touch events for inactive days. can be override with disableTouchEvent in markedDates*/
@@ -73,11 +72,11 @@ export default class BasicDay extends Component<BasicDayProps> {
7372
}
7473

7574
onPress = () => {
76-
invoke(this.props, 'onPress', this.props.date);
75+
this.props.onPress?.(this.props.date);
7776
};
7877

7978
onLongPress = () => {
80-
invoke(this.props, 'onLongPress', this.props.date);
79+
this.props.onLongPress?.(this.props.date);
8180
};
8281

8382
get marking() {

0 commit comments

Comments
 (0)