{"id":492,"date":"2023-02-25T14:12:01","date_gmt":"2023-02-25T06:12:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=492"},"modified":"2023-04-29T20:50:24","modified_gmt":"2023-04-29T12:50:24","slug":"react-native-learning-drawerlayoutandroid-component","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/react-native-learning-drawerlayoutandroid-component\/","title":{"rendered":"React Native\u5b66\u4e60\u4e4bDrawerLayoutAndroid\u7ec4\u4ef6"},"content":{"rendered":"<p>\u5c01\u88c5\u4e86\u5e73\u53f0<code>DrawerLayout<\/code>\uff08\u4ec5\u9650\u5b89\u5353\u5e73\u53f0\uff09\u7684React\u7ec4\u4ef6\u3002\u62bd\u5c49\uff08\u901a\u5e38\u7528\u4e8e\u5bfc\u822a\u5207\u6362\uff09\u662f\u901a\u8fc7<code>renderNavigationView<\/code>\u65b9\u6cd5\u6e32\u67d3\u7684\uff0c\u5e76\u4e14<code>DrawerLayoutAndroid<\/code>\u7684\u76f4\u63a5\u5b50\u89c6\u56fe\u4f1a\u6210\u4e3a\u4e3b\u89c6\u56fe\uff08\u7528\u4e8e\u653e\u7f6e\u4f60\u7684\u5185\u5bb9\uff09\u3002\u5bfc\u822a\u89c6\u56fe\u4e00\u5f00\u59cb\u5728\u5c4f\u5e55\u4e0a\u5e76\u4e0d\u53ef\u89c1\uff0c\u4e0d\u8fc7\u53ef\u4ee5\u4ece<code>drawerPosition<\/code>\u6307\u5b9a\u7684\u7a97\u53e3\u4fa7\u9762\u62d6\u62fd\u51fa\u6765\uff0c\u5e76\u4e14\u62bd\u5c49\u7684\u5bbd\u5ea6\u53ef\u4ee5\u4f7f\u7528<code>drawerWidth<\/code>\u5c5e\u6027\u6765\u6307\u5b9a\u3002<\/p>\n<h3>DrawerLayoutAndroid\u7ec4\u4ef6\u7684\u5c5e\u6027<\/h3>\n<p><!-- more --><\/p>\n<ul>\n<li><code>drawerPosition<\/code>\uff1aDrawerLayoutAndroid.positions.Right \u5de6\u53f3 \u9ed8\u8ba4\u5de6<\/li>\n<li><code>drawerWidth<\/code>\uff1a\u6307\u5b9a\u62bd\u5c49\u7684\u5bbd\u5ea6\uff0c\u4e5f\u5c31\u662f\u4ece\u5c4f\u5e55\u8fb9\u7f18\u62d6\u8fdb\u7684\u89c6\u56fe\u7684\u5bbd\u5ea6<\/li>\n<\/ul>\n<h3>DrawerLayoutAndroid\u7ec4\u4ef6\u7684\u65b9\u6cd5<\/h3>\n<ul>\n<li><code>onDrawerClose<\/code><\/li>\n<li><code>onDrawerOpen<\/code><\/li>\n<li><code>onDrawerSlide<\/code>\uff1a\u6bcf\u5f53\u5bfc\u822a\u89c6\u56fe\uff08\u62bd\u5c49\uff09\u4ea7\u751f\u4ea4\u4e92\u7684\u65f6\u5019\u8c03\u7528\u6b64\u56de\u8c03\u51fd\u6570<\/li>\n<li><code>onDrawerStateChanged<\/code>\uff1aidle\uff08\u7a7a\u95f2\uff09 dragging\uff08\u62d6\u62fd\u4e2d\uff09 settling\uff08\u505c\u9760\u4e2d\uff09<\/li>\n<li><code>renderNavigationView<\/code>\uff1a\u6e32\u67d3\u4e00\u4e2a\u53ef\u4ee5\u4ece\u5c4f\u5e55\u4e00\u8fb9\u62d6\u5165\u7684\u5bfc\u822a\u89c6\u56fe<\/li>\n<\/ul>\n<h3>DrawerLayoutAndroid\u7ec4\u4ef6\u7684\u6a21\u5f0f<\/h3>\n<p><code>drawerLockMode<\/code>\uff1a\u8bbe\u7f6e\u62bd\u5c49\u7684\u9501\u5b9a\u6a21\u5f0f \u6709\u4e09\u79cd\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li><code>unlocked<\/code> (\u9ed8\u8ba4\u503c)\uff0c\u610f\u5473\u7740\u6b64\u65f6\u62bd\u5c49\u53ef\u4ee5\u54cd\u5e94\u6253\u5f00\u548c\u5173\u95ed\u7684\u624b\u52bf\u64cd\u4f5c<\/li>\n<li><code>locked-closed<\/code>\uff0c\u610f\u5473\u7740\u6b64\u65f6\u62bd\u5c49\u5c06\u4fdd\u6301\u5173\u95ed\uff0c\u4e0d\u53ef\u7528\u624b\u52bf\u6253\u5f00\u3002<\/li>\n<li><code>locked-open<\/code>\uff0c\u610f\u5473\u7740\u6b64\u65f6\u62bd\u5c49\u5c06\u4fdd\u6301\u6253\u5f00\uff0c\u4e0d\u53ef\u7528\u624b\u52bf\u5173\u95ed\u3002<\/li>\n<\/ul>\n<p>\u65e0\u8bba\u62bd\u5c49\u5904\u4e8e\u90a3\u79cd\u72b6\u6001\uff0c\u90fd\u4ecd\u7136\u53ef\u4ee5\u8c03\u7528<code>openDrawer\/closeDrawer<\/code>\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u6253\u5f00\u548c\u5173\u95ed<\/p>\n<p>\u6e90\u7801\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/**\n * Sample React Native App\n * https:\/\/github.com\/facebook\/react-native\n *\/\n&#039;use strict&#039;;\n\nimport React, { Component } from &#039;react&#039;;\nimport {\n    AppRegistry,\n    StyleSheet,\n    PixelRatio,\n    Text,\n    Image,\n    TouchableOpacity,\n    DrawerLayoutAndroid,\n    View\n} from &#039;react-native&#039;;\n\nclass RNAPP extends Component {\n    render() {\n        var navigationView = (\n            &lt;View style={{flex: 1, backgroundColor: &#039;#ff0&#039;}}&gt;\n                &lt;Text style={{margin: 10, fontSize: 15, textAlign: &#039;left&#039;}}&gt;\u6211\u662f\u62bd\u5c49!&lt;\/Text&gt;\n            &lt;\/View&gt;\n        );\n\n        return (\n            &lt;DrawerLayoutAndroid\n                drawerWidth={100}\n                drawerPosition={DrawerLayoutAndroid.positions.Right}\n                renderNavigationView={() =&gt; navigationView}\n                &gt;\n\n                &lt;View style={{flex: 1, alignItems: &#039;center&#039;}}&gt;\n                    &lt;Text style={{margin: 10, fontSize: 15, textAlign: &#039;right&#039;}}&gt;Hello&lt;\/Text&gt;\n                    &lt;Text style={{margin: 10, fontSize: 15, textAlign: &#039;right&#039;}}&gt;React Native World!&lt;\/Text&gt;\n                &lt;\/View&gt;\n            &lt;\/DrawerLayoutAndroid&gt;\n        );\n    }\n}\n\nconst styles = StyleSheet.create({\n    flex:{\n        flex:1,\n    },\n});\n\nAppRegistry.registerComponent(&#039;RNAPP&#039;, () =&gt; RNAPP);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c01\u88c5\u4e86\u5e73\u53f0DrawerLayout\uff08\u4ec5\u9650\u5b89\u5353\u5e73\u53f0\uff09\u7684React\u7ec4\u4ef6\u3002\u62bd\u5c49\uff08\u901a\u5e38\u7528\u4e8e\u5bfc\u822a\u5207\u6362\uff09\u662f\u901a\u8fc7render [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-492","post","type-post","status-publish","format-standard","hentry","category-react-native"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}