Skip to content

Commit cee93f9

Browse files
committed
Fix forwardRef wrapper
1 parent bb2004d commit cee93f9

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

example/src/screens/calendarPlaygroundScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import times from 'lodash/times';
2-
import React, {useState, useCallback, useMemo, useRef} from 'react';
2+
import React, {forwardRef, useState, useCallback, useMemo, useRef} from 'react';
33
import {StyleSheet, View, ScrollView, Text, TouchableOpacity, Switch, Alert} from 'react-native';
44
import {Calendar, CalendarUtils} from 'react-native-calendars';
55

@@ -368,7 +368,7 @@ const NewCalendarScreen = () => {
368368
setCustomHeaderNewMonth(false);
369369
};
370370

371-
const CustomHeader = React.forwardRef((props, ref) => {
371+
const CustomHeader = forwardRef((props, ref) => {
372372
customHeaderProps.current = props;
373373

374374
return (

example/src/screens/calendarScreen.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useState, Fragment, useCallback, useMemo, useRef} from 'react';
1+
import React, {forwardRef, useState, Fragment, useCallback, useMemo, useRef} from 'react';
22
import {StyleSheet, View, ScrollView, Text, TouchableOpacity} from 'react-native';
33
import {Calendar, CalendarUtils} from 'react-native-calendars';
44
import testIDs from '../testIDs';
@@ -448,7 +448,7 @@ const CalendarScreen = () => {
448448
};
449449

450450
const renderCalendarWithCustomHeader = () => {
451-
const CustomHeader = React.forwardRef((props, ref) => {
451+
const CustomHeader = forwardRef((props, ref) => {
452452
customHeaderProps.current = props;
453453

454454
return (

src/agenda/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class Agenda extends Component<AgendaProps, State> {
8282
onDayChange: PropTypes.func,
8383
renderKnob: PropTypes.func,
8484
renderList: PropTypes.func,
85-
selected: PropTypes.any, //TODO: Should be renamed 'selectedDay' and inherited from ReservationList
85+
selected: PropTypes.any,
8686
hideKnob: PropTypes.bool,
8787
showClosingKnob: PropTypes.bool
8888
};

src/calendar/header/index.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const accessibilityActions = [
8383
{name: 'decrement', label: 'decrement'}
8484
];
8585

86-
const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
86+
const CalendarHeader = (props: CalendarHeaderProps, ref) => {
8787
const {
8888
theme,
8989
style: propsStyle,
@@ -306,12 +306,13 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
306306
{renderDayNames()}
307307
</View>
308308
);
309-
});
310-
311-
export default CalendarHeader;
312-
CalendarHeader.displayName = 'CalendarHeader';
313-
CalendarHeader.defaultProps = {
314-
monthFormat: 'MMMM yyyy',
315-
webAriaLevel: 1,
316-
arrowsHitSlop: 20
317309
};
310+
311+
export default Object.assign(forwardRef(CalendarHeader), {
312+
displayName: 'CalendarHeader',
313+
defaultProps: {
314+
monthFormat: 'MMMM yyyy',
315+
webAriaLevel: 1,
316+
arrowsHitSlop: 20
317+
}
318+
});

src/expandableCalendar/AgendaList/agendaList.tsx

+13-14
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const viewabilityConfig = {
4141
* @extends: SectionList
4242
* @example: https://github.com/wix/react-native-calendars/blob/master/example/src/screens/expandableCalendar.js
4343
*/
44-
const AgendaList = forwardRef((props: AgendaListProps, ref: any) => {
44+
const AgendaList = (props: AgendaListProps, ref: any) => {
4545
const {
4646
theme,
4747
sections,
@@ -247,17 +247,16 @@ const AgendaList = forwardRef((props: AgendaListProps, ref: any) => {
247247
// _getItemLayout = (data, index) => {
248248
// return {length: constants.screenWidth, offset: constants.screenWidth * index, index};
249249
// }
250-
});
251-
252-
export default AgendaList;
253-
254-
AgendaList.displayName = 'AgendaList';
255-
AgendaList.propTypes = {
256-
dayFormat: PropTypes.string,
257-
dayFormatter: PropTypes.func,
258-
useMoment: PropTypes.bool,
259-
markToday: PropTypes.bool,
260-
// @ts-expect-error TODO Figure out why forwardRef causes error about the number type
261-
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
262-
avoidDateUpdates: PropTypes.bool
263250
};
251+
252+
export default Object.assign(forwardRef(AgendaList), {
253+
displayName: 'AgendaList',
254+
propTypes: {
255+
dayFormat: PropTypes.string,
256+
dayFormatter: PropTypes.func,
257+
useMoment: PropTypes.bool,
258+
markToday: PropTypes.bool,
259+
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
260+
avoidDateUpdates: PropTypes.bool
261+
}
262+
});

0 commit comments

Comments
 (0)