11import React , { useState , useCallback } from 'react' ;
2- import { Text , View , StyleSheet } from 'react-native' ;
3- import { ExpandableCalendar , CalendarProvider } from 'react-native-calendars' ;
2+ import { View , Text , Button , StyleSheet } from 'react-native' ;
3+ import { Profiler , Calendar , CalendarList , ExpandableCalendar , CalendarProvider } from 'react-native-calendars' ;
44
5- const INITIAL_DATE = '2019-04-01' ;
5+ const INITIAL_DATE = '2022-07-07' ;
6+ const enum elements {
7+ CALENDAR = 'Calendar' ,
8+ LIST = 'CalendarList' ,
9+ EXPANDABLE = 'Expandable' ,
10+ }
11+ const BLUE = '#00BBF2' ;
612
713export default function PlaygroundScreen ( ) {
814 const [ selectedDate , setSelectedDate ] = useState ( INITIAL_DATE ) ;
15+ const [ element , setElement ] = useState ( elements . LIST ) ;
16+
917
1018 const onDayPress = useCallback ( ( day ) => {
1119 setSelectedDate ( day . dateString ) ;
1220 } , [ selectedDate ] ) ;
1321
14- return (
15- < View style = { styles . container } >
16- < Text style = { styles . text } > Selected Date: { selectedDate } </ Text >
22+ const renderCalendar = ( ) => {
23+ return (
24+ < Calendar
25+ current = { INITIAL_DATE }
26+ style = { styles . calendar }
27+ />
28+ ) ;
29+ } ;
30+
31+ const renderCalendarList = ( ) => {
32+ return (
33+ < CalendarList
34+ current = { INITIAL_DATE }
35+ style = { styles . calendar }
36+ horizontal
37+ />
38+ ) ;
39+ } ;
40+
41+ const renderExpendableCalendar = ( ) => {
42+ return (
1743 < CalendarProvider date = { INITIAL_DATE } >
1844 < ExpandableCalendar
1945 pastScrollRange = { 3 }
@@ -23,22 +49,50 @@ export default function PlaygroundScreen() {
2349 style = { styles . calendar }
2450 />
2551 </ CalendarProvider >
26- </ View >
52+ ) ;
53+ } ;
54+
55+ const renderElement = ( ) => {
56+ switch ( element ) {
57+ case elements . CALENDAR :
58+ return renderCalendar ( ) ;
59+ case elements . LIST :
60+ return renderCalendarList ( ) ;
61+ case elements . EXPANDABLE :
62+ return renderExpendableCalendar ( ) ;
63+ default :
64+ return renderCalendar ( ) ;
65+ }
66+ } ;
67+
68+ return (
69+ < >
70+ < View style = { styles . buttonsContainer } >
71+ < Button color = { BLUE } title = 'Calendar' onPress = { ( ) => setElement ( elements . CALENDAR ) } />
72+ < Button color = { BLUE } title = 'Calendar List' onPress = { ( ) => setElement ( elements . LIST ) } />
73+ < Button color = { BLUE } title = 'Expandable' onPress = { ( ) => setElement ( elements . EXPANDABLE ) } />
74+ </ View >
75+ < Text style = { styles . text } > Selected Date: { selectedDate } </ Text >
76+ < Profiler id = { element } >
77+ { renderElement ( ) }
78+ </ Profiler >
79+ </ >
2780 ) ;
2881}
2982
3083const styles = StyleSheet . create ( {
31- container : {
32- flex : 1
84+ buttonsContainer : {
85+ padding : 5 ,
86+ flexDirection : 'row' ,
87+ justifyContent : 'space-between'
3388 } ,
3489 calendar : {
3590 borderWidth : 1 ,
3691 borderColor : '#b6c1cd'
3792 } ,
3893 text : {
39- marginLeft : 10 ,
94+ alignSelf : 'center' ,
4095 padding : 20 ,
41- color : '#00BBF2' ,
4296 fontSize : 16
4397 }
4498} ) ;
0 commit comments