Skip to content

Commit e851f33

Browse files
Amber-Nan杨楠
and
杨楠
authored
feat(DragDrawer):增加自定义图标 & 文档更新 (#342)
* 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 拖曳抽屉 & 文档更新 * doc(website): 增加DragDrawer目录 * feat(DragDrawer):增加自定义图标 & 文档更新 Co-authored-by: 杨楠 <[email protected]>
1 parent 5e1d0b5 commit e851f33

File tree

3 files changed

+60
-55
lines changed

3 files changed

+60
-55
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useState, Fragment} from 'react';
2-
import {View, Text, Dimensions} from 'react-native';
3-
import {DragDrawer, Card, Button} from '@uiw/react-native';
2+
import {View, Text} from 'react-native';
3+
import {DragDrawer, Card, Icon} from '@uiw/react-native';
44
import Layout, {Container} from '../../Layout';
55
import {ComProps} from '../../routes';
66
const {Header, Body, Footer} = Layout;
@@ -11,7 +11,11 @@ export default function DragDrawerView({route}: DragDrawerViewProps) {
1111
const title = route.params.title;
1212
return (
1313
<Fragment>
14-
<DragDrawer>
14+
<DragDrawer
15+
drawerHeight={350}
16+
// drawerBackgroundColor='lightblue' //抽屉背景
17+
// icon={<Icon name="smile" fill="red" size={30} />} //自定义拖曳图标
18+
>
1519
<View>
1620
<Text>按住图标可上下拖曳抽屉</Text>
1721
</View>
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
DragDrawer 拖曳抽屉
22
---
33

4-
![](https://user-images.githubusercontent.com/66067296/143007086-5594c9ee-95cc-4802-9434-cc4041a8dae7.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
4+
![](https://user-images.githubusercontent.com/66067296/143187302-bee614b4-7799-49d1-9cab-470ad8228372.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
55

66
可自定义拖曳抽屉高度。
77

88
### 基础示例
99

1010
```jsx
1111
import React, { useState, Fragment } from 'react';
12-
import { View, Text, Dimensions } from 'react-native';
13-
import { DragDrawer, Card, Button } from '@uiw/react-native';
12+
import { View, Text } from 'react-native';
13+
import { DragDrawer, Card, Icon } from '@uiw/react-native';
1414
import Layout, { Container } from '../../Layout';
1515
import { ComProps } from '../../routes';
1616
const { Header, Body, Footer } = Layout;
@@ -21,27 +21,36 @@ export default function DragDrawerView({ route }: DragDrawerViewProps) {
2121
const title = route.params.title;
2222
return (
2323
<Fragment>
24-
<DragDrawer>
24+
<DragDrawer
25+
drawerHeight={350}
26+
// drawerBackgroundColor='lightblue' //抽屉背景
27+
// icon={<Icon name="smile" fill="red" size={30} />} //自定义拖曳图标
28+
>
2529
<View>
2630
<Text>按住图标可上下拖曳抽屉</Text>
2731
</View>
2832
</DragDrawer>
29-
<Container >
33+
<Container>
3034
<Layout>
3135
<Header title={title} description={description} />
32-
<Body >
36+
<Body>
37+
<Card title="下边抽屉可上下拖曳">
38+
<Text>下边抽屉可上下拖曳</Text>
39+
</Card>
3340
</Body>
3441
<Footer />
3542
</Layout>
3643
</Container>
3744
</Fragment>
3845
);
3946
}
47+
4048
```
4149

4250
### props
4351

4452
| 参数 | 说明 | 类型 | 默认值 |
4553
|------|------|-----|------|
4654
| `drawerHeight` | 抽屉高度 | Number | `300` |
47-
| `drawerBackgroundColor` | 指定抽屉背景色 | String | `#fff` |
55+
| `drawerBackgroundColor` | 指定抽屉背景色 | String | `#fff` |
56+
| `icon` | 自定义图标 | `IconsName | React.ReactElement | React.ReactNode` | |

packages/core/src/DragDrawer/index.tsx

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { number } from 'prop-types';
2-
import React, { useState, useRef, useEffect, useMemo, Fragment } from 'react';
2+
import React, { useState, useRef } from 'react';
33
import {
44
StyleSheet,
55
TouchableOpacity,
@@ -21,25 +21,22 @@ const DEVICE_WIDTH = Dimensions.get('window').width;
2121
const DEVICE_HEIGHT = Dimensions.get('window').height;
2222

2323
export interface DragDrawerProps extends ViewProps {
24+
/** 抽屉高度 */
2425
drawerHeight?: number;
26+
/** 抽屉颜色 */
2527
drawerBackgroundColor?: string;
28+
/** 自定义图标 */
29+
icon?: IconsName | React.ReactElement | React.ReactNode;
2630
children?: React.ReactNode;
2731
}
28-
export interface DragDrawerProps extends ViewProps {}
32+
2933
function DragDrawer(props: DragDrawerProps) {
30-
const { drawerBackgroundColor = '#fff', drawerHeight = 300, children } = props;
34+
const { drawerBackgroundColor = '#fff', drawerHeight = 300, children, icon } = props;
3135

32-
const [zIndexValue, setZIndexValue] = useState(0);
3336
const [animatedViewHeight, setAnimatedViewHeight] = useState(new Animated.Value(drawerHeight));
3437
const [viewHeight, setViewHeight] = useState(drawerHeight);
3538
const [showAnimate, setShowAnimate] = useState(false);
3639

37-
const openDrawer = () => {
38-
setZIndexValue(3002);
39-
};
40-
const closeDrawer = () => {
41-
setZIndexValue(0);
42-
};
4340
const dynamicDrawerStyles: any = {
4441
backgroundColor: drawerBackgroundColor,
4542
top: null,
@@ -48,6 +45,9 @@ function DragDrawer(props: DragDrawerProps) {
4845
width: '100%',
4946
};
5047

48+
/**
49+
* 拖曳效果动画
50+
* */
5151
const panResponder = useRef(
5252
PanResponder.create({
5353
onMoveShouldSetPanResponder: () => true,
@@ -65,7 +65,6 @@ function DragDrawer(props: DragDrawerProps) {
6565
}, // 可选的异步监听函数
6666
)(evt, gestureState);
6767
},
68-
6968
onPanResponderRelease: (e, gestureState) => {
7069
let values = DEVICE_HEIGHT + 30 - gestureState.moveY;
7170
if (gestureState.dy >= 0) {
@@ -104,30 +103,35 @@ function DragDrawer(props: DragDrawerProps) {
104103
}),
105104
).current;
106105

106+
/**
107+
* 自定义图标
108+
* */
109+
const IconCustom = (icon?: IconsName | React.ReactElement | React.ReactNode) => {
110+
if (icon) {
111+
return <>{typeof icon === 'string' ? <Icon name={icon as IconsName} size={25} color="#8F8F8F" /> : icon}</>;
112+
} else {
113+
return <Icon name="minus" size={25} color="#8F8F8F" />;
114+
}
115+
};
116+
107117
return (
108-
<Fragment>
109-
<Animated.View
110-
style={[
111-
styles.drawer,
112-
dynamicDrawerStyles,
113-
{
114-
height: animatedViewHeight,
115-
},
116-
]}
117-
{...panResponder.panHandlers}
118-
>
119-
<Animated.View style={[styles.viewPosition]}>
120-
<View style={{}}>
121-
<TouchableOpacity activeOpacity={1}>
122-
<View style={[styles.homeContainer]}>
123-
<Icon name="minus" size={25} fill="#8F8F8F" />
124-
</View>
125-
</TouchableOpacity>
126-
</View>
127-
</Animated.View>
128-
{children}
118+
<Animated.View
119+
style={[
120+
styles.drawer,
121+
dynamicDrawerStyles,
122+
{
123+
height: animatedViewHeight,
124+
},
125+
]}
126+
{...panResponder.panHandlers}
127+
>
128+
<Animated.View style={[styles.viewPosition]}>
129+
<TouchableOpacity activeOpacity={1}>
130+
<View style={[styles.homeContainer]}>{IconCustom(icon)}</View>
131+
</TouchableOpacity>
129132
</Animated.View>
130-
</Fragment>
133+
{children}
134+
</Animated.View>
131135
);
132136
}
133137

@@ -136,7 +140,6 @@ const styles = StyleSheet.create({
136140
flexDirection: 'row',
137141
justifyContent: 'center',
138142
alignItems: 'center',
139-
backgroundColor: '#fff',
140143
},
141144
homeContainer: {
142145
width: 50,
@@ -153,17 +156,6 @@ const styles = StyleSheet.create({
153156
flex: 1,
154157
zIndex: 3004,
155158
},
156-
positionFull: {
157-
position: 'absolute',
158-
top: 0,
159-
bottom: 0,
160-
left: 0,
161-
right: 0,
162-
},
163-
overlay: {
164-
backgroundColor: '#000',
165-
zIndex: 3002,
166-
},
167159
});
168160

169161
export default DragDrawer;

0 commit comments

Comments
 (0)