Skip to content

Commit 09dc547

Browse files
authored
style(Calendar): 修改Calendar组件安卓样式问题 #382 (#391)
1 parent 04b0a36 commit 09dc547

File tree

1 file changed

+51
-39
lines changed

1 file changed

+51
-39
lines changed

packages/core/src/Calendar/index.tsx

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ const Calendar = (props: CalendarProps) => {
6666
render
6767
) : (
6868
<View style={[styles.header, { backgroundColor: color }]}>
69-
<TouchableOpacity onPress={() => onPressBarLeft && onPressBarLeft()}>
69+
<TouchableOpacity style={styles.headerBtnWrap} onPress={() => onPressBarLeft && onPressBarLeft()}>
7070
<View style={styles.headerBtn}>
7171
<Icon name="left" size={20} color={'#fff'} />
7272
<Text style={styles.headerText}>{barRightText}</Text>
7373
</View>
7474
</TouchableOpacity>
75-
<View>
75+
<View style={styles.headerTextWrap}>
7676
<Text style={styles.headerText}>{title}</Text>
7777
</View>
78-
<TouchableOpacity onPress={() => goToday()}>
78+
<TouchableOpacity style={styles.headerTextTouch} onPress={() => goToday()}>
7979
<Text style={styles.headerText}>{barLeftText}</Text>
8080
</TouchableOpacity>
8181
</View>
@@ -125,40 +125,42 @@ const Calendar = (props: CalendarProps) => {
125125
key={index}
126126
style={
127127
lunarAll.type === 1
128-
? styles.otherMonth
128+
? [styles.dateBase, styles.otherMonth]
129129
: lunarAll.type === 2
130-
? [styles.currentMonth, { backgroundColor: color }]
130+
? [styles.currentMonth, styles.dateBase, { backgroundColor: color }]
131131
: lunarAll.type === 3
132-
? [styles.selectMonth, { borderColor: color }]
133-
: styles.day
132+
? [styles.selectMonth, styles.dateBase, { borderColor: color }]
133+
: styles.dateBase
134134
}
135135
onPress={() => goSelectDay(day)}
136136
>
137-
<Text
138-
style={[
139-
styles.dayText,
140-
{
141-
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : '#000',
142-
lineHeight: lineHeight,
143-
paddingTop: paddingTop,
144-
},
145-
]}
146-
>
147-
{day.monthDays}
148-
</Text>
149-
{lunarHoliday === true && (
137+
<View>
150138
<Text
151139
style={[
152140
styles.dayText,
153141
{
154-
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : colorType,
155-
fontSize: 13,
142+
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : '#000',
143+
lineHeight: lineHeight,
144+
paddingTop: paddingTop,
156145
},
157146
]}
158147
>
159-
{nameLen > 3 ? <Ellipsis maxLen={2}>{day.lunarHolidays}</Ellipsis> : day.lunarHolidays || day.lunar}
148+
{day.monthDays}
160149
</Text>
161-
)}
150+
{lunarHoliday === true && (
151+
<Text
152+
style={[
153+
styles.dayText,
154+
{
155+
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : colorType,
156+
fontSize: 13,
157+
},
158+
]}
159+
>
160+
{nameLen > 3 ? <Ellipsis maxLen={2}>{day.lunarHolidays}</Ellipsis> : day.lunarHolidays || day.lunar}
161+
</Text>
162+
)}
163+
</View>
162164
</TouchableOpacity>
163165
);
164166
});
@@ -249,16 +251,29 @@ const Calendar = (props: CalendarProps) => {
249251
const styles = StyleSheet.create({
250252
header: {
251253
flex: 1,
254+
display: 'flex',
252255
backgroundColor: '#329BCB',
253256
flexDirection: 'row',
254257
padding: 10,
255258
alignItems: 'center',
256259
justifyContent: 'space-between',
257260
},
261+
headerBtnWrap: {
262+
flex: 1,
263+
},
258264
headerBtn: {
259265
flexDirection: 'row',
260266
alignItems: 'center',
261-
width: 50,
267+
// width: 50,
268+
},
269+
headerTextWrap: {
270+
flex: 1,
271+
alignItems: 'center',
272+
},
273+
headerTextTouch: {
274+
flex: 1,
275+
display: 'flex',
276+
flexDirection: 'row-reverse',
262277
},
263278
headerText: {
264279
fontSize: 20,
@@ -299,31 +314,28 @@ const styles = StyleSheet.create({
299314
flexDirection: 'row',
300315
paddingHorizontal: 2,
301316
},
302-
currentMonth: {
303-
backgroundColor: '#329BCB',
304-
borderRadius: 50,
317+
dateBase: {
305318
marginHorizontal: 2,
306319
width: MainWidth / 7 - 4.5,
307320
height: MainWidth / 7 - 4.5,
321+
...Platform.select({
322+
ios: {},
323+
android: {
324+
justifyContent: 'center',
325+
},
326+
}),
327+
},
328+
currentMonth: {
329+
backgroundColor: '#329BCB',
330+
borderRadius: 50,
308331
},
309332
selectMonth: {
310333
borderWidth: 1,
311334
borderColor: '#329BCB',
312335
borderRadius: 50,
313-
marginHorizontal: 2,
314-
width: MainWidth / 7 - 4.5,
315-
height: MainWidth / 7 - 4.5,
316336
},
317337
otherMonth: {
318338
borderRadius: 50,
319-
marginHorizontal: 2,
320-
width: MainWidth / 7 - 4.5,
321-
height: MainWidth / 7 - 4.5,
322-
},
323-
day: {
324-
marginHorizontal: 2,
325-
width: MainWidth / 7 - 4.5,
326-
height: MainWidth / 7 - 4.5,
327339
},
328340
dayText: {
329341
textAlign: 'center',

0 commit comments

Comments
 (0)