Skip to content

Commit

Permalink
Merge pull request wix#1513 from wix/infra/some-formatting
Browse files Browse the repository at this point in the history
Infra/some formatting
  • Loading branch information
ethanshar authored May 23, 2021
2 parents b63f2ec + 7274b3b commit f98d2a8
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 111 deletions.
26 changes: 9 additions & 17 deletions example/src/screens/calendars.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,13 @@ const CalendarsScreen = () => {
<Fragment>
<Text style={styles.text}>Calendar with custom day component</Text>
<Calendar
style={[
styles.calendar,
styles.customCalendar
]}
style={[styles.calendar, styles.customCalendar]}
dayComponent={({date, state}) => {
return (
<View>
<Text style={[styles.customDay, state === 'disabled' ? styles.disabledText : styles.defaultText]}>{date.day}</Text>
<Text style={[styles.customDay, state === 'disabled' ? styles.disabledText : styles.defaultText]}>
{date.day}
</Text>
</View>
);
}}
Expand All @@ -373,11 +372,7 @@ const CalendarsScreen = () => {
const renderCalendarWithCustomHeader = () => {
const CustomHeader = React.forwardRef((props, ref) => {
return (
<View
ref={ref}
{...props}
style={styles.customHeader}
>
<View ref={ref} {...props} style={styles.customHeader}>
<Text>This is a custom header!</Text>
<TouchableOpacity onPress={() => console.warn('Tapped!')}>
<Text>Tap Me</Text>
Expand All @@ -391,10 +386,7 @@ const CalendarsScreen = () => {
<Text style={styles.text}>Calendar with custom header component</Text>
<Calendar
testID={testIDs.calendars.LAST}
style={[
styles.calendar,
styles.customCalendar
]}
style={[styles.calendar, styles.customCalendar]}
customHeader={CustomHeader}
/>
</Fragment>
Expand Down Expand Up @@ -462,12 +454,12 @@ const styles = StyleSheet.create({
marginBottom: 10
},
switchContainer: {
flexDirection: 'row',
margin: 10,
flexDirection: 'row',
margin: 10,
alignItems: 'center'
},
switchText: {
margin: 10,
margin: 10,
fontSize: 16
},
text: {
Expand Down
4 changes: 2 additions & 2 deletions example/src/screens/expandableCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default class ExpandableCalendarScreen extends Component {
theme = getTheme();
todayBtnTheme = {
todayButtonTextColor: themeColor
}
};

onDateChanged = (/* date, updateSource */) => {
// console.warn('ExpandableCalendarScreen onDateChanged: ', date, updateSource);
Expand Down Expand Up @@ -191,7 +191,7 @@ export default class ExpandableCalendarScreen extends Component {
// todayBottomMargin={16}
>
{this.props.weekView ? (
<WeekCalendar testID={testIDs.weekCalendar.CONTAINER} firstDay={1} markedDates={this.marked}/>
<WeekCalendar testID={testIDs.weekCalendar.CONTAINER} firstDay={1} markedDates={this.marked} />
) : (
<ExpandableCalendar
testID={testIDs.expandableCalendar.CONTAINER}
Expand Down
3 changes: 1 addition & 2 deletions example/src/screens/horizontalCalendarList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {CalendarList} from 'react-native-calendars';
const testIDs = require('../testIDs');
const initialDate = '2020-05-16';


const HorizontalCalendarList = () => {
const [selected, setSelected] = useState(initialDate);
const markedDates = {
Expand All @@ -13,7 +12,7 @@ const HorizontalCalendarList = () => {
selectedColor: '#DFA460'
}
};

const onDayPress = day => {
setSelected(day.dateString);
};
Expand Down
9 changes: 4 additions & 5 deletions src/agenda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import styleConstructor from './style';
import CalendarList from '../calendar-list';
import ReservationList from './reservation-list';


const HEADER_HEIGHT = 104;
const KNOB_HEIGHT = 24;

Expand Down Expand Up @@ -47,8 +46,8 @@ export default class AgendaView extends Component {
/** callback that gets called when day changes while scrolling agenda list */
onDaychange: PropTypes.func, //TODO: Should be renamed 'onDayChange'
/** specify how agenda knob should look like */
renderKnob: PropTypes.func,
/** initially selected day */
renderKnob: PropTypes.func,
/** initially selected day */
selected: PropTypes.any, //TODO: Should be renamed 'selectedDay'
/** Hide knob button. Default = false */
hideKnob: PropTypes.bool
Expand Down Expand Up @@ -333,7 +332,7 @@ export default class AgendaView extends Component {
return knob;
}

renderWeekDaysNames = memoize((weekDaysNames) => {
renderWeekDaysNames = memoize(weekDaysNames => {
return weekDaysNames.map((day, index) => (
<Text allowFontScaling={false} key={day + index} style={this.style.weekday} numberOfLines={1}>
{day}
Expand All @@ -342,7 +341,7 @@ export default class AgendaView extends Component {
});

renderWeekNumbersSpace = () => {
return this.props.showWeekNumbers && <View allowFontScaling={false} style={this.style.weekday} numberOfLines={1}/>;
return this.props.showWeekNumbers && <View allowFontScaling={false} style={this.style.weekday} numberOfLines={1} />;
};

render() {
Expand Down
4 changes: 2 additions & 2 deletions src/agenda/reservation-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class ReservationList extends Component {
...Reservation.propTypes,
/** the list of items that have to be displayed in agenda. If you want to render item as empty date
the value of date key kas to be an empty array []. If there exists no value for date key it is
considered that the date in question is not yet loaded */
considered that the date in question is not yet loaded */
reservations: PropTypes.object,
selectedDay: PropTypes.instanceOf(XDate),
topDay: PropTypes.instanceOf(XDate),
/** Show items only for the selected day. Default = false */
showOnlySelectedDayItems: PropTypes.bool,
/** callback that gets called when day changes while scrolling agenda list */
/** callback that gets called when day changes while scrolling agenda list */
onDayChange: PropTypes.func,
/** specify what should be rendered instead of ActivityIndicator */
renderEmptyData: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion src/agenda/reservation-list/reservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Reservation extends Component {
}

const today = dateutils.isToday(date) ? this.style.today : undefined;

if (date) {
return (
<View style={this.style.day} testID={RESERVATION_DATE}>
Expand Down
13 changes: 6 additions & 7 deletions src/calendar-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,15 @@ class CalendarList extends Component {
}

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

if (!doNotTriggerListeners) {
const currMont = this.state.currentMonth.clone();
if (!doNotTriggerListeners) {
const currMont = this.state.currentMonth.clone();

_.invoke(this.props, 'onMonthChange', xdateToData(currMont));
_.invoke(this.props, 'onVisibleMonthsChange', [xdateToData(currMont)]);
}
_.invoke(this.props, 'onMonthChange', xdateToData(currMont));
_.invoke(this.props, 'onVisibleMonthsChange', [xdateToData(currMont)]);
}
);
});
}

onViewableItemsChanged = ({viewableItems}) => {
Expand Down
1 change: 0 additions & 1 deletion src/calendar-list/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {extractComponentProps} from '../component-updater';
import Calendar from '../calendar';
import styleConstructor from './style';


class CalendarListItem extends Component {
static displayName = 'IGNORE';

Expand Down
21 changes: 14 additions & 7 deletions src/calendar/day/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {shouldUpdate} from '../../../component-updater';
import styleConstructor from './style';
import Marking from '../marking';


export default class BasicDay extends Component {
static displayName = 'IGNORE';

Expand All @@ -32,21 +31,29 @@ export default class BasicDay extends Component {

constructor(props) {
super(props);

this.style = styleConstructor(props.theme);
}

shouldComponentUpdate(nextProps) {
return shouldUpdate(this.props, nextProps, ['children', 'state', 'markingType', 'marking', 'onPress', 'onLongPress', 'date']);
return shouldUpdate(this.props, nextProps, [
'children',
'state',
'markingType',
'marking',
'onPress',
'onLongPress',
'date'
]);
}

onPress = () => {
_.invoke(this.props, 'onPress', this.props.date);
}
};

onLongPress = () => {
_.invoke(this.props, 'onLongPress', this.props.date);
}
};

get marking() {
let marking = this.props.marking || {};
Expand Down Expand Up @@ -107,7 +114,7 @@ export default class BasicDay extends Component {
} else if (this.isToday()) {
style.push(this.style.today);
}

//Custom marking type
if (this.isCustom() && customStyles && customStyles.container) {
if (customStyles.container.borderRadius === undefined) {
Expand Down
27 changes: 17 additions & 10 deletions src/calendar/day/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {SELECT_DATE_SLOT} from '../../testIDs';
import BasicDay from './basic';
import PeriodDay from './period';


const basicDayProps = _.omit(BasicDay.propTypes, 'date');

export default class Day extends Component {
Expand All @@ -27,17 +26,25 @@ export default class Day extends Component {
};

shouldComponentUpdate(nextProps) {
return shouldUpdate(this.props, nextProps, ['day', 'dayComponent', 'state', 'markingType', 'marking', 'onPress', 'onLongPress']);
return shouldUpdate(this.props, nextProps, [
'day',
'dayComponent',
'state',
'markingType',
'marking',
'onPress',
'onLongPress'
]);
}

getMarkingLabel(marking) {
let label = '';

if (marking) {
if (marking.accessibilityLabel) {
return marking.accessibilityLabel;
}

if (marking.selected) {
label += 'selected ';
if (!marking.marked) {
Expand Down Expand Up @@ -91,12 +98,12 @@ export default class Day extends Component {

return (
<Component
{...dayProps}
date={date}
testID={`${SELECT_DATE_SLOT}-${date.dateString}`}
accessibilityLabel={accessibilityLabel}
>
{date ? day.getDate() : day}
{...dayProps}
date={date}
testID={`${SELECT_DATE_SLOT}-${date.dateString}`}
accessibilityLabel={accessibilityLabel}
>
{date ? day.getDate() : day}
</Component>
);
}
Expand Down
34 changes: 16 additions & 18 deletions src/calendar/day/period/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as defaultStyle from '../../../style';
import styleConstructor from './style';
import Dot from '../dot';


export default class PeriodDay extends Component {
static displayName = 'IGNORE';

Expand All @@ -27,17 +26,17 @@ export default class PeriodDay extends Component {

this.theme = {...defaultStyle, ...(props.theme || {})};
this.style = styleConstructor(props.theme);

this.markingStyle = this.getDrawingStyle(props.marking || []);
}

onPress = () => {
this.props.onPress(this.props.date);
}
};

onLongPress = () => {
this.props.onLongPress(this.props.date);
}
};

shouldComponentUpdate(nextProps) {
const newMarkingStyle = this.getDrawingStyle(nextProps.marking);
Expand All @@ -51,7 +50,7 @@ export default class PeriodDay extends Component {

getDrawingStyle(marking) {
const defaultStyle = {textStyle: {}, containerStyle: {}};

if (!marking) {
return defaultStyle;
}
Expand All @@ -62,9 +61,9 @@ export default class PeriodDay extends Component {
defaultStyle.textStyle.color = this.style.selectedText.color;
}

const resultStyle = ([marking]).reduce((prev, next) => {

if (next.quickAction) { //???
const resultStyle = [marking].reduce((prev, next) => {
if (next.quickAction) {
//???
if (next.first || next.last) {
prev.containerStyle = this.style.firstQuickAction;
prev.textStyle = this.style.firstQuickActionText;
Expand All @@ -83,10 +82,11 @@ export default class PeriodDay extends Component {
return prev;
}

if (next.status === 'NotAvailable') { //???
if (next.status === 'NotAvailable') {
//???
prev.textStyle = this.style.naText;
}

const color = next.color;
if (next.startingDay) {
prev.startingDay = {color};
Expand Down Expand Up @@ -185,8 +185,8 @@ export default class PeriodDay extends Component {

fillers = (
<View style={[this.style.fillers, fillerStyle]}>
<View style={[this.style.leftFiller, leftFillerStyle]}/>
<View style={[this.style.rightFiller, rightFillerStyle]}/>
<View style={[this.style.leftFiller, leftFillerStyle]} />
<View style={[this.style.rightFiller, rightFillerStyle]} />
</View>
);
}
Expand All @@ -206,12 +206,10 @@ export default class PeriodDay extends Component {
<View style={this.style.wrapper}>
{fillers}
<View style={containerStyle}>
<Text allowFontScaling={false} style={textStyle}>{String(this.props.children)}</Text>
<Dot
theme={theme}
color={marking?.dotColor}
marked={marking?.marked}
/>
<Text allowFontScaling={false} style={textStyle}>
{String(this.props.children)}
</Text>
<Dot theme={theme} color={marking?.dotColor} marked={marking?.marked} />
</View>
</View>
</TouchableWithoutFeedback>
Expand Down
Loading

0 comments on commit f98d2a8

Please sign in to comment.