1
1
import { number } from 'prop-types' ;
2
- import React , { useState , useRef , useEffect , useMemo , Fragment } from 'react' ;
2
+ import React , { useState , useRef } from 'react' ;
3
3
import {
4
4
StyleSheet ,
5
5
TouchableOpacity ,
@@ -21,25 +21,22 @@ const DEVICE_WIDTH = Dimensions.get('window').width;
21
21
const DEVICE_HEIGHT = Dimensions . get ( 'window' ) . height ;
22
22
23
23
export interface DragDrawerProps extends ViewProps {
24
+ /** 抽屉高度 */
24
25
drawerHeight ?: number ;
26
+ /** 抽屉颜色 */
25
27
drawerBackgroundColor ?: string ;
28
+ /** 自定义图标 */
29
+ icon ?: IconsName | React . ReactElement | React . ReactNode ;
26
30
children ?: React . ReactNode ;
27
31
}
28
- export interface DragDrawerProps extends ViewProps { }
32
+
29
33
function DragDrawer ( props : DragDrawerProps ) {
30
- const { drawerBackgroundColor = '#fff' , drawerHeight = 300 , children } = props ;
34
+ const { drawerBackgroundColor = '#fff' , drawerHeight = 300 , children, icon } = props ;
31
35
32
- const [ zIndexValue , setZIndexValue ] = useState ( 0 ) ;
33
36
const [ animatedViewHeight , setAnimatedViewHeight ] = useState ( new Animated . Value ( drawerHeight ) ) ;
34
37
const [ viewHeight , setViewHeight ] = useState ( drawerHeight ) ;
35
38
const [ showAnimate , setShowAnimate ] = useState ( false ) ;
36
39
37
- const openDrawer = ( ) => {
38
- setZIndexValue ( 3002 ) ;
39
- } ;
40
- const closeDrawer = ( ) => {
41
- setZIndexValue ( 0 ) ;
42
- } ;
43
40
const dynamicDrawerStyles : any = {
44
41
backgroundColor : drawerBackgroundColor ,
45
42
top : null ,
@@ -48,6 +45,9 @@ function DragDrawer(props: DragDrawerProps) {
48
45
width : '100%' ,
49
46
} ;
50
47
48
+ /**
49
+ * 拖曳效果动画
50
+ * */
51
51
const panResponder = useRef (
52
52
PanResponder . create ( {
53
53
onMoveShouldSetPanResponder : ( ) => true ,
@@ -65,7 +65,6 @@ function DragDrawer(props: DragDrawerProps) {
65
65
} , // 可选的异步监听函数
66
66
) ( evt , gestureState ) ;
67
67
} ,
68
-
69
68
onPanResponderRelease : ( e , gestureState ) => {
70
69
let values = DEVICE_HEIGHT + 30 - gestureState . moveY ;
71
70
if ( gestureState . dy >= 0 ) {
@@ -104,30 +103,35 @@ function DragDrawer(props: DragDrawerProps) {
104
103
} ) ,
105
104
) . current ;
106
105
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
+
107
117
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 >
129
132
</ Animated . View >
130
- </ Fragment >
133
+ { children }
134
+ </ Animated . View >
131
135
) ;
132
136
}
133
137
@@ -136,7 +140,6 @@ const styles = StyleSheet.create({
136
140
flexDirection : 'row' ,
137
141
justifyContent : 'center' ,
138
142
alignItems : 'center' ,
139
- backgroundColor : '#fff' ,
140
143
} ,
141
144
homeContainer : {
142
145
width : 50 ,
@@ -153,17 +156,6 @@ const styles = StyleSheet.create({
153
156
flex : 1 ,
154
157
zIndex : 3004 ,
155
158
} ,
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
- } ,
167
159
} ) ;
168
160
169
161
export default DragDrawer ;
0 commit comments