├── .editorconfig ├── .gitattributes ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore ├── .tool-versions ├── .yarn └── releases │ └── yarn-4.1.1.cjs ├── .yarnrc.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── android ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── src │ ├── main │ ├── AndroidManifest.xml │ ├── AndroidManifestNew.xml │ └── java │ │ └── com │ │ └── reactnativemenu │ │ ├── MenuOnCloseEvent.kt │ │ ├── MenuOnOpenEvent.kt │ │ ├── MenuOnPressActionEvent.kt │ │ ├── MenuPackage.kt │ │ ├── MenuView.kt │ │ └── MenuViewManagerBase.kt │ ├── newarch │ └── MenuViewManagerSpec.kt │ ├── oldarch │ └── MenuViewManagerSpec.kt │ └── reactNativeVersionPatch │ └── MenuViewManager │ ├── 75 │ └── com │ │ └── reactnativemenu │ │ └── MenuViewManager.kt │ └── latest │ └── com │ └── reactnativemenu │ └── MenuViewManager.kt ├── babel.config.js ├── biome.json ├── example ├── .gitignore ├── .watchmanconfig ├── android │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── Podfile │ └── Podfile.lock ├── src │ └── App.tsx └── visionos │ ├── Podfile │ └── Podfile.lock ├── ios ├── Menu-Bridging-Header.h ├── MenuViewManager.mm ├── NewArch │ ├── FabricActionSheetView.swift │ ├── FabricMenuViewImplementation.swift │ ├── FabricViewImplementationProtocol.swift │ ├── MenuView.h │ └── MenuView.mm ├── OldArch │ ├── LegacyActionSheetView.swift │ └── LegacyMenuViewImplementation.swift └── Shared │ ├── ActionSheetView.swift │ ├── MenuViewImplementation.swift │ ├── RCTAlertAction.swift │ └── RCTMenuItem.swift ├── metro.config.js ├── package.json ├── plugin └── withAndroidDrawables.js ├── react-native-menu.podspec ├── react-native.config.js ├── src ├── NativeModuleSpecs │ └── UIMenuNativeComponent.ts ├── UIMenuView.android.tsx ├── UIMenuView.ios.tsx ├── UIMenuView.tsx ├── __tests__ │ └── index.test.tsx ├── index.tsx ├── types.ts └── utils.ts ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @Naturalclar 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | 4 | 5 | 6 | # Test Plan 7 | 8 | 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | ignore: 9 | - dependency-name: pod-install 10 | versions: 11 | - 0.1.16 12 | - 0.1.17 13 | - 0.1.19 14 | - 0.1.20 15 | - dependency-name: release-it 16 | versions: 17 | - 14.2.2 18 | - 14.3.0 19 | - 14.4.0 20 | - 14.4.1 21 | - 14.5.0 22 | - 14.5.1 23 | - dependency-name: eslint 24 | versions: 25 | - 7.18.0 26 | - 7.20.0 27 | - 7.23.0 28 | - dependency-name: "@types/react-native" 29 | versions: 30 | - 0.63.49 31 | - 0.63.51 32 | - 0.64.0 33 | - dependency-name: react-native 34 | versions: 35 | - 0.64.0 36 | - dependency-name: react 37 | versions: 38 | - 17.0.1 39 | - dependency-name: typescript 40 | versions: 41 | - 4.1.4 42 | - 4.2.3 43 | - dependency-name: eslint-config-prettier 44 | versions: 45 | - 8.0.0 46 | - dependency-name: prettier 47 | versions: 48 | - 2.2.1 49 | - dependency-name: "@types/react" 50 | versions: 51 | - 17.0.0 52 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | pull_request: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | lint: 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node-version: [20] 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v1 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - name: Get yarn cache 20 | id: yarn-cache 21 | run: echo "::set-output name=dir::$(yarn cache dir)" 22 | - uses: actions/cache@v4 23 | with: 24 | path: ${{ steps.yarn-cache.outputs.dir }} 25 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 26 | - name: Install Dependencies 27 | run: yarn 28 | - name: ESLint Checks 29 | run: yarn lint 30 | tsc: 31 | runs-on: ubuntu-latest 32 | strategy: 33 | matrix: 34 | node-version: [20] 35 | steps: 36 | - uses: actions/checkout@v2 37 | - uses: actions/setup-node@v1 38 | with: 39 | node-version: ${{ matrix.node-version }} 40 | - name: Get yarn cache 41 | id: yarn-cache 42 | run: echo "::set-output name=dir::$(yarn cache dir)" 43 | - uses: actions/cache@v4 44 | with: 45 | path: ${{ steps.yarn-cache.outputs.dir }} 46 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 47 | - name: Install Dependencies 48 | run: yarn 49 | - name: TypeScript type check 50 | run: yarn typescript 51 | android: 52 | runs-on: ubuntu-latest 53 | strategy: 54 | matrix: 55 | node-version: [20] 56 | steps: 57 | - uses: actions/checkout@v2 58 | - uses: actions/setup-node@v1 59 | with: 60 | node-version: ${{ matrix.node-version }} 61 | - uses: actions/setup-java@v1 62 | with: 63 | java-version: "17" 64 | - name: Get yarn cache 65 | id: yarn-cache 66 | run: echo "::set-output name=dir::$(yarn cache dir)" 67 | - uses: actions/cache@v4 68 | with: 69 | path: ${{ steps.yarn-cache.outputs.dir }} 70 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 71 | - name: Install Dependencies 72 | run: yarn && yarn bootstrap 73 | - name: Build Android Example App and Library 74 | run: cd example/android && ./gradlew clean assembleDebug 75 | ios: 76 | runs-on: macos-latest 77 | strategy: 78 | matrix: 79 | node-version: [20] 80 | arch: ["NewArch", "OldArch"] 81 | steps: 82 | - uses: actions/checkout@v2 83 | - uses: actions/setup-node@v1 84 | with: 85 | node-version: ${{ matrix.node-version }} 86 | - name: Get yarn cache 87 | id: yarn-cache 88 | run: echo "::set-output name=dir::$(yarn cache dir)" 89 | - uses: actions/cache@v4 90 | with: 91 | path: ${{ steps.yarn-cache.outputs.dir }} 92 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} 93 | - name: Get arch value 94 | run: echo "RCT_NEW_ARCH_ENABLED=${{ matrix.arch == 'NewArch' && '1' || '0' }}" >> $GITHUB_ENV 95 | - name: Install Dependencies 96 | run: yarn && yarn bootstrap 97 | - name: Install Podfiles 98 | run: cd example && npx pod-install 99 | - name: Print React Native Info 100 | run: cd example && npx react-native info 101 | - name: Build example app 102 | run: cd example && yarn ios --no-packager 103 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .idea 35 | .gradle 36 | local.properties 37 | android.iml 38 | 39 | # Cocoapods 40 | # 41 | example/ios/Pods 42 | 43 | # node.js 44 | # 45 | node_modules/ 46 | npm-debug.log 47 | yarn-debug.log 48 | yarn-error.log 49 | 50 | # BUCK 51 | buck-out/ 52 | \.buckd/ 53 | android/app/libs 54 | android/keystores/debug.keystore 55 | 56 | # Expo 57 | .expo/* 58 | 59 | # generated by bob 60 | lib/ 61 | 62 | # yarn 63 | .yarn/install-state.gz -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 2.7.6 2 | java adoptopenjdk-17.0.10+7 3 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-4.1.1.cjs 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn bootstrap` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn bootstrap 11 | ``` 12 | 13 | While developing, you can run the [example app](/example/) to test your changes. 14 | 15 | To start the packager: 16 | 17 | ```sh 18 | yarn start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn android 25 | ``` 26 | 27 | To run the example app on iOS: 28 | 29 | ```sh 30 | yarn ios 31 | ``` 32 | 33 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 34 | 35 | ```sh 36 | yarn typescript 37 | yarn lint 38 | ``` 39 | 40 | To fix formatting errors, run the following: 41 | 42 | ```sh 43 | yarn lint --fix 44 | ``` 45 | 46 | Remember to add tests for your change if possible. Run the unit tests by: 47 | 48 | ```sh 49 | yarn test 50 | ``` 51 | 52 | To edit the Objective-C files, open `example/ios/MenuExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-menu`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativemenu` under `Android`. 55 | 56 | ### Versioning in `MenuViewManager` 57 | 58 | As of the latest update, `com.reactnativemenu.MenuViewManager` has been refactored into an abstract base class, `MenuViewManagerBase`. Any React Native version-dependent changes should be implemented in the specific version folders under `reactNativeVersionPatch`. 59 | 60 | For consistency: 61 | 62 | - When making version-specific modifications, ensure you update the appropriate implementation of `MenuViewManager`: 63 | - `src/reactNativeVersionPatch/75/MenuViewManager.kt` for React Native < 0.76 64 | - `src/reactNativeVersionPatch/latest/MenuViewManager.kt` for React Native >= 0.76 65 | - If adding a new file that depends on React Native version, create folders under `reactNativeVersionPatch` for both `75` and `latest` and include the version-specific implementations there. 66 | - Update `build.gradle` to include the new file in the `sourceSets`, so it’s dynamically selected based on the React Native version. 67 | 68 | This approach ensures consistent version handling and clean separation of code across versions. 69 | 70 | ### Commit message convention 71 | 72 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 73 | 74 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 75 | - `feat`: new features, e.g. add new method to the module. 76 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 77 | - `docs`: changes into documentation, e.g. add usage example for the module.. 78 | - `test`: adding or updating tests, e.g. add integration tests using detox. 79 | - `chore`: tooling changes, e.g. change CI config. 80 | 81 | Our pre-commit hooks verify that your commit message matches this format when committing. 82 | 83 | ### Linting and tests 84 | 85 | [Biome](https://biomejs.dev/), [TypeScript](https://www.typescriptlang.org/) 86 | 87 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [Biome](https://biomejs.dev/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 88 | 89 | Our pre-commit hooks verify that the linter and tests pass when committing. 90 | 91 | ### Scripts 92 | 93 | The `package.json` file contains various scripts for common tasks: 94 | 95 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 96 | - `yarn typescript`: type-check files with TypeScript. 97 | - `yarn lint`: lint files with Biome. 98 | - `yarn test`: run unit tests with Jest. 99 | - `yarn start`: start the Metro server for the example app. 100 | - `yarn android`: run the example app on Android. 101 | - `yarn ios`: run the example app on iOS. 102 | 103 | ### Sending a pull request 104 | 105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github). 106 | 107 | When you're sending a pull request: 108 | 109 | - Prefer small pull requests focused on one change. 110 | - Verify that linters and tests are passing. 111 | - Review the documentation to make sure it looks good. 112 | - Follow the pull request template when opening a pull request. 113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 114 | - For version-dependent changes, follow the versioning structure for `MenuViewManager` outlined in the **Versioning in `MenuViewManager`** section. Ensure all version-specific files are included in `reactNativeVersionPatch` and referenced in `build.gradle`. 115 | 116 | ## Code of Conduct 117 | 118 | ### Our Pledge 119 | 120 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 121 | 122 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 123 | 124 | ### Our Standards 125 | 126 | Examples of behavior that contributes to a positive environment for our community include: 127 | 128 | - Demonstrating empathy and kindness toward other people 129 | - Being respectful of differing opinions, viewpoints, and experiences 130 | - Giving and gracefully accepting constructive feedback 131 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 132 | - Focusing on what is best not just for us as individuals, but for the overall community 133 | 134 | Examples of unacceptable behavior include: 135 | 136 | - The use of sexualized language or imagery, and sexual attention or 137 | advances of any kind 138 | - Trolling, insulting or derogatory comments, and personal or political attacks 139 | - Public or private harassment 140 | - Publishing others' private information, such as a physical or email 141 | address, without their explicit permission 142 | - Other conduct which could reasonably be considered inappropriate in a 143 | professional setting 144 | 145 | ### Enforcement Responsibilities 146 | 147 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 148 | 149 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 150 | 151 | ### Scope 152 | 153 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 154 | 155 | ### Enforcement 156 | 157 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 158 | 159 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 160 | 161 | ### Enforcement Guidelines 162 | 163 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 164 | 165 | #### 1. Correction 166 | 167 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 168 | 169 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 170 | 171 | #### 2. Warning 172 | 173 | **Community Impact**: A violation through a single incident or series of actions. 174 | 175 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 176 | 177 | #### 3. Temporary Ban 178 | 179 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 180 | 181 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 182 | 183 | #### 4. Permanent Ban 184 | 185 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 186 | 187 | **Consequence**: A permanent ban from any sort of public interaction within the community. 188 | 189 | ### Attribution 190 | 191 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 192 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 193 | 194 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 195 | 196 | [homepage]: https://www.contributor-covenant.org 197 | 198 | For answers to common questions about this code of conduct, see the FAQ at 199 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 200 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jesse Katsumata 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @react-native-menu/menu 2 | 3 | ![Supports Android, iOS][support-badge]![Github Action Badge][gha-badge] ![npm][npm-badge] 4 | 5 | Android PopupMenu and iOS14+ UIMenu components for react-native. 6 | Falls back to ActionSheet for versions below iOS14. 7 | 8 | | Android | iOS 14+ | iOS 13 | 9 | |--------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------| 10 | | | | | 11 | 12 | ## Installation 13 | 14 | via npm: 15 | 16 | ```sh 17 | npm install @react-native-menu/menu 18 | ``` 19 | 20 | via yarn: 21 | 22 | ```sh 23 | yarn add @react-native-menu/menu 24 | ``` 25 | 26 | ### Installing on iOS with React Native 0.63 and above 27 | 28 | There is an issue(https://github.com/facebook/react-native/issues/29246) causing projects with this module to fail on build on React Native 0.63 and above. 29 | This issue may be fixed in future versions of react native. 30 | As a work around, look for lines in `[YourPrject].xcodeproj` under `LIBRARY_SEARCH_PATHS` with `"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",` and change `swift-5.0` to `swift-5.3`. 31 | 32 | ## Linking 33 | 34 | The package is [automatically linked](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) when building the app. All you need to do is: 35 | 36 | ```sh 37 | npx pod-install 38 | ``` 39 | 40 | ## Usage 41 | 42 | ```jsx 43 | import { MenuView, MenuComponentRef } from '@react-native-menu/menu'; 44 | 45 | // ... 46 | 47 | const App = () => { 48 | const menuRef = useRef(null); 49 | return ( 50 | 51 |