Skip to content

Commit 81e3092

Browse files
authored
Merge pull request #494 from hy916/dev
fix:优化组件和文档添加测试用例
2 parents 6f61808 + 939cee3 commit 81e3092

File tree

6 files changed

+81
-85
lines changed

6 files changed

+81
-85
lines changed

packages/core/src/Calendar/index.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2-
import { View, Text, ViewProps, StyleSheet, TouchableOpacity, Dimensions, Platform } from 'react-native';
2+
import { View, Text, ViewProps, TextProps, StyleSheet, TouchableOpacity, Dimensions, Platform } from 'react-native';
33
import Icon from '../Icon';
44
import Ellipsis from '../Ellipsis';
55
import { getMonths, getWeeksArray, daysArrProps, getType, getNameLen } from './utils';
@@ -112,7 +112,7 @@ const Calendar = (props: CalendarProps) => {
112112

113113
let nameLen = getNameLen(day.lunarHolidays);
114114
let lineHeight =
115-
lunarHoliday === true && Platform.OS === 'ios' ? 0 : lunarHoliday === true ? MainWidth < 1000 ? 18 : 55 : MainWidth < 1000 ? MainWidth / 7 - 4.5 : MainWidth / 14.5;
115+
lunarHoliday === true && Platform.OS === 'ios' ? 0 : lunarHoliday === true ? 18 : MainWidth / 7 - 4.5;
116116
let paddingTop = lunarHoliday === true ? 4 : 0;
117117
let colorType = '';
118118
if (day.colorType === '') {
@@ -211,9 +211,9 @@ const Calendar = (props: CalendarProps) => {
211211
setCurrentMonth(toMonth);
212212
setCurrentDays(toDays);
213213
};
214-
// const goCurrentDay = (day: number) => {
215-
// setCurrentDays(day);
216-
// };
214+
const goCurrentDay = (day: number) => {
215+
setCurrentDays(day);
216+
};
217217

218218
return (
219219
<View style={{ flex: 1, position: 'relative' }}>
@@ -298,10 +298,10 @@ const styles = StyleSheet.create({
298298
},
299299
calendarWeekdays: {
300300
flexDirection: 'row',
301-
justifyContent: 'space-around',
301+
justifyContent: 'space-between',
302302
alignItems: 'center',
303-
paddingHorizontal: MainWidth < 1000 ? MainWidth / 7 - 33 : MainWidth / 30,
304-
paddingTop: 12,
303+
paddingHorizontal: MainWidth / 7 - 33,
304+
paddingTop: 10,
305305
},
306306
calendarWedText: {
307307
color: '#616161',
@@ -312,12 +312,12 @@ const styles = StyleSheet.create({
312312
},
313313
weekDay: {
314314
flexDirection: 'row',
315-
paddingHorizontal: 22,
315+
paddingHorizontal: 2,
316316
},
317317
dateBase: {
318-
marginHorizontal: 8,
319-
width: MainWidth < 1000 ? MainWidth / 7 - 4.5 : MainWidth / 14,
320-
height: MainHeight < 300 ? MainWidth / 7 - 4.5 : MainWidth / 14,
318+
marginHorizontal: 2,
319+
width: MainWidth / 7 - 4.5,
320+
height: MainWidth / 7 - 4.5,
321321
...Platform.select({
322322
ios: {},
323323
android: {
@@ -327,15 +327,15 @@ const styles = StyleSheet.create({
327327
},
328328
currentMonth: {
329329
backgroundColor: '#329BCB',
330-
borderRadius: 60,
330+
borderRadius: 50,
331331
},
332332
selectMonth: {
333333
borderWidth: 1,
334334
borderColor: '#329BCB',
335-
borderRadius: 60,
335+
borderRadius: 50,
336336
},
337337
otherMonth: {
338-
borderRadius: 60,
338+
borderRadius: 50,
339339
},
340340
dayText: {
341341
textAlign: 'center',

packages/core/src/NoticeBar/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const NoticeBar = (props: NoticeBarProps) => {
4040
operationDom = <View style={styles.actionWrap}>{action ? action : <Text style={[styles.link]}></Text>}</View>;
4141
}
4242
const main = (
43-
<View style={[styles.notice, style]}>
43+
<View style={[styles.notice, style]} testID="RNE__NoticeBar__style">
4444
{icon && <View style={styles.left15}>{icon}</View>}
4545
<View style={[styles.container, icon ? styles.left6 : styles.left15]}>
4646
<Marquee style={[styles.content, textStyle]} text={children} {...marqueeProps} />
@@ -54,7 +54,7 @@ const NoticeBar = (props: NoticeBarProps) => {
5454
mode === 'closable' ? (
5555
main
5656
) : (
57-
<TouchableWithoutFeedback onPress={onPress}>{main}</TouchableWithoutFeedback>
57+
<TouchableWithoutFeedback onPress={onPress} testID="RNE__NoticeBar__link" >{main}</TouchableWithoutFeedback>
5858
)
5959
) : null}
6060
</View>

packages/core/src/Picker/README.md

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,45 +61,16 @@ function Demo() {
6161
export default Demo
6262
```
6363

64-
65-
6664
### Props
6765

68-
```ts
69-
import { StyleProp, TextStyle, ViewStyle } from 'react-native';
70-
71-
export interface PickerData {
72-
label?: string,
73-
render?: (key: string, record: PickerData, index: number)=>React.ReactNode,
74-
[key: string]: any
75-
}
66+
属性 | 说明 | 类型 | 默认值
67+
----|-----|------|------
68+
| lines | 显示行数 | number | 3 |
69+
| rowKey | 在开始位置设置图标 | string | - |
70+
| data | 需要渲染的数据 | Array | - |
71+
| containerStyle | item 容器样式 | obj | - |
72+
| textStyle | 容器的文本样式 | TextStyle | - |
73+
| value | 选中当前项的下标 | number | - |
74+
| onChange | value 改变时触发 | fn | - |
75+
| readonly | 是否只读 | fn | - |
7676

77-
export interface PickerProps {
78-
/** 显示几行, 默认 3 */
79-
lines?: number,
80-
/** 指定需要显示的 key, 默认使用 data 的 label 属性 */
81-
rowKey?: string,
82-
/** 需要渲染的数据 */
83-
data?: Array<PickerData>,
84-
/** item 容器样式 */
85-
containerStyle?: {
86-
/** 激活的容器样式 */
87-
actived?: StyleProp<ViewStyle>,
88-
/** 未激活的容器样式 */
89-
unactived?: StyleProp<ViewStyle>,
90-
},
91-
/** 容器的文本样式 */
92-
textStyle?: {
93-
/** 激活的文本样式 */
94-
actived?: StyleProp<TextStyle>,
95-
/** 未激活的文本样式 */
96-
unactived?: StyleProp<TextStyle>,
97-
},
98-
/** 选中当前项的下标 */
99-
value?: number,
100-
/** value 改变时触发 */
101-
onChange?: (value: number)=>unknown,
102-
/** 是否只读 不能点击不能滑动但可以通过value控制 */
103-
readonly?: boolean
104-
}
105-
```

packages/core/src/SwipeAction/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,36 @@ import React,{ useRef } from 'react';
101101
import {SwipeAction} from '@uiw/react-native';
102102
import { View,Text } from 'react-native'
103103

104+
function Demo() {
105+
const ref = useRef()
106+
const right = [
107+
{
108+
text: '查看',
109+
color: 'orange',
110+
x: 250,
111+
},
112+
{
113+
text: '删除',
114+
color: 'red',
115+
x: 250,
116+
},
117+
];
118+
return (
119+
<SwipeAction ref={ref} buttonWidth={60} right={right}>
120+
<View><Text>滑动</Text></View>
121+
</SwipeAction>
122+
);
123+
}
124+
export default Demo;
125+
```
126+
127+
### 禁用
128+
129+
```jsx
130+
import React,{ useRef } from 'react';
131+
import {SwipeAction} from '@uiw/react-native';
132+
import { View,Text } from 'react-native'
133+
104134
function Demo() {
105135
const ref = useRef()
106136
const right = [

test-ci/src/__tests__/noticeBar.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,30 @@ describe('NoticeBar', () => {
4444
expect(component.props.style).toMatchObject({ fontSize: 12 });
4545
});
4646

47-
// it('onPress', () => {
48-
// const fn = jest.fn();
49-
// const { getByTestId } = render(<NoticeBar onPress={fn}>onPress</NoticeBar>);
50-
// const component = getByTestId('RNE__NoticeBar__wrap');
51-
// fireEvent(component, 'press');
52-
// expect(fn).toHaveBeenCalled();
53-
// });
47+
it('textStyle', () => {
48+
const { UNSAFE_getByType } = render(<NoticeBar textStyle={{ fontSize: 20 }} />);
49+
const component = UNSAFE_getByType(Marquee);
50+
expect(component.props.style[1].fontSize).toBe(20);
51+
});
52+
53+
it('onPress events', () => {
54+
const fn = jest.fn();
55+
const { getByTestId } = render(<NoticeBar mode="link" onPress={fn}>onPress</NoticeBar>);
56+
const component = getByTestId('RNE__NoticeBar__link');
57+
fireEvent(component, 'press');
58+
expect(fn).toHaveBeenCalled();
59+
});
5460

55-
// it('action', () => {
56-
// const { getByText } = render(<NoticeBar action={<Text>去看看</Text>} />);
57-
// expect(getByText('去看看')).toBeTruthy();
58-
// });
61+
it('action', () => {
62+
const { getByText } = render(<NoticeBar mode="closable" action={<Text>去看看</Text>} />);
63+
expect(getByText('去看看')).toBeTruthy();
64+
});
5965

60-
// it('style', () => {
61-
// const { getByTestId } = render(<NoticeBar style={{ height: 50 }} />);
62-
// const component = getByTestId('RNE__NoticeBar__wrap');
63-
// const styles = toObject(component.props.style);
64-
// expect(styles.height).toBe(50);
65-
// });
66+
it('style', () => {
67+
const { getByTestId } = render(<NoticeBar mode="closable" style={{ height: 50 }} />);
68+
const component = getByTestId('RNE__NoticeBar__style');
69+
const styles = toObject(component.props.style);
70+
expect(styles.height).toBe(50);
71+
});
6672

67-
// it('textStyle', () => {
68-
// const { getByTestId } = render(<NoticeBar textStyle={{ fontSize: 20 }} />);
69-
// const component = getByTestId('RNE__NoticeBar__div');
70-
// const styles = toObject(component.props.style);
71-
// expect(styles.fontSize).toBe(20);
72-
// });
7373
});

website/src/component/Preview/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ const Markdown = styled(MarkdownPreview)`
2828
const getBooleanValue = (param, field, defaultValue) => {
2929
if (Reflect.has(param, field)) {
3030
const newValue = Reflect.get(param, field);
31-
if (newValue === 'true') {
32-
return true;
33-
}
34-
if (newValue === 'false') {
35-
return false;
36-
}
31+
return newValue === 'true';
3732
}
3833
return defaultValue;
3934
};

0 commit comments

Comments
 (0)