|
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 */ |
@@ -289,15 +284,15 @@ const NewCalendarScreen = () => { |
289 | 284 |
|
290 | 285 | const markingForType = useCallback(() => { |
291 | 286 | switch (markingType) { |
292 | | - case Markings.DOT: |
| 287 | + case Marking.markings.DOT: |
293 | 288 | return dotMarks; |
294 | | - case Markings.MULTI_DOT: |
| 289 | + case Marking.markings.MULTI_DOT: |
295 | 290 | return multiDotMarks; |
296 | | - case Markings.PERIOD: |
| 291 | + case Marking.markings.PERIOD: |
297 | 292 | return periodWithDotsMarks; //periodMarks; |
298 | | - case Markings.MULTI_PERIOD: |
| 293 | + case Marking.markings.MULTI_PERIOD: |
299 | 294 | return multiPeriodMarks; |
300 | | - case Markings.CUSTOM: |
| 295 | + case Marking.markings.CUSTOM: |
301 | 296 | return customMarks; |
302 | 297 | } |
303 | 298 | }, [markingType, selected]); |
@@ -450,32 +445,36 @@ const NewCalendarScreen = () => { |
450 | 445 | return ( |
451 | 446 | <View> |
452 | 447 | {renderSwitch('Min and Max Dates', minAndMax, toggleMinAndMax)} |
453 | | - {renderSwitch('Allow Selection Out Of Range', allowSelectionOutOfRange, toggleAllowSelectionOutOfRange)} |
| 448 | + <View style={styles.subSwitchContainer}> |
| 449 | + {minAndMax && renderSwitch('Allow Selection Out Of Range', allowSelectionOutOfRange, toggleAllowSelectionOutOfRange)} |
| 450 | + </View> |
454 | 451 | {renderSwitch('Enable Swipe Months', enableSwipeMonths, toggleEnableSwipeMonths)} |
455 | 452 | {renderSwitch('Disable Month Change', disableMonthChange, toggleDisableMonthChange)} |
456 | 453 | {renderSwitch('Show Week Numbers', showWeekNumbers, toggleShowWeekNumbers)} |
457 | 454 | {renderSwitch('Show Six Weeks', showSixWeeks, toggleShowSixWeeks)} |
458 | 455 | {renderSwitch('Hide Extra Days', hideExtraDays, toggleHideExtraDays)} |
459 | 456 | {renderSwitch('Hide Day Names', hideDayNames, toggleHideDayNames)} |
460 | | - {renderSwitch('Hide Arrows', hideArrows, toggleHideArrows)} |
461 | 457 | {renderSwitch('Disabled By Default', disabledByDefault, toggleDisabledByDefault)} |
462 | 458 | {renderSwitch('Disable All Touch Events For Disabled Days', disableAllTouchEventsForDisabledDays, toggleDisableAllTouchEventsForDisabledDays)} |
463 | 459 | {renderSwitch('Disable All Touch Events For Inactive Days', disableAllTouchEventsForInactiveDays, toggleDisableAllTouchEventsForInactiveDays)} |
464 | 460 | {renderSwitch('Display Loading Indicator', displayLoadingIndicator, toggleDisplayLoadingIndicator)} |
465 | 461 | {renderSwitch('Disabled Days Indexes', disabledDaysIndexes, toggleDisabledDaysIndexes)} |
| 462 | + {renderSwitch('Hide Arrows', hideArrows, toggleHideArrows)} |
| 463 | + <View style={styles.subSwitchContainer}> |
| 464 | + {!hideArrows && renderSwitch('Disable Arrow Left', disableArrowLeft, toggleDisableArrowLeft)} |
| 465 | + {!hideArrows && renderSwitch('Disable Arrow Right', disableArrowRight, toggleDisableArrowRight)} |
| 466 | + {!hideArrows && renderSwitch('Render Arrow', renderArrow, toggleRenderArrow)} |
| 467 | + </View> |
466 | 468 | {renderSwitch('Day Component', dayComponent, toggleDayComponent)} |
467 | 469 | {renderSwitch('Custom Header', customHeader, toggleCustomHeader)} |
468 | 470 | {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 | 471 | </View> |
473 | 472 | ); |
474 | 473 | }; |
475 | 474 |
|
476 | 475 | /** Buttons */ |
477 | 476 | const getValue = (index = 0) => { |
478 | | - return Object.values(Markings)[index]; |
| 477 | + return Object.values(Marking.markings)[index]; |
479 | 478 | }; |
480 | 479 |
|
481 | 480 | const setType = (index = 0) => { |
@@ -528,12 +527,12 @@ const NewCalendarScreen = () => { |
528 | 527 | }; |
529 | 528 |
|
530 | 529 | return ( |
531 | | - <Fragment> |
| 530 | + <> |
532 | 531 | {renderCalendar()} |
533 | 532 | <ScrollView showsVerticalScrollIndicator={false} testID={testIDs.calendars.CONTAINER}> |
534 | 533 | {renderOptions()} |
535 | 534 | </ScrollView> |
536 | | - </Fragment> |
| 535 | + </> |
537 | 536 | ); |
538 | 537 | }; |
539 | 538 |
|
@@ -578,6 +577,9 @@ const styles = StyleSheet.create({ |
578 | 577 | switchText: { |
579 | 578 | marginHorizontal: 10 |
580 | 579 | }, |
| 580 | + subSwitchContainer: { |
| 581 | + marginLeft: 20 |
| 582 | + }, |
581 | 583 | buttonsContainer: { |
582 | 584 | margin: 10 |
583 | 585 | }, |
|
0 commit comments