Skip to content

Commit b06ec65

Browse files
author
rulishu
committed
Merge branch 'dev' of github.com:uiwjs/react-native-uiw into rls
2 parents 4c383c8 + 1ecd16d commit b06ec65

File tree

17 files changed

+138
-107
lines changed

17 files changed

+138
-107
lines changed

packages/core/src/ImageViewer/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ export interface ImageViewerProps extends ViewProps {
2020
height?: number;
2121
/** 图像源(远程URL或本地文件资源 */
2222
src?: string | ImageViewerDataSourceProps[];
23-
/** 默认显示第几张图片 */
24-
defaultIndex?: number;
2523
}
2624

2725
function ImageViewer(props: ImageViewerProps) {
28-
const { width = 150, height = 150, src = defaultImage, defaultIndex = 0, ...others } = props;
26+
const { width = 150, height = 150, src = defaultImage, ...others } = props;
2927
const [visible, setVisible] = useState(false);
28+
const [index, setIndex] = useState<number>(0);
3029
const fadeAnim = useRef(new Animated.Value(0)).current;
3130

3231
useMemo(() => {
@@ -43,11 +42,16 @@ function ImageViewer(props: ImageViewerProps) {
4342

4443
const imgUrl = useMemo(() => {
4544
if (Array.isArray(src)) {
46-
return src[defaultIndex].url;
45+
return src[0].url;
4746
}
4847
return src;
4948
}, [src]);
5049

50+
const onImgClick = (index: number) => {
51+
setIndex(index);
52+
setVisible(true);
53+
};
54+
5155
return (
5256
<View style={{}}>
5357
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
@@ -57,7 +61,7 @@ function ImageViewer(props: ImageViewerProps) {
5761
<TransitionImage
5862
key={index}
5963
style={{ width: width, height: height, flex: 1 }}
60-
onPress={() => setVisible(true)}
64+
onPress={() => onImgClick(index)}
6165
source={{ uri: item.url }}
6266
PlaceholderContent={<ActivityIndicator />}
6367
transition={true}
@@ -79,7 +83,7 @@ function ImageViewer(props: ImageViewerProps) {
7983
<MaskLayer visible={visible} onDismiss={() => setVisible(false)} opacity={0.9}>
8084
<Animated.View style={[styles.content, { opacity: fadeAnim }]}>
8185
{Array.isArray(src) ? (
82-
<Swiper dataSource={src} height={200} autoplay={false} />
86+
<Swiper dataSource={src} height={200} autoplay={false} index={index} />
8387
) : (
8488
<Image style={{ width: '100%', height: '100%', resizeMode: 'contain' }} source={{ uri: src }} />
8589
)}

packages/core/src/List/README.md

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ List 列表
33

44
单个连续模块垂直排列,显示当前的内容、状态和可进行的操作。eg:联系人列表。
55

6-
![](https://user-images.githubusercontent.com/66067296/139397639-1bb004ac-fd66-495e-8991-6b6910f84e60.png)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
7-
![](https://user-images.githubusercontent.com/66067296/139397695-5de2fb65-4931-454b-baed-9115a80abebc.png)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
86

97
### 基础示例
108

11-
<!--DemoStart-->
12-
```jsx
9+
```jsx mdx:preview
10+
1311
import { View, Text } from 'react-native';
1412
import { List } from '@uiw/react-native';
13+
import React from "react"
1514

16-
export default function Demo() {
15+
function Demo() {
1716
return (
1817
<List>
1918
<List.Item style={{ height: 50 }}>"X战警新变种人"首曝海报特写诡异人脸</List.Item>
@@ -27,15 +26,18 @@ export default function Demo() {
2726
</List>
2827
);
2928
}
29+
30+
export default Demo
31+
3032
```
31-
<!--End-->
3233

33-
### 简单
34+
### 自定义渲染列表
35+
36+
```jsx mdx:preview
3437

35-
<!--DemoStart-->
36-
```jsx
3738
import { View, Text } from 'react-native';
3839
import { List } from '@uiw/react-native';
40+
import React from "react"
3941

4042
export default function Demo() {
4143
return (
@@ -49,7 +51,7 @@ export default function Demo() {
4951
]}
5052
renderItem={({ item }) => {
5153
return (
52-
<View>
54+
<View style={{borderWidth: 1}}>
5355
<Text>{item.date}</Text>
5456
<Text>{item.time}</Text>
5557
</View>
@@ -59,51 +61,9 @@ export default function Demo() {
5961
)
6062
}
6163
```
62-
<!--End-->
6364

6465

65-
### 基础示例
66-
67-
<!--DemoStart-->
68-
```jsx
69-
import { View, Text } from 'react-native';
70-
import { List, Icon } from '@uiw/react-native';
7166

72-
export default function Demo() {
73-
return (
74-
<List
75-
flat={true}
76-
data={[
77-
{ date: '8月12日', title: '这里是标题', des: '这里是详情内容' },
78-
{ date: '8月10日', title: 'SO18081000004', des: '这里是详情内容' },
79-
{ date: '8月2日', title: 'SO18080200003', des: '这里是详情内容' },
80-
{ date: '8月1日', title: 'SO18080100002', des: '这里是详情内容' },
81-
{ date: '8月1日', title: 'SO18080100001', des: '这里是详情内容' }
82-
]}
83-
renderItem={({ item, index }) => {
84-
return (
85-
<List.Item
86-
key={index}
87-
extra={<Icon name="right" fill="#abb0b5" size={14} />}
88-
size="large"
89-
paddingLeft={15}
90-
style={{ borderBottomWidth: 0, }}
91-
onPress={() => { }}
92-
>
93-
<View>
94-
<Text>{item.title}</Text>
95-
<View>
96-
<Text>{item.des}</Text>
97-
</View>
98-
</View>
99-
</List.Item>
100-
)
101-
}}
102-
/>
103-
);
104-
}
105-
```
106-
<!--End-->
10767

10868
### Props
10969

@@ -142,7 +102,7 @@ export default function Demo() {
142102

143103
| 参数 | 说明 | 类型 | 默认值|
144104
|------|------|-----|------|
145-
| `size` | 单元格大小 | `small`, `default`, `large` | List`default`, List.Item '-' |
105+
| `size` | 单元格大小 | `small`, `default`, `large` | `default` |
146106
| `extra` | 额外内容,展示右侧内容 | ReactNode | - |
147107
| `extraStyle` | 设置 `extra` 包裹样式 | ViewProps['style'] | TextProps['style'] | - |
148108
| `paddingLeft` | 左边补白 | Number | `16` |

packages/core/src/Modal/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Modal 模态框
88

99
### 基础示例
1010

11-
<!--DemoStart-->
11+
1212
```jsx mdx:preview
1313
import React, { useState, Fragment } from 'react';
1414
import { View, Text, SafeAreaView } from 'react-native';
@@ -39,7 +39,6 @@ function ButtonGroupView() {
3939
}
4040
export default ButtonGroupView
4141
```
42-
<!--End-->
4342

4443
### Props
4544

packages/core/src/NoticeBar/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default NoticeBarExample;
7272
7373
属性 | 说明 | 类型 | 默认值
7474
----|-----|------|------
75-
| mode | 提示类型,可选 `closable`,`link` | String | '' |
75+
| mode | 提示类型,可选 `closable`,`link` | String | - |
7676
| icon | 在开始位置设置图标 | ReactNode | `<Icon type={require('./trips.svg')} size="xxs" />`|
7777
| onPress | 点击关闭或者操作区域的回调函数 | () => void | |
7878
| marqueeProps | marquee 参数 | Object | `{loop: false, leading: 500, trailing: 800, fps: 40, style: {}}` |

packages/core/src/Progress/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ Progress 进度条
33

44
表明某个任务的当前进度。
55

6-
![](https://user-images.githubusercontent.com/66067296/140003519-03faded1-e004-45eb-b9af-442d84d6f258.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
76

87
### 基础示例
98

10-
<!--DemoStart-->
11-
```jsx
9+
<!--DemoStart-->
10+
```jsx mdx:preview
11+
import React from 'react';
1212
import { SafeAreaView } from 'react-native';
1313
import { Progress } from '@uiw/react-native';
1414
import { motorcycle } from './svg';
@@ -20,29 +20,29 @@ function Demo() {
2020
</SafeAreaView>
2121
)
2222
}
23+
export default Demo
2324
```
2425

25-
### 展示进度图标 & 进度提示字
26+
### 自定义颜色
2627

27-
<!--DemoStart-->
28-
```jsx
28+
<!--DemoStart-->
29+
```jsx mdx:preview
30+
import React from 'react';
2931
import { SafeAreaView } from 'react-native';
3032
import { Progress } from '@uiw/react-native';
31-
import { motorcycle } from './svg';
3233

3334
function Demo() {
3435
return (
3536
<SafeAreaView style={{ flex: 1 }}>
3637
<Progress
3738
progressColor="#5847FF"
38-
xml={motorcycle}
3939
progressShow={false}
40-
iconShow={true}
4140
progress={30}
4241
/>
4342
</SafeAreaView>
4443
)
4544
}
45+
export default Demo
4646
```
4747
<!--End-->
4848

packages/core/src/QuickList/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export default QuickListDemo
8888
| onFetch | 请求的接口函数) | `(params: any) => void` | - |
8989
| data | 数据 | `Array<any>` | [] |
9090
| renderItem | 从data列表中获取一个项目并将其渲染到列表中 | `ListRenderItem<any>` | - |
91-
| keyId | 唯一健 | `string | number` | - |
91+
| keyId | 唯一健 | `string` \| `number` | - |
9292
| emptyView | 当列表为空时呈现 | `() => React.ReactNode` | - |
9393
| pageSize | 每次加载数据条数 | `number` | - |
9494
| total | 总条数 | `number` | - |

packages/core/src/Steps/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Steps 步骤条
33

44
引导用户按照流程完成任务的分步导航条,可根据实际应用场景设定步骤,步骤不得少于 2 步。
55

6-
![](https://user-images.githubusercontent.com/57083007/146733593-0e6583f2-4caa-4e37-9f5d-6e6c9a821d4e.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
76

87
### 基础示例
98

10-
```jsx
9+
```jsx mdx:preview
10+
import React from 'react';
1111
import { Steps } from '@uiw/react-native';
1212

1313
function Demo() {
@@ -22,6 +22,7 @@ function Demo() {
2222
/>
2323
);
2424
}
25+
export default Demo;
2526
```
2627

2728
### props

packages/core/src/Swiper/index.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface SwiperProps {
3131
autoplay?: boolean;
3232
// 指示点样式 dot: 圆点 block: 方块
3333
dotStyle?: dotType;
34+
// 初始位置
35+
index?: number;
3436
loading?: boolean;
3537
}
3638
const Swiper = (porps: SwiperProps) => {
@@ -44,11 +46,21 @@ const Swiper = (porps: SwiperProps) => {
4446
borderRadius = 0,
4547
dotStyle = 'dot',
4648
loading = false,
49+
index = 0,
4750
} = porps;
48-
let [curIndex, setCurIndex] = useState(0);
51+
let [curIndex, setCurIndex] = useState(index);
4952
let timer = useRef<NodeJS.Timeout | undefined>();
5053
const scrollToRef: any = useRef();
5154

55+
useEffect(() => {
56+
if (scrollToRef && scrollToRef.current && index !== 0) {
57+
setTimeout(() => {
58+
onClickDot(index);
59+
scrollToRef.current.scrollTo({ x: width * index, y: 0, animated: true });
60+
}, 0);
61+
}
62+
}, [scrollToRef, index]);
63+
5264
// 自动播放
5365
const autoPlay = useCallback(() => {
5466
clearInterval(timer.current as unknown as number);

packages/core/src/Timeline/README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ Timeline 时间轴
77

88
```jsx mdx:preview
99
import React from 'react'
10-
import Timeline from '@uiw/react-native/lib/Timeline';
11-
import WingBlank from '@uiw/react-native/lib/WingBlank';
12-
import Icon from '@uiw/react-native/lib/Icon';
13-
import Card from '@uiw/react-native/lib/Card';
10+
import { Card, Icon, WingBlank, Timeline } from '@uiw/react-native';
1411

1512
function Demo() {
1613
const item = [
@@ -57,10 +54,7 @@ export default Demo
5754

5855
```jsx mdx:preview
5956
import React from 'react'
60-
import Timeline from '@uiw/react-native/lib/Timeline';
61-
import WingBlank from '@uiw/react-native/lib/WingBlank';
62-
import Card from '@uiw/react-native/lib/Card';
63-
import Icon from '@uiw/react-native/lib/Icon';
57+
import { Card, Icon, WingBlank, Timeline } from '@uiw/react-native';
6458

6559
function Demo() {
6660
const item = [
@@ -108,10 +102,8 @@ export default Demo
108102

109103
```jsx mdx:preview
110104
import React from 'react'
111-
import Timeline from '@uiw/react-native/lib/Timeline';
112-
import WingBlank from '@uiw/react-native/lib/WingBlank';
113-
import Card from '@uiw/react-native/lib/Card';
114-
import Icon from '@uiw/react-native/lib/Icon';
105+
import { Card, Icon, WingBlank, Timeline } from '@uiw/react-native';
106+
115107

116108
function Demo() {
117109
const item = [
@@ -157,7 +149,7 @@ export default Demo
157149

158150
### Props
159151

160-
<!-- ```ts
152+
```ts
161153
export interface TimelineItemsProps {
162154
/** 标题 */
163155
title: string;
@@ -181,4 +173,4 @@ export interface TimelineProps extends ViewProps {
181173
/** 改变时间轴和内容的相对位置 */
182174
mode?: 'left' | 'alternate';
183175
}
184-
``` -->
176+
```

test-ci/src/__tests__/progress.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import Progress from '../lib/Progress';
8+
// Note: test renderer must be required after react-native.
9+
import renderer from 'react-test-renderer';
10+
import { run } from '../lib/Progress/svg';
11+
12+
it('Progress', () => {
13+
const component = renderer.create(
14+
<Progress
15+
progress={30}
16+
position="fixed"
17+
progressColor="#108ee9"
18+
animation={{ duration: 1000 }}
19+
xml={run}
20+
iconShow={true}
21+
size={25}
22+
progressShow={true}
23+
/>,
24+
);
25+
expect(component.root.props.progress).toBe(30);
26+
expect(component.root.props.position).toBe('fixed');
27+
expect(component.root.props.progressColor).toBe('#108ee9');
28+
expect(component.root.props.animation.duration).toBe(1000);
29+
expect(component.root.props.iconShow).toBeTruthy();
30+
expect(component.root.props.xml).toStrictEqual(run);
31+
expect(component.root.props.size).toBe(25);
32+
expect(component.root.props.progressShow).toBeTruthy();
33+
});

0 commit comments

Comments
 (0)