Drawer 抽屉

从左侧滑出的模态,包含各种导航分类。

规则

  • 是 Android 推荐的导航方式,常见于该平台应用。

代码演示

基本

遮罩层模式

  1. import { Drawer, List, NavBar } from 'antd-mobile';
  2. const App1 = React.createClass({
  3. getInitialState() {
  4. return {
  5. open: false,
  6. position: 'left',
  7. };
  8. },
  9. onOpenChange(isOpen) {
  10. console.log(isOpen, arguments);
  11. this.setState({ open: !this.state.open });
  12. },
  13. render() {
  14. const sidebar = (<List>
  15. {[...Array(20).keys()].map((i, index) => {
  16. if (index === 0) {
  17. return (<List.Item key={index}
  18. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  19. multipleLine
  20. >分类</List.Item>);
  21. }
  22. return (<List.Item key={index}
  23. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  24. >分类{index}</List.Item>);
  25. })}
  26. </List>);
  27. const drawerProps = {
  28. open: this.state.open,
  29. position: this.state.position,
  30. onOpenChange: this.onOpenChange,
  31. };
  32. return (<div style={{ height: '100%' }}>
  33. <NavBar iconName="ellipsis" onLeftClick={this.onOpenChange}>基本</NavBar>
  34. <Drawer
  35. className="my-drawer"
  36. sidebar={sidebar}
  37. dragHandleStyle={{ display: 'none' }}
  38. contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
  39. {...drawerProps}
  40. >
  41. 请点击左上角图标
  42. </Drawer>
  43. </div>);
  44. },
  45. });
  46. ReactDOM.render(<App1 />, mountNode);
  1. .my-drawer {
  2. position: relative;
  3. height: 100%;
  4. overflow: auto;
  5. }
  6. .my-drawer .am-drawer-sidebar {
  7. max-width: 4.6rem;
  8. background-color: #fff;
  9. overflow: auto;
  10. }
  11. .my-drawer .am-drawer-sidebar .am-list {
  12. padding: 0;
  13. }

嵌入文档模式

嵌入到文档流中

  1. import { Drawer, List, NavBar } from 'antd-mobile';
  2. const App = React.createClass({
  3. getInitialState() {
  4. return {
  5. docked: false,
  6. };
  7. },
  8. onDock(d) {
  9. this.setState({
  10. [d]: !this.state[d],
  11. });
  12. },
  13. render() {
  14. const sidebar = (<List>
  15. {[...Array(20).keys()].map((i, index) => {
  16. if (index === 0) {
  17. return (<List.Item key={index}
  18. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  19. multipleLine
  20. >分类</List.Item>);
  21. }
  22. return (<List.Item key={index}
  23. thumb="https://zos.alipayobjects.com/rmsportal/eOZidTabPoEbPeU.png"
  24. >分类{index}</List.Item>);
  25. })}
  26. </List>);
  27. const drawerProps = {
  28. docked: this.state.docked,
  29. open: false,
  30. position: 'left',
  31. };
  32. return (<div style={{ height: '100%' }}>
  33. <NavBar iconName="ellipsis" onLeftClick={() => this.onDock('docked')}>嵌入文档</NavBar>
  34. <Drawer
  35. className="my-drawer"
  36. sidebar={sidebar}
  37. dragHandleStyle={{ display: 'none' }}
  38. sidebarStyle={{ border: '1px solid #ddd' }}
  39. contentStyle={{ color: '#A6A6A6', textAlign: 'center', paddingTop: 42 }}
  40. {...drawerProps}
  41. >
  42. 请点击左上角图标
  43. </Drawer>
  44. </div>);
  45. },
  46. });
  47. ReactDOM.render(<App />, mountNode);
  1. .my-drawer {
  2. position: relative;
  3. height: 100%;
  4. overflow: auto;
  5. }
  6. .my-drawer .am-drawer-sidebar {
  7. max-width: 4.6rem;
  8. background-color: #fff;
  9. overflow: auto;
  10. }
  11. .my-drawer .am-drawer-sidebar .am-list {
  12. padding: 0;
  13. }

Drawer抽屉 - 图1

API ( 适用平台:WEB、React-Native )

成员说明类型默认值
children主要内容any-
sidebar抽屉里的内容any-
onOpenChangeopen 状态切换时调用(open: bool): void-
position抽屉所在位置String'left', enum{'left', 'right', 'top'(web only), 'bottom'(web only)}
sidebarStyle (web only)-Object{}
contentStyle (web only)-Object{}
overlayStyle(web only)-Object{}
dragHandleStyle(web only)-Object{}
touch(web only)是否开启触摸手势Booleantrue
transitions(web only)是否开启动画Booleantrue
docked(web only)是否嵌入到正常文档流里Booleanfalse
dragToggleDistance(web only)打开关闭抽屉时距 sidebar 的拖动距离Number30
open(web only)开关状态Booleanfalse
drawerWidth (rn only)抽屉宽度Number300
drawerBackgroundColor (rn only)指定抽屉背景色String-
openDrawer (rn only)打开函数(): void-
closeDrawer (rn only)关闭函数(): void-