Skip to content

Commit 0f8f1a9

Browse files
authored
Merge pull request #1825 from wix/infra/WeekDaysName_component
WeekDaysNames component
2 parents cb8ae11 + 36e3db6 commit 0f8f1a9

File tree

8 files changed

+52
-69
lines changed

8 files changed

+52
-69
lines changed

src/agenda/index.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import memoize from 'memoize-one';
44

55
import React, {Component} from 'react';
66
import {
7-
Text,
87
View,
98
Dimensions,
109
Animated,
@@ -16,13 +15,14 @@ import {
1615

1716
import {extractComponentProps} from '../componentUpdater';
1817
import {parseDate, xdateToData, toMarkingFormat} from '../interface';
19-
import {weekDayNames, sameDate, sameMonth} from '../dateutils';
18+
import {sameDate, sameMonth} from '../dateutils';
2019
// @ts-expect-error
2120
import {AGENDA_CALENDAR_KNOB} from '../testIDs';
2221
import {VelocityTracker} from '../velocityTracker';
2322
import {DateData, AgendaSchedule} from '../types';
2423
import {getCalendarDateString} from '../services';
2524
import styleConstructor from './style';
25+
import WeekDaysNames from '../commons/WeekDaysNames';
2626
import CalendarList, {CalendarListProps} from '../calendar-list';
2727
import ReservationList, {ReservationListProps} from './reservation-list';
2828

@@ -373,26 +373,21 @@ export default class Agenda extends Component<AgendaProps, State> {
373373
return knob;
374374
}
375375

376-
renderWeekDaysNames = memoize((weekDaysNames: string[]) => {
377-
return weekDaysNames.map((day, index) => (
378-
<Text
379-
key={day + index}
380-
style={this.style.weekday}
381-
allowFontScaling={false}
382-
numberOfLines={1}
383-
>
384-
{day}
385-
</Text>
386-
));
387-
});
376+
renderWeekDaysNames = () => {
377+
return (
378+
<WeekDaysNames
379+
firstDay={this.props.firstDay}
380+
style={this.style.dayHeader}
381+
/>
382+
);
383+
};
388384

389385
renderWeekNumbersSpace = () => {
390-
return this.props.showWeekNumbers && <View style={this.style.weekday} />;
386+
return this.props.showWeekNumbers && <View style={this.style.dayHeader}/>;
391387
};
392388

393389
render() {
394-
const {firstDay, hideKnob, style, testID} = this.props;
395-
const weekDaysNames = weekDayNames(firstDay);
390+
const {hideKnob, style, testID} = this.props;
396391
const agendaHeight = this.initialScrollPadPosition();
397392
const weekdaysStyle = [
398393
this.style.weekdays,
@@ -458,7 +453,7 @@ export default class Agenda extends Component<AgendaProps, State> {
458453
</Animated.View>
459454
<Animated.View style={weekdaysStyle}>
460455
{this.renderWeekNumbersSpace()}
461-
{this.renderWeekDaysNames(weekDaysNames)}
456+
{this.renderWeekDaysNames()}
462457
</Animated.View>
463458
<Animated.ScrollView
464459
ref={this.scrollPad}

src/agenda/style.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export default function styleConstructor(theme: Theme = {}) {
3434
alignItems: 'center',
3535
backgroundColor: appStyle.calendarBackground
3636
},
37-
weekday: {
37+
dayHeader: {
3838
width: 32,
3939
textAlign: 'center',
40-
color: appStyle.textSectionTitleColor,
4140
fontSize: appStyle.textDayHeaderFontSize,
4241
fontFamily: appStyle.textDayHeaderFontFamily,
43-
fontWeight: appStyle.textDayHeaderFontWeight
42+
fontWeight: appStyle.textDayHeaderFontWeight,
43+
color: appStyle.textSectionTitleColor
4444
},
4545
reservations: {
4646
flex: 1,

src/calendar/header/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,15 @@ const CalendarHeader = forwardRef((props: CalendarHeaderProps, ref) => {
235235
}
236236
};
237237

238+
const renderWeekNumbersSpace = () => {
239+
return showWeekNumbers && <View style={style.current.dayHeader}/>;
240+
};
241+
238242
const renderDayNames = () => {
239243
if (!hideDayNames) {
240244
return (
241245
<View style={style.current.week} testID={testID ? `${HEADER_DAY_NAMES}-${testID}` : HEADER_DAY_NAMES}>
242-
{showWeekNumbers && <Text allowFontScaling={false} style={style.current.dayHeader}></Text>}
246+
{renderWeekNumbersSpace()}
243247
{renderWeekDays}
244248
</View>
245249
);

src/expandableCalendar/WeekCalendar/WeekDaysNames.tsx renamed to src/commons/WeekDaysNames.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import {StyleProp, Text, TextStyle} from 'react-native';
3-
4-
import {weekDayNames} from '../../dateutils';
3+
import {weekDayNames} from '../dateutils';
54

65
interface WeekDaysNamesProps {
76
firstDay?: number;
@@ -10,6 +9,7 @@ interface WeekDaysNamesProps {
109

1110
const WeekDaysNames = React.memo(({firstDay, style}: WeekDaysNamesProps) => {
1211
const dayNames = weekDayNames(firstDay);
12+
1313
return dayNames.map((day: string, index: number) => (
1414
<Text
1515
allowFontScaling={false}

src/expandableCalendar/WeekCalendar/index.tsx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import XDate from 'xdate';
44
import {Map} from 'immutable';
55

66
import React, {Component} from 'react';
7-
import {FlatList, View, Text, NativeSyntheticEvent, NativeScrollEvent} from 'react-native';
7+
import {FlatList, View, NativeSyntheticEvent, NativeScrollEvent} from 'react-native';
88

99
import {extractComponentProps} from '../../componentUpdater';
10-
import {weekDayNames, sameWeek} from '../../dateutils';
10+
import {sameWeek} from '../../dateutils';
1111
import {toMarkingFormat} from '../../interface';
1212
import {DateData} from '../../types';
1313
import styleConstructor from '../style';
1414
import asCalendarConsumer from '../asCalendarConsumer';
1515
import CalendarList, {CalendarListProps} from '../../calendar-list';
16+
import WeekDaysNames from '../../commons/WeekDaysNames';
1617
import Week from '../week';
1718
import Presenter from './presenter';
1819
import constants from '../../commons/constants';
@@ -168,26 +169,18 @@ class WeekCalendar extends Component<WeekCalendarProps, State> {
168169

169170
keyExtractor = (_: string, index: number) => index.toString();
170171

171-
renderWeekDaysNames = memoize(weekDaysNames => {
172-
return weekDaysNames.map((day: string, index: number) => (
173-
<Text
174-
allowFontScaling={false}
175-
key={index}
176-
style={this.style.dayHeader}
177-
numberOfLines={1}
178-
accessibilityLabel={''}
179-
// accessible={false} // not working
180-
// importantForAccessibility='no'
181-
>
182-
{day}
183-
</Text>
184-
));
185-
});
172+
renderWeekDaysNames = () => {
173+
return (
174+
<WeekDaysNames
175+
firstDay={this.props.firstDay}
176+
style={this.style.dayHeader}
177+
/>
178+
);
179+
};
186180

187181
render() {
188182
const {allowShadow, firstDay, hideDayNames, current, context} = this.props;
189183
const {items} = this.state;
190-
const weekDaysNames = weekDayNames(firstDay);
191184
const extraData = Map({
192185
current,
193186
date: context.date,
@@ -202,7 +195,7 @@ class WeekCalendar extends Component<WeekCalendarProps, State> {
202195
{!hideDayNames && (
203196
<View style={[this.style.week, this.style.weekCalendar]}>
204197
{/* {this.props.weekNumbers && <Text allowFontScaling={false} style={this.style.dayHeader}></Text>} */}
205-
{this.renderWeekDaysNames(weekDaysNames)}
198+
{this.renderWeekDaysNames()}
206199
</View>
207200
)}
208201
<FlatList

src/expandableCalendar/WeekCalendar/new.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XDate from 'xdate';
44

55
import InfiniteList from '../../infinite-list';
66
import Week from '../week';
7-
import WeekDaysNames from './WeekDaysNames';
7+
import WeekDaysNames from '../../commons/WeekDaysNames';
88
import {CalendarListProps} from '../../calendar-list';
99
import CalendarContext from '../../expandableCalendar/Context';
1010
import styleConstructor from '../style';
@@ -106,7 +106,7 @@ const WeekCalendar = (props: WeekCalendarProps) => {
106106
>
107107
{!hideDayNames && (
108108
<View style={[style.current.week, style.current.weekCalendar]}>
109-
<WeekDaysNames firstDay={firstDay} style={style.current.dayHeader} />
109+
<WeekDaysNames firstDay={firstDay} style={style.current.dayHeader}/>
110110
</View>
111111
)}
112112
<View>

src/expandableCalendar/index.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ import {
2323

2424
// @ts-expect-error
2525
import {CALENDAR_KNOB} from '../testIDs';
26-
import {page, weekDayNames} from '../dateutils';
26+
import {page} from '../dateutils';
2727
import {parseDate, toMarkingFormat} from '../interface';
2828
import {Theme, DateData, Direction} from '../types';
2929
import styleConstructor, {HEADER_HEIGHT, KNOB_CONTAINER_HEIGHT} from './style';
30-
import CalendarList, {CalendarListProps} from '../calendar-list';
30+
import WeekDaysNames from '../commons/WeekDaysNames';
3131
import Calendar from '../calendar';
32-
import asCalendarConsumer from './asCalendarConsumer';
33-
import WeekCalendar from './WeekCalendar';
32+
import CalendarList, {CalendarListProps} from '../calendar-list';
3433
import Week from './week';
34+
import WeekCalendar from './WeekCalendar';
35+
import asCalendarConsumer from './asCalendarConsumer';
3536

3637
import constants from '../commons/constants';
3738
const commons = require('./commons');
@@ -475,21 +476,19 @@ class ExpandableCalendar extends Component<ExpandableCalendarProps, State> {
475476
];
476477
});
477478

478-
renderWeekDaysNames = memoize((weekDaysNames, calendarStyle) => {
479+
renderWeekDaysNames = () => {
479480
return (
480-
<View style={this.getWeekDaysStyle(calendarStyle)}>
481-
{weekDaysNames.map((day: string, index: number) => (
482-
<Text allowFontScaling={false} key={day + index} style={this.style.weekday} numberOfLines={1}>
483-
{day}
484-
</Text>
485-
))}
481+
<View style={this.getWeekDaysStyle(this.props.calendarStyle)}>
482+
<WeekDaysNames
483+
firstDay={this.props.firstDay}
484+
style={this.style.dayHeader}
485+
/>
486486
</View>
487487
);
488-
});
488+
};
489489

490490
renderHeader() {
491491
const monthYear = new XDate(this.props.context.date).toString('MMMM yyyy');
492-
const weekDaysNames = weekDayNames(this.props.firstDay);
493492

494493
return (
495494
<Animated.View
@@ -500,7 +499,7 @@ class ExpandableCalendar extends Component<ExpandableCalendarProps, State> {
500499
<Text allowFontScaling={false} style={this.style.headerTitle}>
501500
{monthYear}
502501
</Text>
503-
{this.renderWeekDaysNames(weekDaysNames, this.props.calendarStyle)}
502+
{this.renderWeekDaysNames()}
504503
</Animated.View>
505504
);
506505
}

src/expandableCalendar/style.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default function styleConstructor(theme: Theme = {}) {
8181
flexDirection: 'row',
8282
justifyContent: 'space-between'
8383
},
84-
weekday: {
84+
dayHeader: {
8585
width: 32,
8686
textAlign: 'center',
8787
fontSize: appStyle.textDayHeaderFontSize,
@@ -96,7 +96,7 @@ export default function styleConstructor(theme: Theme = {}) {
9696
position: 'absolute',
9797
left: 0,
9898
right: 0,
99-
top: HEADER_HEIGHT + (constants.isAndroid ? 8 : 4), // align row on top of calendar's first row
99+
top: HEADER_HEIGHT + (constants.isAndroid ? 8 : 9), // align row on top of calendar's first row
100100
},
101101
hidden: {
102102
opacity: 0
@@ -123,14 +123,6 @@ export default function styleConstructor(theme: Theme = {}) {
123123
emptyDayContainer: {
124124
flex: 1
125125
},
126-
dayHeader: {
127-
width: 32,
128-
textAlign: 'center',
129-
fontSize: appStyle.textDayHeaderFontSize,
130-
fontFamily: appStyle.textDayHeaderFontFamily,
131-
fontWeight: appStyle.textDayHeaderFontWeight,
132-
color: appStyle.textSectionTitleColor
133-
},
134126
arrowImage: {
135127
tintColor: appStyle.arrowColor,
136128
transform: constants.isRTL ? [{scaleX: -1}] : undefined

0 commit comments

Comments
 (0)