1
- import React , { Fragment , useCallback , useRef } from 'react' ;
2
- import { TouchableOpacity , Text , View , ViewProps } from 'react-native' ;
3
- import { xdateToData } from '../../../interface' ;
4
- import { Theme , DayState , MarkingTypes , DateData } from '../../../types' ;
5
- import Marking , { MarkingProps } from '../marking' ;
1
+ import React , { Fragment , useCallback , useRef } from 'react' ;
2
+ import { TouchableOpacity , Text , View , ViewProps } from 'react-native' ;
3
+ import { xdateToData } from '../../../interface' ;
4
+ import { Theme , DayState , MarkingTypes , DateData } from '../../../types' ;
5
+ import Marking , { MarkingProps } from '../marking' ;
6
6
import styleConstructor from './style' ;
7
7
8
8
@@ -31,24 +31,10 @@ export interface BasicDayProps extends ViewProps {
31
31
testID ?: string ;
32
32
}
33
33
34
- const BasicDay = ( props : BasicDayProps ) => {
35
- const {
36
- theme,
37
- date,
38
- onPress,
39
- onLongPress,
40
- markingType,
41
- marking,
42
- state,
43
- disableAllTouchEventsForDisabledDays,
44
- disableAllTouchEventsForInactiveDays,
45
- accessibilityLabel,
46
- children,
47
- testID
48
- } = props ;
34
+ const BasicDay = ( props ) => {
35
+ const { theme, date, onPress, onLongPress, markingType, marking, state, disableAllTouchEventsForDisabledDays, disableAllTouchEventsForInactiveDays, accessibilityLabel, children, testID } = props ;
49
36
const dateData = date ? xdateToData ( date ) : undefined ;
50
37
const style = useRef ( styleConstructor ( theme ) ) ;
51
-
52
38
const _marking = marking || { } ;
53
39
const isSelected = _marking . selected || state === 'selected' ;
54
40
const isDisabled = typeof _marking . disabled !== 'undefined' ? _marking . disabled : state === 'disabled' ;
@@ -57,143 +43,101 @@ const BasicDay = (props: BasicDayProps) => {
57
43
const isMultiDot = markingType === Marking . markings . MULTI_DOT ;
58
44
const isMultiPeriod = markingType === Marking . markings . MULTI_PERIOD ;
59
45
const isCustom = markingType === Marking . markings . CUSTOM ;
60
-
61
46
const shouldDisableTouchEvent = ( ) => {
62
- const { disableTouchEvent} = _marking ;
47
+ const { disableTouchEvent } = _marking ;
63
48
let disableTouch = false ;
64
-
65
49
if ( typeof disableTouchEvent === 'boolean' ) {
66
50
disableTouch = disableTouchEvent ;
67
- } else if ( typeof disableAllTouchEventsForDisabledDays === 'boolean' && isDisabled ) {
51
+ }
52
+ else if ( typeof disableAllTouchEventsForDisabledDays === 'boolean' && isDisabled ) {
68
53
disableTouch = disableAllTouchEventsForDisabledDays ;
69
- } else if ( typeof disableAllTouchEventsForInactiveDays === 'boolean' && isInactive ) {
54
+ }
55
+ else if ( typeof disableAllTouchEventsForInactiveDays === 'boolean' && isInactive ) {
70
56
disableTouch = disableAllTouchEventsForInactiveDays ;
71
57
}
72
58
return disableTouch ;
73
59
} ;
74
-
75
60
const getContainerStyle = ( ) => {
76
- const { customStyles, selectedColor} = _marking ;
61
+ const { customStyles, selectedColor } = _marking ;
77
62
const styles = [ style . current . base ] ;
78
-
79
63
if ( isSelected ) {
80
64
styles . push ( style . current . selected ) ;
81
65
if ( selectedColor ) {
82
- styles . push ( { backgroundColor : selectedColor } ) ;
66
+ styles . push ( { backgroundColor : selectedColor } ) ;
83
67
}
84
- } else if ( isToday ) {
68
+ }
69
+ else if ( isToday ) {
85
70
styles . push ( style . current . today ) ;
86
71
}
87
-
88
72
//Custom marking type
89
73
if ( isCustom && customStyles && customStyles . container ) {
90
74
if ( customStyles . container . borderRadius === undefined ) {
91
75
customStyles . container . borderRadius = 16 ;
92
76
}
93
77
styles . push ( customStyles . container ) ;
94
78
}
95
-
96
79
return styles ;
97
80
} ;
98
-
99
81
const getTextStyle = ( ) => {
100
- const { customStyles, selectedTextColor} = _marking ;
82
+ const { customStyles, selectedTextColor } = _marking ;
101
83
const styles = [ style . current . text ] ;
102
-
103
84
if ( isSelected ) {
104
85
styles . push ( style . current . selectedText ) ;
105
86
if ( selectedTextColor ) {
106
- styles . push ( { color : selectedTextColor } ) ;
87
+ styles . push ( { color : selectedTextColor } ) ;
107
88
}
108
- } else if ( isDisabled ) {
89
+ }
90
+ else if ( isDisabled ) {
109
91
styles . push ( style . current . disabledText ) ;
110
- } else if ( isToday ) {
92
+ }
93
+ else if ( isToday ) {
111
94
styles . push ( style . current . todayText ) ;
112
- } else if ( isInactive ) {
95
+ }
96
+ else if ( isInactive ) {
113
97
styles . push ( style . current . inactiveText ) ;
114
98
}
115
-
116
99
// Custom marking type
117
100
if ( isCustom && customStyles && customStyles . text ) {
118
101
styles . push ( customStyles . text ) ;
119
102
}
120
-
121
103
return styles ;
122
104
} ;
123
-
124
105
const _onPress = useCallback ( ( ) => {
125
106
onPress ?.( dateData ) ;
126
107
} , [ onPress , date ] ) ;
127
-
128
108
const _onLongPress = useCallback ( ( ) => {
129
109
onLongPress ?.( dateData ) ;
130
110
} , [ onLongPress , date ] ) ;
131
-
132
111
const renderMarking = ( ) => {
133
- const { marked, dotColor, dots, periods} = _marking ;
134
-
135
- return (
136
- < Marking
137
- type = { markingType }
138
- theme = { theme }
139
- marked = { isMultiDot ? true : marked }
140
- selected = { isSelected }
141
- disabled = { isDisabled }
142
- inactive = { isInactive }
143
- today = { isToday }
144
- dotColor = { dotColor }
145
- dots = { dots }
146
- periods = { periods }
147
- />
148
- ) ;
112
+ const { marked, dotColor, dots, periods } = _marking ;
113
+ // if marking is not set or is multi dot, return null
114
+ // we are doing this as it takes the space in bottom of day making text move upwards.
115
+ if ( ! marked || isMultiDot ) return null ;
116
+ return ( < Marking type = { markingType } theme = { theme } marked = { isMultiDot ? true : marked } selected = { isSelected } disabled = { isDisabled } inactive = { isInactive } today = { isToday } dotColor = { dotColor } dots = { dots } periods = { periods } /> ) ;
149
117
} ;
150
-
151
118
const renderText = ( ) => {
152
- return (
153
- < Text allowFontScaling = { false } style = { getTextStyle ( ) } testID = { `${ testID } .text` } >
154
- { String ( children ) }
155
- </ Text >
156
- ) ;
119
+ return ( < Text allowFontScaling = { false } style = { getTextStyle ( ) } testID = { `${ testID } .text` } >
120
+ { String ( children ) }
121
+ </ Text > ) ;
157
122
} ;
158
-
159
123
const renderContent = ( ) => {
160
- return (
161
- < Fragment >
162
- { renderText ( ) }
163
- { renderMarking ( ) }
164
- </ Fragment >
165
- ) ;
124
+ return ( < Fragment >
125
+ { renderText ( ) }
126
+ { renderMarking ( ) }
127
+ </ Fragment > ) ;
166
128
} ;
167
-
168
129
const renderContainer = ( ) => {
169
- const { activeOpacity} = _marking ;
170
-
171
- return (
172
- < TouchableOpacity
173
- testID = { testID }
174
- style = { getContainerStyle ( ) }
175
- activeOpacity = { activeOpacity }
176
- disabled = { shouldDisableTouchEvent ( ) }
177
- onPress = { ! shouldDisableTouchEvent ( ) ? _onPress : undefined }
178
- onLongPress = { ! shouldDisableTouchEvent ( ) ? _onLongPress : undefined }
179
- accessible
180
- accessibilityRole = { isDisabled ? undefined : 'button' }
181
- accessibilityLabel = { accessibilityLabel }
182
- >
183
- { isMultiPeriod ? renderText ( ) : renderContent ( ) }
184
- </ TouchableOpacity >
185
- ) ;
130
+ const { activeOpacity } = _marking ;
131
+ return ( < TouchableOpacity testID = { testID } style = { getContainerStyle ( ) } activeOpacity = { activeOpacity } disabled = { shouldDisableTouchEvent ( ) } onPress = { ! shouldDisableTouchEvent ( ) ? _onPress : undefined } onLongPress = { ! shouldDisableTouchEvent ( ) ? _onLongPress : undefined } accessible accessibilityRole = { isDisabled ? undefined : 'button' } accessibilityLabel = { accessibilityLabel } >
132
+ { isMultiPeriod ? renderText ( ) : renderContent ( ) }
133
+ </ TouchableOpacity > ) ;
186
134
} ;
187
-
188
135
const renderPeriodsContainer = ( ) => {
189
- return (
190
- < View style = { style . current . container } >
191
- { renderContainer ( ) }
192
- { renderMarking ( ) }
193
- </ View >
194
- ) ;
136
+ return ( < View style = { style . current . container } >
137
+ { renderContainer ( ) }
138
+ { renderMarking ( ) }
139
+ </ View > ) ;
195
140
} ;
196
-
197
141
return isMultiPeriod ? renderPeriodsContainer ( ) : renderContainer ( ) ;
198
142
} ;
199
143
0 commit comments