From d50116c6cb19585840d1ac1c218f7a58e5ea175e Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Mon, 30 Jan 2023 22:38:18 +0100 Subject: [PATCH] feat: extract drawer to a separate package --- packages/react-native-drawer-layout/LICENSE | 21 + packages/react-native-drawer-layout/README.md | 257 +++++++ .../react-native-drawer-layout/package.json | 66 ++ .../src/constants.tsx | 4 + .../react-native-drawer-layout/src/index.tsx | 4 + .../react-native-drawer-layout/src/types.tsx | 116 +++ .../src/utils/DrawerGestureContext.tsx | 3 + .../src/utils/DrawerProgressContext.tsx | 6 + .../src/utils/useDrawerProgress.tsx | 18 + .../src/views/Drawer.tsx | 122 ++++ .../src/views/GestureHandler.android.tsx | 1 + .../src/views/GestureHandler.ios.tsx | 1 + .../src/views/GestureHandler.tsx | 29 + .../src/views/GestureHandlerNative.tsx | 24 + .../src/views/legacy/Drawer.tsx | 681 ++++++++++++++++++ .../src/views/legacy/Overlay.tsx | 75 ++ .../src/views/modern/Drawer.tsx | 412 +++++++++++ .../src/views/modern/Overlay.tsx | 70 ++ .../tsconfig.build.json | 6 + .../react-native-drawer-layout/tsconfig.json | 7 + 20 files changed, 1923 insertions(+) create mode 100644 packages/react-native-drawer-layout/LICENSE create mode 100644 packages/react-native-drawer-layout/README.md create mode 100644 packages/react-native-drawer-layout/package.json create mode 100644 packages/react-native-drawer-layout/src/constants.tsx create mode 100644 packages/react-native-drawer-layout/src/index.tsx create mode 100644 packages/react-native-drawer-layout/src/types.tsx create mode 100644 packages/react-native-drawer-layout/src/utils/DrawerGestureContext.tsx create mode 100644 packages/react-native-drawer-layout/src/utils/DrawerProgressContext.tsx create mode 100644 packages/react-native-drawer-layout/src/utils/useDrawerProgress.tsx create mode 100644 packages/react-native-drawer-layout/src/views/Drawer.tsx create mode 100644 packages/react-native-drawer-layout/src/views/GestureHandler.android.tsx create mode 100644 packages/react-native-drawer-layout/src/views/GestureHandler.ios.tsx create mode 100644 packages/react-native-drawer-layout/src/views/GestureHandler.tsx create mode 100644 packages/react-native-drawer-layout/src/views/GestureHandlerNative.tsx create mode 100644 packages/react-native-drawer-layout/src/views/legacy/Drawer.tsx create mode 100644 packages/react-native-drawer-layout/src/views/legacy/Overlay.tsx create mode 100644 packages/react-native-drawer-layout/src/views/modern/Drawer.tsx create mode 100644 packages/react-native-drawer-layout/src/views/modern/Overlay.tsx create mode 100644 packages/react-native-drawer-layout/tsconfig.build.json create mode 100644 packages/react-native-drawer-layout/tsconfig.json diff --git a/packages/react-native-drawer-layout/LICENSE b/packages/react-native-drawer-layout/LICENSE new file mode 100644 index 0000000000..001d6a9bd1 --- /dev/null +++ b/packages/react-native-drawer-layout/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 React Native Community + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/react-native-drawer-layout/README.md b/packages/react-native-drawer-layout/README.md new file mode 100644 index 0000000000..4130b7d381 --- /dev/null +++ b/packages/react-native-drawer-layout/README.md @@ -0,0 +1,257 @@ +# React Native Drawer Layout + +A cross-platform Drawer component for React Native. Implemented using [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/). + +Note that swipe gestures are only supported on iOS and Android. + +## Installation + +Open a Terminal in the project root and run: + +```sh +npm install react-native-drawer-layout +``` + +Then, you need to install and configure the libraries that are required by the drawer: + +1. First, install [`react-native-gesture-handler`](https://docs.swmansion.com/react-native-gesture-handler/) and [`react-native-reanimated`](https://docs.swmansion.com/react-native-reanimated/). + + If you have a Expo managed project, in your project directory, run: + + ```sh + npx expo install react-native-gesture-handler react-native-reanimated + ``` + + If you have a bare React Native project, in your project directory, run: + + ```bash npm2yarn + npm install react-native-gesture-handler react-native-reanimated + ``` + + The Drawer supports both Reanimated 1 and Reanimated 2. If you want to use Reanimated 2, make sure to configure it following the [installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation). + +2. To finalize installation of `react-native-gesture-handler`, add the following at the **top** (make sure it's at the top and there's nothing else before it) of your entry file, such as `index.js` or `App.js`: + + ```js + import 'react-native-gesture-handler'; + ``` + + > Note: If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms. + +3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking. + +```sh +npx pod-install ios +``` + +We're done! Now you can build and run the app on your device/simulator. + +## Quick Start + +```js +import * as React from 'react'; +import { Button, Text } from 'react-native'; +import { Drawer } from 'react-native-drawer-layout'; + +export default function DrawerExample() { + const [open, setOpen] = React.useState(false); + + return ( + setOpen(true)} + onClose={() => setOpen(false)} + renderDrawerContent={() => { + return Drawer content; + }} + > +