11Drawer 抽屉
22---
33
4- ![ ] ( https://user-images.githubusercontent.com/66067296/137705595-a9eb337a-90f7-42bd-a662-579063731db3.gif ) <!-- rehype:style=zoom: 33%;float: right; margin-left: 15px; -->
4+
55
66用于在屏幕边缘显示应用导航等内容的面板。
77
88### 基础示例
99
10- ``` jsx
11- import { Fragment , useState } from ' react' ;
10+ ``` jsx mdx:preview
11+ import React , { useState } from ' react' ;
1212import { View , Text } from ' react-native' ;
1313import { Drawer , Button } from ' @uiw/react-native' ;
1414
1515function Demo () {
1616 const [visible , setVisible ] = useState (false );
1717 return (
18- < Fragment >
18+ <>
1919 < Drawer
2020 isOpen= {visible}
2121 onChange= {(isOpen ) => setVisible (isOpen)}
@@ -25,65 +25,102 @@ function Demo() {
2525 < / View>
2626 < / Drawer>
2727 < Button onPress= {() => setVisible (! visible)}> 左边打开抽屉< / Button>
28- < / Fragment >
28+ < / >
2929 );
3030}
31+
32+ export default Demo
33+
3134```
3235
3336### 右边展示
3437
35- ``` jsx
36- import { Fragment , useState } from ' react' ;
38+ ``` jsx mdx:preview
39+ import React , { useState } from ' react' ;
3740import { View , Text } from ' react-native' ;
3841import { Drawer , Button } from ' @uiw/react-native' ;
3942
4043function Demo () {
4144 const [visible , setVisible ] = useState (false );
4245 return (
43- < Fragment >
46+ <>
4447 < Drawer
4548 isOpen= {visible}
4649 placement= " right"
4750 onChange= {(isOpen ) => setVisible (isOpen)}
4851 >
4952 < View>
50- < Text > 左边打开抽屉内容 < / Text >
53+ < Text > 右边打开抽屉内容 < / Text >
5154 < / View>
5255 < / Drawer>
53- < Button onPress= {() => setVisible (! visible)}> 左边打开抽屉 < / Button>
54- < / Fragment >
56+ < Button onPress= {() => setVisible (! visible)}> 右边打开抽屉 < / Button>
57+ < / >
5558 );
5659}
57- ```
5860
59- ### 注意事项 - 抽屉高度是页面有效高度
61+ export default Demo
62+ ```
63+ ### 设置Drawer高度
6064
61- ``` jsx
62- import { Fragment , useState } from ' react' ;
65+ ``` jsx mdx:preview
66+ import React , { useState } from ' react' ;
6367import { View , Text , SafeAreaView } from ' react-native' ;
6468import { Drawer , Button } from ' @uiw/react-native' ;
6569
6670function Demo () {
6771 const [visible , setVisible ] = useState (false );
6872 return (
69- < SafeAreaView style= {{flex : 1 }}>
73+ < SafeAreaView style= {{height : 200 }}>
7074 < Drawer
7175 isOpen= {visible}
76+ placement= " bottom"
77+ drawerHeight= {100 }
7278 onChange= {(isOpen ) => setVisible (isOpen)}
7379 >
7480 < View>
75- < Text > 左边打开抽屉内容 < / Text >
81+ < Text > 下边打开抽屉内容 < / Text >
7682 < / View>
7783 < / Drawer>
78- < Button onPress= {() => setVisible (! visible)}> 左边打开抽屉 < / Button>
84+ < Button onPress= {() => setVisible (! visible)}> 下边打开抽屉 < / Button>
7985 < / SafeAreaView>
8086 );
8187}
88+
89+ export default Demo
90+ ```
91+
92+ ### 修改Drawer宽度
93+
94+ ``` jsx mdx:preview
95+ import React , { useState } from ' react' ;
96+ import { View , Text , SafeAreaView } from ' react-native' ;
97+ import { Drawer , Button } from ' @uiw/react-native' ;
98+
99+ function Demo () {
100+ const [visible , setVisible ] = useState (false );
101+ return (
102+ < View style= {{height: 200 }}>
103+ < Drawer
104+ isOpen= {visible}
105+ onChange= {(isOpen ) => setVisible (isOpen)}
106+ drawerHeight= {10 }
107+ >
108+ < View>
109+ < Text > 打开抽屉内容< / Text >
110+ < / View>
111+ < / Drawer>
112+ < Button onPress= {() => setVisible (! visible)}> 打开抽屉< / Button>
113+ < / View>
114+ );
115+ }
116+ export default Demo
117+
82118```
83119
84120### 抽屉覆盖全屏
85121
86122- 可查看 [ react-native-root-siblings] ( https://www.npmjs.com/package/react-native-root-siblings ) 文档
123+
87124``` jsx
88125// 在 App.js 文件中
89126import React from ' react' ;
0 commit comments