Skip to content

Commit be47772

Browse files
Amber-Nan杨楠
andauthored
feat(Calendar):增加农历详情展示 & 文档更新 (#340)
* fix(Divider):优化 gutter属性不生效问题 * feat(Divider): 增加分割线标题的位置调整功能 & 更新文档 * feat(Rating):增加自定义每项的提示信息 & 更新文档 * feat(Rating):增加只读功能 & 文档更新 * feat(Timeline): 增加改变时间轴内容相对位置功能 & 文档更新 * style(Timeline):Update Readme.md img * feat(Timeline):增加自定义图标 & 文档更新 * feat(Timeline):优化自定义图标 & 文档更新 * feat:新增Calendar 日历组件 * doc(website): Update Calendar Readme.md * feat(Calendar):增加农历及假期展示 && 文档更新 * feat(Calendar):增加假日文字颜色 * feat(Calendar):左上角按钮增加自定义跳转功能&文档更新 * feat(Calendar):优化农历假日及文字排版 * feat(Calendar):处理文字长度 * fix(Calendar):优化安卓文字排版 * feat(Calendar):增加农历详情展示 & 文档更新 * feat(DragDrawer):新增DragDrawer 拖曳抽屉 & 文档更新 Co-authored-by: 杨楠 <[email protected]>
1 parent fa671eb commit be47772

File tree

12 files changed

+416
-55
lines changed

12 files changed

+416
-55
lines changed

example/examples/src/routes.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,4 +466,12 @@ export const stackPageData: Routes[] = [
466466
description: '展示日历',
467467
},
468468
},
469+
{
470+
name: 'DragDrawer',
471+
component: require('./routes/DragDrawer').default,
472+
params: {
473+
title: 'DragDrawer 拖曳抽屉',
474+
description: '可自定义拖曳抽屉高度',
475+
},
476+
},
469477
];

example/examples/src/routes/Calendar/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
2727
<Calendar />
2828
<Spacing size={'large'} />
2929
<Calendar color="red" lunarHoliday={true} />
30-
<Calendar bar={barProps} />
30+
<Spacing size={'large'} />
31+
<Calendar bar={barProps} showLunar={true} />
3132
</Body>
3233
<Footer />
3334
</Layout>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, {useState, Fragment} from 'react';
2+
import {View, Text, Dimensions} from 'react-native';
3+
import {DragDrawer, Card, Button} from '@uiw/react-native';
4+
import Layout, {Container} from '../../Layout';
5+
import {ComProps} from '../../routes';
6+
const {Header, Body, Footer} = Layout;
7+
8+
export interface DragDrawerViewProps extends ComProps {}
9+
export default function DragDrawerView({route}: DragDrawerViewProps) {
10+
const description = route.params.description;
11+
const title = route.params.title;
12+
return (
13+
<Fragment>
14+
<DragDrawer>
15+
<View>
16+
<Text>按住图标可上下拖曳抽屉</Text>
17+
</View>
18+
</DragDrawer>
19+
<Container>
20+
<Layout>
21+
<Header title={title} description={description} />
22+
<Body>
23+
<Card title="下边抽屉可上下拖曳">
24+
<Text>下边抽屉可上下拖曳</Text>
25+
</Card>
26+
</Body>
27+
<Footer />
28+
</Layout>
29+
</Container>
30+
</Fragment>
31+
);
32+
}

