+
+
+> [!TIP] [Github 地址](https://github.com/rnc-archive/react-native-drawer-layout-polyfill)
+
+## 安装与使用
+
+进入到工程目录并输入以下命令:
+
+
+
+#### **npm**
+
+```bash
+npm install react-native-drawer-layout-polyfill@2.0.0
+```
+
+#### **yarn**
+
+```bash
+yarn add react-native-drawer-layout-polyfill@2.0.0
+```
+
+
+
+下面的代码展示了这个库的基本使用场景:
+
+```tsx
+import React, { useState, useRef } from "react";
+import { Button, Text, StyleSheet, View, TextInput } from "react-native";
+import DrawerLayout from 'react-native-drawer-layout-polyfill';
+
+const App = () => {
+ const drawerLayoutRef = useRef(null)
+ const [drawerPosition, setDrawerPosition] = useState("left");
+ const [keyboardDismissMode, setKeyboardDismissMode] = useState("none");
+ const [drawerLockMode, setDrawerLockMode] = useState("unlocked ");
+ const [isOpen, setIsOpen] = useState("关闭 ");
+ const [drawerSlideOutput, setDrawerSlideOutput] = useState("");
+ const [drawerStateChangedOutput, setDrawerStateChangedOutput] = useState("");
+ const [drawerWidth, setDrawerWidth] = useState(300);
+ const [value, onChangeText] = useState("");
+
+
+ const open = () =>{
+ drawerLayoutRef.current.openDrawer()
+ }
+
+ const close = () =>{
+ drawerLayoutRef.current.closeDrawer()
+ }
+
+ const changeDrawerPosition = () => {
+ console.log('drawerPosition-修改弹框位置', drawerPosition);
+ if (drawerPosition === "left") {
+ setDrawerPosition("right");
+ } else {
+ setDrawerPosition("left");
+ }
+ };
+
+ const changeDrawerHideKeyboard = () => {
+ console.log('keyboardDismissMode-是否隐藏软键盘', keyboardDismissMode);
+ if (keyboardDismissMode === "none") {
+ setKeyboardDismissMode("on-drag");
+ } else {
+ setKeyboardDismissMode("none");
+ }
+ };
+
+ const changeDrawerWidth = () => {
+ console.log('drawerWidth-修改弹框宽度', drawerWidth);
+ if(value && Number(value) >= 100 ) {
+ setDrawerWidth(Number(value))
+ }
+ }
+
+ const changeDrawerLockMode = (type) => {
+ console.log('drawerLockMode-修改弹框锁定模式', type);
+ setDrawerLockMode(type)
+ };
+
+ const handleDrawerOpen = (e) =>{
+ console.log('onDrawerOpen-打开弹框的回调');
+ setIsOpen('打开')
+ }
+
+ const handleDrawerClose = (e) =>{
+ console.log('onDrawerClose-关闭弹框的回调');
+ setIsOpen('关闭')
+ }
+
+ const handleDrawerSlide = (e) =>{
+ console.log('onDrawerSlide-导航视图发生交互时的回调函数');
+ setDrawerSlideOutput(JSON.stringify(e.nativeEvent))
+ }
+
+ const handleDrawerStateChanged = (e) =>{
+ console.log('onDrawerStateChanged-导航视图的状态发生变化时的回调函数');
+ setDrawerStateChangedOutput(JSON.stringify(e))
+ }
+
+
+ const navigationView = (
+
+ I'm in the Drawer!
+ 弹框状态:{isOpen}
+ 弹框打开关闭过程中触发:{drawerSlideOutput}
+ 弹框状态切换触发:{drawerStateChangedOutput}
+
+ );
+
+ return (
+ navigationView}
+ keyboardDismissMode={keyboardDismissMode}
+ drawerLockMode={drawerLockMode}
+ drawerBackgroundColor="red"
+ statusBarBackgroundColor="blue"
+ onDrawerOpen={handleDrawerOpen}
+ onDrawerClose={handleDrawerClose}
+ onDrawerSlide={handleDrawerSlide}
+ onDrawerStateChanged={handleDrawerStateChanged}
+ >
+
+ 设置导航视图的锁定模式:{drawerLockMode}
+ 是否隐藏软键盘:{keyboardDismissMode}
+ 弹框状态:{isOpen}
+ 弹框打开关闭过程中触发:{drawerSlideOutput}
+ 弹框状态切换触发:{drawerStateChangedOutput}
+
+
+ );
+};
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ alignItems: "center",
+ justifyContent: "center",
+ paddingTop: 50,
+ padding: 8
+ },
+ navigationContainer: {
+ flex: 1,
+ paddingTop: 50,
+ padding: 8
+ },
+ textCommon: {
+ marginBottom:10,
+ fontSize:15
+ },
+ buttonMargin:{
+ marginBottom:5,
+ },
+
+});
+
+export default App;
+```
+
+## 兼容性
+
+在以下版本验证通过
+
+1. RNOH:0.72.13; SDK:HarmonyOS NEXT Developer Preview1; IDE:DevEco Studio 4.1.3.500; ROM:204.1.0.59;
+
+## 属性
+
+详情见[react-native-drawer-layout-polyfill](https://reactnative.dev/docs/drawerlayoutandroid)
+
+
+
+| Name | Description | Type | Required | Platform | HarmonyOS Support | note |
+|--------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|----------|-------------|-------------------|--------------------------------------------------------|
+| renderNavigationView | The navigation view that will be rendered to the side of the screen and can be pulled in. | function | YES | Android IOS | YES | |
+| drawerPosition | Specifies the side of the screen from which the drawer will slide in. By default it is set to left. enum('left', 'right') | string | NO | Android IOS | YES | |
+| drawerWidth | Specifies the width of the drawer, more precisely the width of the view that be pulled in from the edge of the window. | number | NO | Android IOS | YES | |
+| keyboardDismissMode | Determines whether the keyboard gets dismissed in response to a drag. 'none' (the default), drags do not dismiss the keyboard. 'on-drag', the keyboard is dismissed when a drag begins. | string | NO | Android IOS | YES | |
+| drawerLockMode | Specifies the lock mode of the drawer. The drawer can be locked in 3 states: unlocked (default), meaning that the drawer will respond (open/close) to touch gestures. locked-closed, meaning that the drawer will stay closed and not respond to gestures. locked-open, meaning that the drawer will stay opened and not respond to gestures. The drawer may still be opened and closed programmatically (openDrawer/closeDrawer). | string | NO | Android IOS | YES | |
+| drawerBackgroundColor | Specifies the background color of the drawer. The default value is white. If you want to set the opacity of the drawer, use rgba. | string | NO | Android IOS | YES | |
+| statusBarBackgroundColor | Make the drawer take the entire screen and draw the background of the status bar to allow it to open over the status bar. It will only have an effect on API 21+. IOS and harmony are not supported. | string | NO | Android | NO | The original library only does the function of Android |
+| onDrawerOpen | Function called whenever the navigation view has been opened. | function | NO | Android IOS | YES | |
+| onDrawerClose | Function called whenever the navigation view has been closed. | function | NO | Android IOS | YES | |
+| onDrawerSlide | Function called whenever there is an interaction with the navigation view. | function | NO | Android IOS | YES | |
+| onDrawerStateChanged | Function called when the drawer state has changed. The drawer can be in 3 states: idle, meaning there is no interaction with the navigation view happening at the time | function | NO | Android IOS | YES | |
+
+
+
+## 方法
+
+| Name | Description | Required | Platform | HarmonyOS Support |
+|-------------|--------------------|----------|-------------|-------------------|
+| openDrawer | Closes the drawer. | NO | Android IOS | YES |
+| closeDrawer | Opens the drawer. | NO | Android IOS | YES |
+
+
+
+## 遗留问题
+
+## 其他