Skip to content

Commit edf88b3

Browse files
committed
Merge branch 'master' of github.com:wix/react-native-calendars into release
2 parents a0bee58 + 5fb4535 commit edf88b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1115
-538
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This module includes various customizable **React-Native** calendar components.
99

1010
The package is both **Android** and **iOS** compatible.
1111

12-
See our new [Docs site](https://wix.github.io/react-native-calendars/)
12+
**See our new [Docs site](https://wix.github.io/react-native-calendars/)**
1313

1414
## Try it out
1515

@@ -94,7 +94,7 @@ LocaleConfig.defaultLocale = 'fr';
9494
```javascript
9595
<Calendar
9696
// Initially visible month. Default = now
97-
current={'2012-03-01'}
97+
initialDate={'2012-03-01'}
9898
// Minimum date that can be selected, dates before minDate will be grayed out. Default = undefined
9999
minDate={'2012-05-10'}
100100
// Maximum date that can be selected, dates after maxDate will be grayed out. Default = undefined

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.android.build.OutputFile
44

55
project.ext.react = [
66
entryFile: "index.js",
7-
enableHermes: false, // clean and rebuild if changing
7+
enableHermes: true, // clean and rebuild if changing
88
]
99

1010
apply from: "../../node_modules/react-native/react.gradle"

android/app/proguard-rules.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@
6868
-dontwarn java.nio.file.*
6969
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
7070
-dontwarn okio.**
71+
72+
-keep class com.facebook.hermes.unicode.** { *; }
73+
-keep class com.facebook.jni.** { *; }

example/src/screens/calendarsList.tsx renamed to example/src/screens/calendarListScreen.tsx

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,62 @@
1-
import React, {useState} from 'react';
2-
import {StyleSheet, Text, View} from 'react-native';
3-
// @ts-expect-error
4-
import {CalendarList} from 'react-native-calendars';
1+
import React, {useState, useMemo, useCallback} from 'react';
2+
import {StyleSheet, Text, View, TextStyle} from 'react-native';
3+
import {CalendarList, DateData} from 'react-native-calendars';
54
import testIDs from '../testIDs';
65

76
const RANGE = 24;
8-
const initialDate = '2020-06-10';
7+
const initialDate = '2022-07-05';
98

10-
const CalendarsList = () => {
9+
interface Props {
10+
horizontalView?: boolean;
11+
}
12+
13+
const CalendarListScreen = (props: Props) => {
14+
const {horizontalView} = props;
1115
const [selected, setSelected] = useState(initialDate);
12-
const markedDates = {
13-
[selected]: {
14-
selected: true,
15-
disableTouchEvent: true,
16-
selectedColor: '#5E60CE',
17-
selectedTextColor: 'white'
18-
}
19-
};
16+
const marked = useMemo(() => {
17+
return {
18+
[selected]: {
19+
selected: true,
20+
disableTouchEvent: true,
21+
selectedColor: '#5E60CE',
22+
selectedTextColor: 'white'
23+
},
24+
['2022-08-05']: {
25+
selectedTextColor: 'pink'
26+
}
27+
};
28+
}, [selected]);
2029

21-
const onDayPress = day => {
30+
const onDayPress = useCallback((day: DateData) => {
2231
setSelected(day.dateString);
23-
};
32+
}, []);
2433

2534
return (
2635
<CalendarList
2736
testID={testIDs.calendarList.CONTAINER}
2837
current={initialDate}
2938
pastScrollRange={RANGE}
3039
futureScrollRange={RANGE}
31-
renderHeader={renderCustomHeader}
32-
theme={theme}
3340
onDayPress={onDayPress}
34-
markedDates={markedDates}
41+
markedDates={marked}
42+
renderHeader={!horizontalView ? renderCustomHeader : undefined}
43+
theme={!horizontalView ? theme : undefined}
44+
horizontal={horizontalView}
45+
pagingEnabled={horizontalView}
46+
staticHeader={horizontalView}
3547
/>
3648
);
3749
};
3850

3951
const theme = {
40-
'stylesheet.calendar.header': {
41-
dayHeader: {
42-
fontWeight: '600',
43-
color: '#48BFE3'
52+
stylesheet: {
53+
calendar: {
54+
header: {
55+
dayHeader: {
56+
fontWeight: '600',
57+
color: '#48BFE3'
58+
}
59+
}
4460
}
4561
},
4662
'stylesheet.day.basic': {
@@ -55,10 +71,10 @@ const theme = {
5571
}
5672
};
5773

58-
function renderCustomHeader(date) {
74+
function renderCustomHeader(date: any) {
5975
const header = date.toString('MMMM yyyy');
6076
const [month, year] = header.split(' ');
61-
const textStyle = {
77+
const textStyle: TextStyle = {
6278
fontSize: 18,
6379
fontWeight: 'bold',
6480
paddingTop: 10,
@@ -75,7 +91,7 @@ function renderCustomHeader(date) {
7591
);
7692
}
7793

78-
export default CalendarsList;
94+
export default CalendarListScreen;
7995

8096
const styles = StyleSheet.create({
8197
header: {

example/src/screens/calendarScreen.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState, Fragment, useCallback, useMemo} from 'react';
1+
import React, {useState, Fragment, useCallback, useMemo, useRef} from 'react';
22
import {StyleSheet, View, ScrollView, Text, TouchableOpacity} from 'react-native';
33
import {Calendar, CalendarProps} from 'react-native-calendars';
44
import testIDs from '../testIDs';
@@ -7,6 +7,7 @@ const INITIAL_DATE = '2020-02-02';
77

88
const CalendarScreen = () => {
99
const [selected, setSelected] = useState(INITIAL_DATE);
10+
const [currentMonth, setCurrentMonth] = useState(INITIAL_DATE);
1011

1112
const onDayPress: CalendarProps['onDayPress'] = useCallback(day => {
1213
setSelected(day.dateString);
@@ -138,12 +139,16 @@ const CalendarScreen = () => {
138139
selectedDayBackgroundColor: '#333248',
139140
arrowColor: 'white',
140141
// textDisabledColor: 'red',
141-
'stylesheet.calendar.header': {
142-
week: {
143-
marginTop: 30,
144-
marginHorizontal: 12,
145-
flexDirection: 'row',
146-
justifyContent: 'space-between'
142+
stylesheet: {
143+
calendar: {
144+
header: {
145+
week: {
146+
marginTop: 30,
147+
marginHorizontal: 12,
148+
flexDirection: 'row',
149+
justifyContent: 'space-between'
150+
}
151+
}
147152
}
148153
}
149154
}}
@@ -411,14 +416,36 @@ const CalendarScreen = () => {
411416
);
412417
};
413418

419+
const customHeaderProps: any = useRef();
420+
421+
const setCustomHeaderNewMonth = (next = false) => {
422+
const add = next ? 1 : -1;
423+
const month = customHeaderProps?.current?.month;
424+
const newMonth = new Date(month.setMonth(month.getMonth() + add));
425+
customHeaderProps?.current?.addMonth(add);
426+
setCurrentMonth(newMonth.toISOString().split('T')[0]);
427+
};
428+
const moveNext = () => {
429+
setCustomHeaderNewMonth(true);
430+
};
431+
const movePrevious = () => {
432+
setCustomHeaderNewMonth(false);
433+
};
434+
414435
const renderCalendarWithCustomHeader = () => {
415436
const CustomHeader = React.forwardRef((props, ref) => {
437+
customHeaderProps.current = props;
438+
416439
return (
417440
// @ts-expect-error
418441
<View ref={ref} {...props} style={styles.customHeader}>
419-
<Text>This is a custom header!</Text>
420-
<TouchableOpacity onPress={() => console.warn('Tapped!')}>
421-
<Text>Tap Me</Text>
442+
<TouchableOpacity onPress={movePrevious}>
443+
<Text>Previous</Text>
444+
</TouchableOpacity>
445+
<Text>Custom header!</Text>
446+
<Text>{currentMonth}</Text>
447+
<TouchableOpacity onPress={moveNext}>
448+
<Text>Next</Text>
422449
</TouchableOpacity>
423450
</View>
424451
);
@@ -428,6 +455,7 @@ const CalendarScreen = () => {
428455
<Fragment>
429456
<Text style={styles.text}>Calendar with custom header component</Text>
430457
<Calendar
458+
initialDate={INITIAL_DATE}
431459
testID={testIDs.calendars.LAST}
432460
style={[styles.calendar, styles.customCalendar]}
433461
customHeader={CustomHeader}

example/src/screens/expandableCalendarScreen.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ const ITEMS: any[] = [
9797
}
9898
];
9999

100-
type MarkedDate = {
100+
type MarkedDates = {
101101
[key: string]: object;
102102
}
103103

104104
function getMarkedDates(items: any[]) {
105-
const marked: MarkedDate = {};
105+
const marked: MarkedDates = {};
106106

107107
items.forEach(item => {
108108
// NOTE: only mark dates with data
@@ -122,21 +122,23 @@ function getTheme() {
122122
// arrows
123123
arrowColor: 'black',
124124
arrowStyle: {padding: 0},
125+
// knob
126+
expandableKnobColor: themeColor,
125127
// month
126128
monthTextColor: 'black',
127129
textMonthFontSize: 16,
128130
textMonthFontFamily: 'HelveticaNeue',
129-
textMonthFontWeight: 'bold',
131+
textMonthFontWeight: 'bold' as 'bold',
130132
// day names
131133
textSectionTitleColor: 'black',
132134
textDayHeaderFontSize: 12,
133135
textDayHeaderFontFamily: 'HelveticaNeue',
134-
textDayHeaderFontWeight: 'normal',
136+
textDayHeaderFontWeight: 'normal' as 'normal',
135137
// dates
136138
dayTextColor: themeColor,
137139
textDayFontSize: 18,
138140
textDayFontFamily: 'HelveticaNeue',
139-
textDayFontWeight: '500',
141+
textDayFontWeight: '500' as '500',
140142
textDayStyle: {marginTop: Platform.OS === 'android' ? 2 : 4},
141143
// selected date
142144
selectedDayBackgroundColor: themeColor,
@@ -186,7 +188,7 @@ export default class ExpandableCalendarScreen extends Component<Props> {
186188
onMonthChange={this.onMonthChange}
187189
showTodayButton
188190
disabledOpacity={0.6}
189-
// theme={this.todayBtnTheme}
191+
theme={this.todayBtnTheme}
190192
// todayBottomMargin={16}
191193
>
192194
{this.props.weekView ? (
@@ -202,7 +204,7 @@ export default class ExpandableCalendarScreen extends Component<Props> {
202204
// calendarStyle={styles.calendar}
203205
// headerStyle={styles.calendar} // for horizontal only
204206
// disableWeekScroll
205-
// theme={this.theme}
207+
theme={this.theme}
206208
// disableAllTouchEventsForDisabledDays
207209
firstDay={1}
208210
markedDates={this.marked}

example/src/screens/horizontalCalendarList.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

example/src/screens/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import {Navigation} from 'react-native-navigation';
22

33
import MenuScreen from './menuScreen';
4-
import CalendarsScreen from './calendarScreen';
4+
import CalendarScreen from './calendarScreen';
55
import AgendaScreen from './agendaScreen';
6-
import CalendarsList from './calendarsList';
7-
import HorizontalCalendarList from './horizontalCalendarList';
6+
import CalendarsListScreen from './calendarListScreen';
7+
import NewCalendarsListScreen from './newCalendarListScreen';
88
import ExpandableCalendarScreen from './expandableCalendarScreen';
99
import TimelineCalendarScreen from './timelineCalendarScreen';
1010

1111
export function registerScreens() {
1212
Navigation.registerComponent('Menu', () => MenuScreen);
13-
Navigation.registerComponent('Calendars', () => CalendarsScreen);
14-
Navigation.registerComponent('Agenda', () => AgendaScreen);
15-
Navigation.registerComponent('CalendarsList', () => CalendarsList);
16-
Navigation.registerComponent('HorizontalCalendarList', () => HorizontalCalendarList);
13+
Navigation.registerComponent('CalendarScreen', () => CalendarScreen);
14+
Navigation.registerComponent('AgendaScreen', () => AgendaScreen);
15+
Navigation.registerComponent('CalendarListScreen', () => CalendarsListScreen);
16+
Navigation.registerComponent('NewCalendarListScreen', () => NewCalendarsListScreen);
1717
Navigation.registerComponent('ExpandableCalendarScreen', () => ExpandableCalendarScreen);
18-
Navigation.registerComponent('TimelineCalendar', () => TimelineCalendarScreen);
18+
Navigation.registerComponent('TimelineCalendarScreen', () => TimelineCalendarScreen);
1919
}

example/src/screens/menu.tsx.orig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class MenuScreen extends Component<Props> {
9494
}
9595

9696
onCalendarListPress() {
97-
this.pushScreen('CalendarsList');
97+
this.pushScreen('CalendarListScreen');
9898
}
9999

100100
onHorizontalCalendarListPress() {

0 commit comments

Comments
 (0)