packages/core/src/Calendar/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
7171
}
7272
```
7373

74-
### 自定义日历头部
74+
### 自定义日历头部及农历详情展示
7575

7676
```jsx
7777
import React from 'react';
@@ -100,7 +100,7 @@ export default class CalendarView extends React.Component<CalendarViewProps> {
100100
<Layout>
101101
<Header title={title} description={description} />
102102
<Body>
103-
<Calendar color="red" bar={barProps} lunarHoliday={true}/>
103+
<Calendar color="red" bar={barProps} lunarHoliday={true} showLunar={true}/>
104104
</Body>
105105
<Footer />
106106
</Layout>
@@ -134,5 +134,7 @@ export interface CalendarProps extends ViewProps {
134134
//是否显示农历及假日
135135
lunarHoliday: boolean;
136136
bar: barState ;
137+
//农历详情
138+
showLunar: boolean;
137139
}
138140
```

packages/core/src/Calendar/index.tsx

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
import React, { useEffect, useState } from 'react';
22
import { View, Text, ViewProps, TextProps, StyleSheet, TouchableOpacity, Dimensions, Platform } from 'react-native';
3-
import { color } from 'src/utils';
43
import Icon from '../Icon';
54
import Ellipsis from '../Ellipsis';
65
import { getMonths, getWeeksArray, daysArrProps, getType, getNameLen } from './utils';
6+
import ShowDate from './show';
77

88
export let MainWidth = Dimensions.get('window').width;
9+
export let MainHeight = Dimensions.get('window').height;
910
export let newDates = new Date();
1011
export let toYear = newDates.getFullYear();
1112
export let toMonth = newDates.getMonth();
1213
export let toDays = newDates.getDate();
13-
1414
interface barState {
1515
title?: string;
1616
barRightText?: string;
1717
barLeftText?: string;
1818
onPressBarLeft?: () => void;
1919
render?: React.ReactNode;
2020
}
21+
2122
export interface CalendarProps extends ViewProps {
2223
// 日历颜色
2324
color: string;
2425
//是否显示农历及假日
2526
lunarHoliday: boolean;
2627
bar?: barState;
28+
//农历详情
29+
showLunar: boolean;
2730
}
31+
2832
const Calendar = (props: CalendarProps) => {
2933
const bars = {
3034
barRightText: 'Menu',
@@ -33,15 +37,15 @@ const Calendar = (props: CalendarProps) => {
3337
onPressBarLeft: undefined,
3438
render: undefined,
3539
};
36-
const { color = '#329BCB', lunarHoliday = false, bar = bars } = props;
40+
const { color = '#329BCB', lunarHoliday = false, bar = bars, showLunar = false } = props;
3741
const { barRightText, title, barLeftText, onPressBarLeft, render } = bar;
38-
3942
const [currentYear, setCurrentYear] = useState<number>(toYear);
4043
const [currentMonth, setCurrentMonth] = useState<number>(toMonth);
4144
const [currentDays, setCurrentDays] = useState<number>(toDays);
4245
const [dayData, setDayData] = useState<number[]>([]);
4346
const [lastData, setLastData] = useState<number[]>([]);
4447
const [nextData, setNextData] = useState<number[]>([]);
48+
const [lunarName, setLunarName] = useState('');
4549

4650
useEffect(() => {
4751
let toMonths = getMonths(currentYear, currentMonth, currentDays);
@@ -98,9 +102,14 @@ const Calendar = (props: CalendarProps) => {
98102
);
99103
});
100104
};
105+
101106
const renderDays = (weekDays: daysArrProps[]) => {
102107
return weekDays.map((day, index) => {
103-
let type = getType(day, currentYear, currentMonth, currentDays, toYear, toMonth, toDays);
108+
let lunarAll = getType(day, currentYear, currentMonth, currentDays, toYear, toMonth, toDays);
109+
if (lunarAll.lunarShow !== '' && lunarName === '') {
110+
setLunarName(lunarAll.lunarShow);
111+
}
112+
104113
let nameLen = getNameLen(day.lunarHolidays);
105114
let lineHeight =
106115
lunarHoliday === true && Platform.OS === 'ios' ? 0 : lunarHoliday === true ? 18 : MainWidth / 7 - 4.5;
@@ -115,11 +124,11 @@ const Calendar = (props: CalendarProps) => {
115124
<TouchableOpacity
116125
key={index}
117126
style={
118-
type === 1
127+
lunarAll.type === 1
119128
? styles.otherMonth
120-
: type === 2
129+
: lunarAll.type === 2
121130
? [styles.currentMonth, { backgroundColor: color }]
122-
: type === 3
131+
: lunarAll.type === 3
123132
? [styles.selectMonth, { borderColor: color }]
124133
: styles.day
125134
}
@@ -129,7 +138,7 @@ const Calendar = (props: CalendarProps) => {
129138
style={[
130139
styles.dayText,
131140
{
132-
color: type === 1 ? '#B5B5B5' : type === 2 ? '#fff' : '#000',
141+
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : '#000',
133142
lineHeight: lineHeight,
134143
paddingTop: paddingTop,
135144
},
@@ -142,20 +151,22 @@ const Calendar = (props: CalendarProps) => {
142151
style={[
143152
styles.dayText,
144153
{
145-
color: type === 1 ? '#B5B5B5' : type === 2 ? '#fff' : colorType,
154+
color: lunarAll.type === 1 ? '#B5B5B5' : lunarAll.type === 2 ? '#fff' : colorType,
146155
fontSize: 13,
147156
},
148157
]}
149158
>
150-
{nameLen > 3 ? <Ellipsis maxLen={2}>{day.lunarHolidays}</Ellipsis> : day.lunarHolidays}
159+
{nameLen > 3 ? <Ellipsis maxLen={2}>{day.lunarHolidays}</Ellipsis> : day.lunarHolidays || day.lunar}
151160
</Text>
152161
)}
153162
</TouchableOpacity>
154163
);
155164
});
156165
};
157166
const goSelectDay = (day: daysArrProps) => {
167+
let lunarName = `农历${day.lunarMonth}${day.lunar}`;
158168
if (day.type === 'current') {
169+
setLunarName(lunarName);
159170
setCurrentDays(day.monthDays);
160171
} else if (day.type === 'last') {
161172
setCurrentDays(day.monthDays);
@@ -203,32 +214,35 @@ const Calendar = (props: CalendarProps) => {
203214
};
204215

205216
return (
206-
<View style={{ flex: 1, backgroundColor: '#fff' }}>
207-
{renderBar}
208-
<View style={styles.calendarHeader}>
209-
<View style={styles.calendarHeaderItem}>
210-
<TouchableOpacity onPress={() => getCurrentYear('last')}>
211-
<Icon name="left" size={20} color={'#333'} />
212-
</TouchableOpacity>
213-
<Text style={styles.calendarHeaderText}>{currentYear}</Text>
214-
<TouchableOpacity onPress={() => getCurrentYear('next')}>
215-
<Icon name="right" size={20} color={'#333'} />
216-
</TouchableOpacity>
217-
</View>
217+
<View style={{ flex: 1, position: 'relative' }}>
218+
<View style={{ flex: 1, backgroundColor: '#fff' }}>
219+
{renderBar}
220+
<View style={styles.calendarHeader}>
221+
<View style={styles.calendarHeaderItem}>
222+
<TouchableOpacity onPress={() => getCurrentYear('last')}>
223+
<Icon name="left" size={20} color={'#333'} />
224+
</TouchableOpacity>
225+
<Text style={styles.calendarHeaderText}>{currentYear}</Text>
226+
<TouchableOpacity onPress={() => getCurrentYear('next')}>
227+
<Icon name="right" size={20} color={'#333'} />
228+
</TouchableOpacity>
229+
</View>
218230

219-
<View style={styles.calendarHeaderItem}>
220-
<TouchableOpacity onPress={() => getCurrentMonth('last')}>
221-
<Icon name="left" size={20} color={'#333'} />
222-
</TouchableOpacity>
223-
<Text style={styles.calendarHeaderText}>{currentMonth + 1}</Text>
224-
<TouchableOpacity onPress={() => getCurrentMonth('next')}>
225-
<Icon name="right" size={20} color={'#333'} />
226-
</TouchableOpacity>
231+
<View style={styles.calendarHeaderItem}>
232+
<TouchableOpacity onPress={() => getCurrentMonth('last')}>
233+
<Icon name="left" size={20} color={'#333'} />
234+
</TouchableOpacity>
235+
<Text style={styles.calendarHeaderText}>{currentMonth + 1}</Text>
236+
<TouchableOpacity onPress={() => getCurrentMonth('next')}>
237+
<Icon name="right" size={20} color={'#333'} />
238+
</TouchableOpacity>
239+
</View>
227240
</View>
228-
</View>
229241

230-
<View style={styles.calendarWeekdays}>{renderWeekDays()}</View>
231-
<View style={styles.calendarDays}>{renderWeeks()}</View>
242+
<View style={styles.calendarWeekdays}>{renderWeekDays()}</View>
243+
<View style={styles.calendarDays}>{renderWeeks()}</View>
244+
</View>
245+
{showLunar === true && <ShowDate iconColor={color} lunar={lunarName} />}
232246
</View>
233247
);
234248
};

packages/core/src/Calendar/lunarDatas.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ export let lunarInfo = [
1616
0xa9d4, 0xa4d0, 0xd150, 0xf252, 0xd520,
1717
];
1818

19-
export let nStr1 = ['日', '', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
19+
export let nStr1 = ['日', '', '二', '三', '四', '五', '六', '七', '八', '九', '十', '冬', '腊'];
2020

2121
export let nStr2 = ['初', '十', '廿', '三十'];
2222

23+
export let nStr3 = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
24+
2325
/**
2426
* 公历节日
2527
*/

packages/core/src/Calendar/lunarHolidays.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,89 @@
11
import { Dimensions, Text } from 'react-native';
2-
import { lunarInfo, nStr1, nStr2, lunarHoliday, solarTerm, sTermInfo, basejieri } from './lunarDatas';
2+
import { lunarInfo, nStr1, nStr2, nStr3, lunarHoliday, solarTerm, sTermInfo, basejieri } from './lunarDatas';
33
export interface CalendarProps {
44
lunarHolidays: string;
55
colorType: string;
6+
lunarMonth: string;
7+
lunar: string;
68
}
79
/**
810
* 获取农历
911
* @returns CalendarProps
1012
*/
11-
export function getLunarCalendar(year: number, month: number, day: number) {
13+
export function getLunarCalendar(year: number, month: number, day: number, type?: string) {
1214
let lDate = Lunar(year, month, day);
1315
let y = lDate.years;
1416
let m = lDate.months;
1517
let d = lDate.days;
1618
let lunar = '';
1719
let paraHoliday = (m > 9 ? m : '0' + m) + '' + (d > 9 ? d : '0' + d);
20+
21+
let lunarMonth = '';
22+
if (type === 'currentMonth') {
23+
lunarMonth = nStr3[m] + '月';
24+
}
25+
1826
//农历节日
1927
if (lunarHoliday.hasOwnProperty(paraHoliday)) {
2028
let paraData = lunarHoliday[paraHoliday as keyof typeof lunarHoliday];
21-
let getHoliday: CalendarProps = { lunarHolidays: paraData, colorType: 'type' };
29+
lunar = cDay(d);
30+
let getHoliday: CalendarProps = {
31+
lunarHolidays: paraData,
32+
colorType: 'type',
33+
lunarMonth: lunarMonth,
34+
lunar: lunar,
35+
};
2236
return getHoliday;
2337
}
2438
if (m === 12) {
2539
let theLastDay = lDate.isLeap ? leapDays(y) : monthDays(y, m); //农历当月最後一天
40+
lunar = cDay(d);
2641
if (theLastDay === d) {
27-
let getHoliday: CalendarProps = { lunarHolidays: '除夕', colorType: 'type' };
42+
let getHoliday: CalendarProps = {
43+
lunarHolidays: '除夕',
44+
colorType: 'type',
45+
lunarMonth: lunarMonth,
46+
lunar: lunar,
47+
};
2848
return getHoliday;
2949
}
3050
}
3151
// 节气
3252
let solarTermDay = (month + 1 > 9 ? month + 1 : '0' + (month + 1)) + '' + (day > 9 ? day : '0' + day);
53+
lunar = cDay(d);
3354
let sTermDateArr = sTermDate(year);
3455
for (var i = 0; i < sTermDateArr.length; i++) {
3556
if (solarTermDay === sTermDateArr[i]) {
3657
let paraData = solarTerm[i];
37-
let getHoliday: CalendarProps = { lunarHolidays: paraData, colorType: 'type' };
58+
let getHoliday: CalendarProps = {
59+
lunarHolidays: paraData,
60+
colorType: 'type',
61+
lunarMonth: lunarMonth,
62+
lunar: lunar,
63+
};
3864
return getHoliday;
3965
}
4066
}
4167
//法定节日
4268
if (basejieri.hasOwnProperty(solarTermDay)) {
4369
let paraData = basejieri[solarTermDay as keyof typeof basejieri];
44-
let getHoliday: CalendarProps = { lunarHolidays: paraData, colorType: 'type' };
70+
let getHoliday: CalendarProps = {
71+
lunarHolidays: paraData,
72+
colorType: 'type',
73+
lunarMonth: lunarMonth,
74+
lunar: lunar,
75+
};
4576
return getHoliday;
4677
}
4778
if (d === 1) {
4879
lunar = nStr1[m] + '月';
80+
let lunar1 = cDay(d);
81+
let getHoliday: CalendarProps = { lunarHolidays: lunar, colorType: '', lunarMonth: lunarMonth, lunar: lunar1 };
82+
return getHoliday;
4983
} else {
5084
lunar = cDay(d);
85+
let getHoliday: CalendarProps = { lunarHolidays: '', colorType: '', lunarMonth: lunarMonth, lunar: lunar };
86+
return getHoliday;
5187
}
5288
return lunar;
5389
}

packages/core/src/Calendar/show.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { View, Text, ViewProps, TextProps, StyleSheet, TouchableOpacity } from 'react-native';
3+
import Icon from '../Icon';
4+
5+
export interface ShowProps extends ViewProps {
6+
iconColor?: string;
7+
lunar?: string;
8+
}
9+
const Show = (props: ShowProps) => {
10+
const { iconColor = '#329BCB', lunar = '' } = props;
11+
return (
12+
<View style={styles.show}>
13+
<Text style={{ fontSize: 18, fontWeight: 'bold' }}>{lunar}</Text>
14+
</View>
15+
);
16+
};
17+
const styles = StyleSheet.create({
18+
show: {
19+
borderRadius: 5,
20+
backgroundColor: '#fff',
21+
marginHorizontal: 5,
22+
marginVertical: 10,
23+
paddingHorizontal: 10,
24+
paddingVertical: 15,
25+
},
26+
});
27+
28+
export default Show;

0 commit comments

Comments
 (0)