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 ( 'Calendar' ) ;
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+ />
37+ ) ;
38+ } ;
39+
40+ const renderExpendableCalendar = ( ) => {
41+ return (
1742 < CalendarProvider date = { INITIAL_DATE } >
1843 < ExpandableCalendar
1944 pastScrollRange = { 3 }
@@ -23,22 +48,50 @@ export default function PlaygroundScreen() {
2348 style = { styles . calendar }
2449 />
2550 </ CalendarProvider >
26- </ View >
51+ ) ;
52+ } ;
53+
54+ const renderElement = ( ) => {
55+ switch ( element ) {
56+ case elements . CALENDAR :
57+ return renderCalendar ( ) ;
58+ case elements . LIST :
59+ return renderCalendarList ( ) ;
60+ case elements . EXPANDABLE :
61+ return renderExpendableCalendar ( ) ;
62+ default :
63+ return renderCalendar ( ) ;
64+ }
65+ } ;
66+
67+ return (
68+ < >
69+ < View style = { styles . buttonsContainer } >
70+ < Button color = { BLUE } title = 'Calendar' onPress = { ( ) => setElement ( elements . CALENDAR ) } />
71+ < Button color = { BLUE } title = 'Calendar List' onPress = { ( ) => setElement ( elements . LIST ) } />
72+ < Button color = { BLUE } title = 'Expandable' onPress = { ( ) => setElement ( elements . EXPANDABLE ) } />
73+ </ View >
74+ < Text style = { styles . text } > Selected Date: { selectedDate } </ Text >
75+ < Profiler id = { element } >
76+ { renderElement ( ) }
77+ </ Profiler >
78+ </ >
2779 ) ;
2880}
2981
3082const styles = StyleSheet . create ( {
31- container : {
32- flex : 1
83+ buttonsContainer : {
84+ padding : 5 ,
85+ flexDirection : 'row' ,
86+ justifyContent : 'space-between'
3387 } ,
3488 calendar : {
3589 borderWidth : 1 ,
3690 borderColor : '#b6c1cd'
3791 } ,
3892 text : {
39- marginLeft : 10 ,
93+ alignSelf : 'center' ,
4094 padding : 20 ,
41- color : '#00BBF2' ,
4295 fontSize : 16
4396 }
4497} ) ;
0 commit comments