@@ -11,38 +11,48 @@ SpeedDial 悬浮标记组件按下时,浮动动作按钮可以以快速显示
1111### 基础示例
1212
1313``` jsx mdx:preview&background=#bebebe29
14- import React , { Fragment } from ' react' ;
14+ import React , { Fragment , useEffect , useRef , useState } from ' react' ;
1515import { SpeedDial , Icon } from ' @uiw/react-native' ;
1616import { View , Text , Dimensions } from ' react-native' ;
1717
18+ const bodyHeight = window .screen .height
19+
1820function Demo () {
21+ const refs = useRef ()
22+ const [position , usePosition ]= useState (0 )
23+ useEffect (() => {
24+ const parent = refs .current .getBoundingClientRect ();
25+ console .log (' parent: ' , parent);
26+ usePosition (parent .y )
27+ },[refs .current ])
28+
1929 return (
20- < View style= {{ height: 180 , background : ' #ddd ' }}>
30+ < div ref = {refs} style= {{ height: 200 }}>
2131 < SpeedDial
2232 onOpen= {()=> console .log (' onOpen2' )}
2333 onClose= {()=> console .log (' onClose' )}
24- bottom= {750 }
34+ bottom= {bodyHeight - position }
2535 children= {[
2636 {
2737 icon: ' plus' ,
2838 title: < Text > Add< / Text > ,
2939 onPress : ()=> console .log (' Add' )
3040 },
3141 {
32- icon: < Icon name= ' star-on' color = " #fff " size= {18 } / > ,
42+ icon: < Icon name= ' star-on' size= {18 } / > ,
3343 title: ' Star'
3444 },
3545 {
36- icon: < Icon name= ' mail' color = " #fff " size= {18 } / > ,
46+ icon: < Icon name= ' mail' size= {18 } / > ,
3747 title: ' Mail'
3848 },
3949 {
40- icon: < Icon name= ' share' color = " #fff " size= {18 } / > ,
50+ icon: < Icon name= ' share' size= {18 } / > ,
4151 title: ' Share'
4252 }
4353 ]}
4454 / >
45- < / View >
55+ < / div >
4656 );
4757}
4858export default Demo
@@ -51,39 +61,47 @@ export default Demo
5161### 设置动画时间
5262
5363``` jsx mdx:preview&background=#bebebe29
54- import React , { Fragment } from ' react' ;
64+ import React , { Fragment , useEffect , useRef , useState } from ' react' ;
5565import { SpeedDial , Icon } from ' @uiw/react-native' ;
5666import { View , Text , Dimensions } from ' react-native' ;
5767
68+ const bodyHeight = window .screen .height
5869function Demo () {
70+ const refs = useRef ()
71+ const [position , usePosition ]= useState (0 )
72+ useEffect (() => {
73+ const parent = refs .current .getBoundingClientRect ();
74+ usePosition (parent .y )
75+ },[refs .current ])
76+
5977 return (
60- < View style= {{ height: 180 , background : ' #ddd ' }}>
78+ < div ref = {refs} style= {{ height: 200 }}>
6179 < SpeedDial
6280 transitionDuration= {2000 }
6381 onOpen= {()=> console .log (' onOpen' )}
6482 onClose= {()=> console .log (' onClose' )}
65- bottom= {750 }
83+ bottom= {bodyHeight - (position / 2 ) }
6684 children= {[
6785 {
6886 icon: ' plus' ,
6987 title: < Text > Add< / Text > ,
7088 onPress : ()=> console .log (' Add' )
7189 },
7290 {
73- icon: < Icon name= ' star-on' color = " #fff " size= {18 } / > ,
91+ icon: < Icon name= ' star-on' size= {18 } / > ,
7492 title: ' Star'
7593 },
7694 {
77- icon: < Icon name= ' mail' color = " #fff " size= {18 } / > ,
95+ icon: < Icon name= ' mail' size= {18 } / > ,
7896 title: ' Mail'
7997 },
8098 {
81- icon: < Icon name= ' share' color = " #fff " size= {18 } / > ,
99+ icon: < Icon name= ' share' size= {18 } / > ,
82100 title: ' Share'
83101 }
84102 ]}
85103 / >
86- < / View >
104+ < / div >
87105 );
88106}
89107export default Demo
0 commit comments