|
1 | 1 | import times from 'lodash/times'; |
2 | | -import React, {useState, Fragment, useCallback, useMemo, useRef} from 'react'; |
| 2 | +import React, {useState, useCallback, useMemo, useRef} from 'react'; |
3 | 3 | import {StyleSheet, View, ScrollView, Text, TouchableOpacity, Switch, Alert} from 'react-native'; |
4 | 4 | import {Calendar, CalendarUtils} from 'react-native-calendars'; |
| 5 | + |
5 | 6 | import testIDs from '../testIDs'; |
| 7 | +import Marking from '../../../src/calendar/day/marking'; |
6 | 8 |
|
7 | 9 | const INITIAL_DATE = '2022-07-06'; |
8 | 10 | const GREEN = '#13ba7d'; |
9 | 11 | const PINK = '#a68a9f'; |
10 | 12 | const RED = '#ba1313'; |
11 | | -enum Markings { |
12 | | - DOT = 'dot', |
13 | | - MULTI_DOT = 'multi-dot', |
14 | | - PERIOD = 'period', |
15 | | - MULTI_PERIOD = 'multi-period', |
16 | | - CUSTOM = 'custom' |
17 | | -} |
18 | 13 |
|
19 | 14 | const NewCalendarScreen = () => { |
20 | 15 | const [selected, setSelected] = useState(INITIAL_DATE); |
21 | 16 | const [currentMonth, setCurrentMonth] = useState(INITIAL_DATE); |
22 | | - const [markingType, setMarkingType] = useState(Markings.DOT); |
| 17 | + const [markingType, setMarkingType] = useState(Marking.markings.DOT); |
23 | 18 | const [selectedButtonIndex, setSelectedButtonIndex] = useState(0); |
24 | 19 |
|
25 | 20 | /** props */ |
@@ -91,16 +86,20 @@ const NewCalendarScreen = () => { |
91 | 86 |
|
92 | 87 | const dotMarks = useMemo(() => { |
93 | 88 | return { |
| 89 | + [getDate(1)]: { |
| 90 | + disabled: true, |
| 91 | + dotColor: RED, |
| 92 | + marked: true |
| 93 | + }, |
| 94 | + [getDate(2)]: { |
| 95 | + dotColor: RED, |
| 96 | + marked: true |
| 97 | + }, |
94 | 98 | [selected]: { |
95 | 99 | selected: true, |
96 | 100 | disableTouchEvent: true, |
97 | 101 | selectedColor: PINK, |
98 | 102 | selectedTextColor: RED |
99 | | - }, |
100 | | - [getDate(1)]: { |
101 | | - disabled: true, |
102 | | - dotColor: RED, |
103 | | - marked: true |
104 | 103 | } |
105 | 104 | }; |
106 | 105 | }, [selected]); |
@@ -289,15 +288,15 @@ const NewCalendarScreen = () => { |
289 | 288 |
|
290 | 289 | const markingForType = useCallback(() => { |
291 | 290 | switch (markingType) { |
292 | | - case Markings.DOT: |
| 291 | + case Marking.markings.DOT: |
293 | 292 | return dotMarks; |
294 | | - case Markings.MULTI_DOT: |
| 293 | + case Marking.markings.MULTI_DOT: |
295 | 294 | return multiDotMarks; |
296 | | - case Markings.PERIOD: |
| 295 | + case Marking.markings.PERIOD: |
297 | 296 | return periodWithDotsMarks; //periodMarks; |
298 | | - case Markings.MULTI_PERIOD: |
| 297 | + case Marking.markings.MULTI_PERIOD: |
299 | 298 | return multiPeriodMarks; |
300 | | - case Markings.CUSTOM: |
| 299 | + case Marking.markings.CUSTOM: |
301 | 300 | return customMarks; |
302 | 301 | } |
303 | 302 | }, [markingType, selected]); |
@@ -450,32 +449,36 @@ const NewCalendarScreen = () => { |
450 | 449 | return ( |
451 | 450 | <View> |
452 | 451 | {renderSwitch('Min and Max Dates', minAndMax, toggleMinAndMax)} |
453 | | - {renderSwitch('Allow Selection Out Of Range', allowSelectionOutOfRange, toggleAllowSelectionOutOfRange)} |
| 452 | + <View style={styles.subSwitchContainer}> |
| 453 | + {minAndMax && renderSwitch('Allow Selection Out Of Range', allowSelectionOutOfRange, toggleAllowSelectionOutOfRange)} |
| 454 | + </View> |
454 | 455 | {renderSwitch('Enable Swipe Months', enableSwipeMonths, toggleEnableSwipeMonths)} |
455 | 456 | {renderSwitch('Disable Month Change', disableMonthChange, toggleDisableMonthChange)} |
456 | 457 | {renderSwitch('Show Week Numbers', showWeekNumbers, toggleShowWeekNumbers)} |
457 | 458 | {renderSwitch('Show Six Weeks', showSixWeeks, toggleShowSixWeeks)} |
458 | 459 | {renderSwitch('Hide Extra Days', hideExtraDays, toggleHideExtraDays)} |
459 | 460 | {renderSwitch('Hide Day Names', hideDayNames, toggleHideDayNames)} |
460 | | - {renderSwitch('Hide Arrows', hideArrows, toggleHideArrows)} |
461 | 461 | {renderSwitch('Disabled By Default', disabledByDefault, toggleDisabledByDefault)} |
462 | 462 | {renderSwitch('Disable All Touch Events For Disabled Days', disableAllTouchEventsForDisabledDays, toggleDisableAllTouchEventsForDisabledDays)} |
463 | 463 | {renderSwitch('Disable All Touch Events For Inactive Days', disableAllTouchEventsForInactiveDays, toggleDisableAllTouchEventsForInactiveDays)} |
464 | 464 | {renderSwitch('Display Loading Indicator', displayLoadingIndicator, toggleDisplayLoadingIndicator)} |
465 | 465 | {renderSwitch('Disabled Days Indexes', disabledDaysIndexes, toggleDisabledDaysIndexes)} |
| 466 | + {renderSwitch('Hide Arrows', hideArrows, toggleHideArrows)} |
| 467 | + <View style={styles.subSwitchContainer}> |
| 468 | + {!hideArrows && renderSwitch('Disable Arrow Left', disableArrowLeft, toggleDisableArrowLeft)} |
| 469 | + {!hideArrows && renderSwitch('Disable Arrow Right', disableArrowRight, toggleDisableArrowRight)} |
| 470 | + {!hideArrows && renderSwitch('Render Arrow', renderArrow, toggleRenderArrow)} |
| 471 | + </View> |
466 | 472 | {renderSwitch('Day Component', dayComponent, toggleDayComponent)} |
467 | 473 | {renderSwitch('Custom Header', customHeader, toggleCustomHeader)} |
468 | 474 | {renderSwitch('Custom Header Title', customHeaderTitle, toggleCustomHeaderTitle)} |
469 | | - {renderSwitch('Render Arrow', renderArrow, toggleRenderArrow)} |
470 | | - {renderSwitch('Disable Arrow Left', disableArrowLeft, toggleDisableArrowLeft)} |
471 | | - {renderSwitch('Disable Arrow Right', disableArrowRight, toggleDisableArrowRight)} |
472 | 475 | </View> |
473 | 476 | ); |
474 | 477 | }; |
475 | 478 |
|
476 | 479 | /** Buttons */ |
477 | 480 | const getValue = (index = 0) => { |
478 | | - return Object.values(Markings)[index]; |
| 481 | + return Object.values(Marking.markings)[index]; |
479 | 482 | }; |
480 | 483 |
|
481 | 484 | const setType = (index = 0) => { |
@@ -528,12 +531,12 @@ const NewCalendarScreen = () => { |
528 | 531 | }; |
529 | 532 |
|
530 | 533 | return ( |
531 | | - <Fragment> |
| 534 | + <> |
532 | 535 | {renderCalendar()} |
533 | 536 | <ScrollView showsVerticalScrollIndicator={false} testID={testIDs.calendars.CONTAINER}> |
534 | 537 | {renderOptions()} |
535 | 538 | </ScrollView> |
536 | | - </Fragment> |
| 539 | + </> |
537 | 540 | ); |
538 | 541 | }; |
539 | 542 |
|
@@ -578,6 +581,9 @@ const styles = StyleSheet.create({ |
578 | 581 | switchText: { |
579 | 582 | marginHorizontal: 10 |
580 | 583 | }, |
| 584 | + subSwitchContainer: { |
| 585 | + marginLeft: 20 |
| 586 | + }, |
581 | 587 | buttonsContainer: { |
582 | 588 | margin: 10 |
583 | 589 | }, |
|
0 commit comments