├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .husky ├── .npmignore ├── commit-msg └── pre-commit ├── .yarnrc ├── CONTRIBUTING.md ├── Doc ├── android.gif └── ios.gif ├── Example ├── .gitattributes ├── .gitignore ├── app.json ├── package.json ├── src │ └── App.tsx ├── tsconfig.json └── yarn.lock ├── LICENSE ├── README.md ├── babel.config.js ├── doc ├── android.gif └── ios.gif ├── package.json ├── scripts └── bootstrap.js ├── src ├── TooltipMenu.tsx ├── TooltipMenuItem.tsx └── index.ts ├── tsconfig.build.json ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /.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 4 | -------------------------------------------------------------------------------- /.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 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # node.js 48 | # 49 | node_modules/ 50 | npm-debug.log 51 | yarn-debug.log 52 | yarn-error.log 53 | 54 | # BUCK 55 | buck-out/ 56 | \.buckd/ 57 | android/app/libs 58 | android/keystores/debug.keystore 59 | 60 | # Expo 61 | .expo/* 62 | 63 | # generated by bob 64 | lib/ 65 | -------------------------------------------------------------------------------- /.husky/.npmignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint -E HUSKY_GIT_PARAMS 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn typescript 5 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 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` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | To run the example app on Android: 24 | 25 | ```sh 26 | yarn example android 27 | ``` 28 | 29 | To run the example app on iOS: 30 | 31 | ```sh 32 | yarn example ios 33 | ``` 34 | 35 | To run the example app on Web: 36 | 37 | ```sh 38 | yarn example web 39 | ``` 40 | 41 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 42 | 43 | ```sh 44 | yarn typescript 45 | yarn lint 46 | ``` 47 | 48 | To fix formatting errors, run the following: 49 | 50 | ```sh 51 | yarn lint --fix 52 | ``` 53 | 54 | Remember to add tests for your change if possible. Run the unit tests by: 55 | 56 | ```sh 57 | yarn test 58 | ``` 59 | 60 | ### Commit message convention 61 | 62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 63 | 64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 65 | - `feat`: new features, e.g. add new method to the module. 66 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 67 | - `docs`: changes into documentation, e.g. add usage example for the module.. 68 | - `test`: adding or updating tests, e.g. add integration tests using detox. 69 | - `chore`: tooling changes, e.g. change CI config. 70 | 71 | Our pre-commit hooks verify that your commit message matches this format when committing. 72 | 73 | ### Linting and tests 74 | 75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 76 | 77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 78 | 79 | Our pre-commit hooks verify that the linter and tests pass when committing. 80 | 81 | ### Publishing to npm 82 | 83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 84 | 85 | To publish new versions, run the following: 86 | 87 | ```sh 88 | yarn release 89 | ``` 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 ESLint. 98 | - `yarn test`: run unit tests with Jest. 99 | - `yarn example start`: start the Metro server for the example app. 100 | - `yarn example android`: run the example app on Android. 101 | - `yarn example 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://app.egghead.io/playlists/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 | 115 | ## Code of Conduct 116 | 117 | ### Our Pledge 118 | 119 | 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. 120 | 121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 122 | 123 | ### Our Standards 124 | 125 | Examples of behavior that contributes to a positive environment for our community include: 126 | 127 | - Demonstrating empathy and kindness toward other people 128 | - Being respectful of differing opinions, viewpoints, and experiences 129 | - Giving and gracefully accepting constructive feedback 130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 131 | - Focusing on what is best not just for us as individuals, but for the overall community 132 | 133 | Examples of unacceptable behavior include: 134 | 135 | - The use of sexualized language or imagery, and sexual attention or 136 | advances of any kind 137 | - Trolling, insulting or derogatory comments, and personal or political attacks 138 | - Public or private harassment 139 | - Publishing others' private information, such as a physical or email 140 | address, without their explicit permission 141 | - Other conduct which could reasonably be considered inappropriate in a 142 | professional setting 143 | 144 | ### Enforcement Responsibilities 145 | 146 | 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. 147 | 148 | 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. 149 | 150 | ### Scope 151 | 152 | 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. 153 | 154 | ### Enforcement 155 | 156 | 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. 157 | 158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 159 | 160 | ### Enforcement Guidelines 161 | 162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 163 | 164 | #### 1. Correction 165 | 166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 167 | 168 | **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. 169 | 170 | #### 2. Warning 171 | 172 | **Community Impact**: A violation through a single incident or series of actions. 173 | 174 | **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. 175 | 176 | #### 3. Temporary Ban 177 | 178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 179 | 180 | **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. 181 | 182 | #### 4. Permanent Ban 183 | 184 | **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. 185 | 186 | **Consequence**: A permanent ban from any sort of public interaction within the community. 187 | 188 | ### Attribution 189 | 190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 192 | 193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 194 | 195 | [homepage]: https://www.contributor-covenant.org 196 | 197 | For answers to common questions about this code of conduct, see the FAQ at 198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 199 | -------------------------------------------------------------------------------- /Doc/android.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimek/react-native-tooltip-menu/f627ed92d9e1ff562564f3ec81d4420a52b4d597/Doc/android.gif -------------------------------------------------------------------------------- /Doc/ios.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimek/react-native-tooltip-menu/f627ed92d9e1ff562564f3ec81d4420a52b4d597/Doc/ios.gif -------------------------------------------------------------------------------- /Example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | -------------------------------------------------------------------------------- /Example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 50 | 51 | fastlane/report.xml 52 | fastlane/Preview.html 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /Example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-tooltip-menu-example", 3 | "expo": { 4 | "name": "react-native-tooltip-menu-example", 5 | "slug": "react-native-tooltip-menu-example", 6 | "description": "Example app for react-native-tooltip-menu", 7 | "privacy": "public", 8 | "version": "1.0.0", 9 | "platforms": [ 10 | "ios", 11 | "android", 12 | "web" 13 | ], 14 | "ios": { 15 | "supportsTablet": true 16 | }, 17 | "assetBundlePatterns": [ 18 | "**/*" 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-tooltip-menu-example", 3 | "description": "Example app for react-native-tooltip-menu", 4 | "version": "0.0.1", 5 | "private": true, 6 | "main": "index", 7 | "scripts": { 8 | "android": "expo start --android", 9 | "ios": "expo start --ios", 10 | "web": "expo start --web", 11 | "start": "expo start", 12 | "test": "jest" 13 | }, 14 | "dependencies": { 15 | "expo": "^42.0.0", 16 | "expo-splash-screen": "~0.11.2", 17 | "react": "16.13.1", 18 | "react-dom": "16.13.1", 19 | "react-native": "0.63.4", 20 | "react-native-unimodules": "~0.14.5", 21 | "react-native-web": "~0.13.12" 22 | }, 23 | "devDependencies": { 24 | "@babel/core": "~7.9.0", 25 | "@babel/runtime": "^7.9.6", 26 | "babel-plugin-module-resolver": "^4.0.0", 27 | "babel-preset-expo": "8.3.0", 28 | "expo-cli": "^4.0.13" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | 3 | import { StyleSheet, View, Text, SafeAreaView } from 'react-native'; 4 | // @ts-ignore 5 | import { TooltipMenu } from 'react-native-tooltip-menu'; 6 | 7 | export default function App() { 8 | return ( 9 | 10 | 11 | { 21 | // @ts-ignore 22 | alert('pressed test'); 23 | }, 24 | }, 25 | { 26 | label: () => Test2, 27 | onPress: () => { 28 | // @ts-ignore 29 | alert('pressed test2'); 30 | }, 31 | }, 32 | ]} 33 | > 34 | 42 | Button 43 | 44 | 45 | 46 | 47 | ); 48 | } 49 | 50 | const styles = StyleSheet.create({ 51 | container: { 52 | flex: 1, 53 | backgroundColor: 'green', 54 | position: 'relative', 55 | }, 56 | box: { 57 | width: 60, 58 | height: 60, 59 | marginVertical: 20, 60 | }, 61 | }); 62 | -------------------------------------------------------------------------------- /Example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": {}, 3 | "extends": "expo/tsconfig.base" 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 d 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-tooltip-menu 2 | 3 | Currently works only with `iOS` and `Android`. 4 | 5 | Component for specfied case. Left bottom button with nice looking menu tooltip with animation after click. 6 | 7 | ![alt text](https://github.com/alimek/react-native-tooltip-menu/raw/master/Doc/ios.gif "React Native ToolTip Menu") 8 | ![alt text](https://github.com/alimek/react-native-tooltip-menu/raw/master/Doc/android.gif "React Native ToolTip Menu") 9 | 10 | 11 | # How to install 12 | 13 | Via NPM 14 | 15 | ```bash 16 | npm install react-native-tooltip-menu 17 | ``` 18 | 19 | Via yarn 20 | ```bash 21 | yarn add react-native-tooltip-menu 22 | ``` 23 | 24 | then 25 | 26 | ```js 27 | import { TooltipMenu } from 'react-native-tooltip-menu'; 28 | ``` 29 | 30 | # Configuration 31 | 32 | ## ReactNativeTooltipMenu: 33 | 34 | | Property | Type | Default | Description | 35 | |---------------------|---------------------------|------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | children | ReactNode | required | | 37 | | items | `Array` | required | Items to be rendered in menu. Each of item requires `label` as `string` or `function` if you want to render your own component and `onPress` as `function` to be called when you click item. | 38 | | style | `ViewStyle` | Optional | Style `Object` if you want to overwrite wrapper for your `children`| 39 | | overlayStyle | Object | Optional | Style `Object` if you want to overwrite overlay style's.| 40 | | widthType | `auto`, `half` or `full` | `auto` | Menu items width. `auto` = automatically set width to your longest test, `half` = always 50% your screen width, `full` = 100% screen width.| 41 | | onRequestClose | `function` | Optional, default `() => {}` | Modal onRequestClose required function on Android| 42 | | labelContainerStyle | `Object` | Optional | Style `Object` if you want to change default `TooltipMenuItem` View's style.| 43 | | labelStyle | `Object` | Optional | Style `Object` if you want to change default `TooltipMenuItem` Text's style.| 44 | | modalButtonStyle | `Object` | optional | Style. for `TouchabelOpacity` when modal is opened.| 45 | | trianglePosition | `left`, `center`, `right` | `center` | Position of the triangle.| 46 | # Example 47 | 48 | ```js 49 | import { TooltipMenu } from 'react-native-tooltip-menu'; 50 | 51 | const Example = () => ( 52 | 53 | 54 | This is example of react-native-tooltip-menu 55 | Clicked item1: {counter1} 56 | Clicked item2: {counter2} 57 | 58 | incrementCounter1() 63 | }, 64 | { 65 | label: 'Label #2', 66 | onPress: () => incrementCounter2(), 67 | }, 68 | ]} 69 | > 70 | 77 | Click me to show tooltip! 78 | 79 | 80 | 81 | ); 82 | ``` 83 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /doc/android.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimek/react-native-tooltip-menu/f627ed92d9e1ff562564f3ec81d4420a52b4d597/doc/android.gif -------------------------------------------------------------------------------- /doc/ios.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alimek/react-native-tooltip-menu/f627ed92d9e1ff562564f3ec81d4420a52b4d597/doc/ios.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-tooltip-menu", 3 | "version": "3.0.7", 4 | "description": "ReactNative component showing tooltip with menu items.", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "!lib/typescript/example", 17 | "!android/build", 18 | "!ios/build", 19 | "!**/__tests__", 20 | "!**/__fixtures__", 21 | "!**/__mocks__" 22 | ], 23 | "scripts": { 24 | "test": "jest", 25 | "typescript": "tsc --noEmit", 26 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 27 | "prepare": "bob build", 28 | "release": "release-it", 29 | "example": "yarn --cwd example", 30 | "pods": "cd example && pod-install --quiet", 31 | "bootstrap": "yarn example && yarn && yarn pods" 32 | }, 33 | "keywords": [ 34 | "react-native", 35 | "ios", 36 | "android" 37 | ], 38 | "repository": { 39 | "type": "git", 40 | "url": "git+https://github.com/alimek/react-native-tooltip-menu.git" 41 | }, 42 | "author": "Grzegorz Mandziak", 43 | "license": "MIT", 44 | "bugs": { 45 | "url": "https://github.com/alimek/react-native-tooltip-menu/issues" 46 | }, 47 | "homepage": "https://github.com/alimek/react-native-tooltip-menu#readme", 48 | "publishConfig": { 49 | "registry": "https://registry.npmjs.org/" 50 | }, 51 | "devDependencies": { 52 | "@commitlint/config-conventional": "^11.0.0", 53 | "@react-native-community/eslint-config": "^2.0.0", 54 | "@release-it/conventional-changelog": "^2.0.0", 55 | "@types/jest": "^26.0.0", 56 | "@types/react": "^16.9.19", 57 | "@types/react-native": "0.62.13", 58 | "commitlint": "^11.0.0", 59 | "eslint": "^7.2.0", 60 | "eslint-config-prettier": "^7.0.0", 61 | "eslint-plugin-prettier": "^3.1.3", 62 | "husky": "^6.0.0", 63 | "jest": "^26.0.1", 64 | "pod-install": "^0.1.0", 65 | "prettier": "^2.0.5", 66 | "react": "16.13.1", 67 | "react-native": "0.63.4", 68 | "react-native-builder-bob": "^0.18.0", 69 | "release-it": "^14.2.2", 70 | "typescript": "^4.1.3" 71 | }, 72 | "peerDependencies": { 73 | "react": "*", 74 | "react-native": "*" 75 | }, 76 | "jest": { 77 | "preset": "react-native", 78 | "modulePathIgnorePatterns": [ 79 | "/example/node_modules", 80 | "/lib/" 81 | ] 82 | }, 83 | "commitlint": { 84 | "extends": [ 85 | "@commitlint/config-conventional" 86 | ] 87 | }, 88 | "release-it": { 89 | "git": { 90 | "commitMessage": "chore: release ${version}", 91 | "tagName": "v${version}" 92 | }, 93 | "npm": { 94 | "publish": true 95 | }, 96 | "github": { 97 | "release": true 98 | }, 99 | "plugins": { 100 | "@release-it/conventional-changelog": { 101 | "preset": "angular" 102 | } 103 | } 104 | }, 105 | "eslintConfig": { 106 | "root": true, 107 | "extends": [ 108 | "@react-native-community", 109 | "prettier" 110 | ], 111 | "rules": { 112 | "prettier/prettier": [ 113 | "error", 114 | { 115 | "quoteProps": "consistent", 116 | "singleQuote": true, 117 | "tabWidth": 2, 118 | "trailingComma": "es5", 119 | "useTabs": false 120 | } 121 | ] 122 | } 123 | }, 124 | "eslintIgnore": [ 125 | "node_modules/", 126 | "lib/" 127 | ], 128 | "prettier": { 129 | "quoteProps": "consistent", 130 | "singleQuote": true, 131 | "tabWidth": 2, 132 | "trailingComma": "es5", 133 | "useTabs": false 134 | }, 135 | "react-native-builder-bob": { 136 | "source": "src", 137 | "output": "lib", 138 | "targets": [ 139 | "commonjs", 140 | "module", 141 | [ 142 | "typescript", 143 | { 144 | "project": "tsconfig.build.json" 145 | } 146 | ] 147 | ] 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true; 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /src/TooltipMenu.tsx: -------------------------------------------------------------------------------- 1 | import React, { createRef, ReactNode, useMemo, useState } from 'react'; 2 | import { 3 | View, 4 | Modal, 5 | Animated, 6 | TouchableOpacity, 7 | StyleSheet, 8 | ViewStyle, 9 | LayoutRectangle, 10 | useWindowDimensions, 11 | LayoutChangeEvent, 12 | TouchableOpacityProps, 13 | StatusBar, 14 | } from 'react-native'; 15 | import { TooltipMenuItem } from './TooltipMenuItem'; 16 | 17 | type WidthType = 'auto' | 'half' | 'full'; 18 | type TrianglePosition = 'left' | 'center' | 'right'; 19 | type Props = { 20 | children: ReactNode; 21 | items: { 22 | label: string | (() => ReactNode); 23 | onPress: () => void; 24 | testID?: string; 25 | }[]; 26 | style?: TouchableOpacityProps['style']; 27 | overlayStyle?: ViewStyle; 28 | labelContainerStyle?: ViewStyle; 29 | modalButtonStyle?: ViewStyle; 30 | labelStyle?: ViewStyle; 31 | widthType?: WidthType; 32 | onRequestClose?: () => void; 33 | trianglePosition?: TrianglePosition; 34 | }; 35 | 36 | export const TooltipMenu = ({ 37 | children, 38 | items, 39 | style, 40 | overlayStyle, 41 | widthType, 42 | labelContainerStyle, 43 | labelStyle, 44 | modalButtonStyle, 45 | onRequestClose, 46 | trianglePosition, 47 | }: Props) => { 48 | const { width: windowWidth, height: windowHeight } = useWindowDimensions(); 49 | const buttonRef = createRef(); 50 | const [isModalOpen, setModalOpen] = useState(false); 51 | const [componentPosition, setComponentPosition] = useState(); 52 | const opacity = useMemo(() => new Animated.Value(0), []); 53 | 54 | const toggleModal = () => { 55 | setModalOpen(!isModalOpen); 56 | }; 57 | 58 | const openModal = () => { 59 | Animated.timing(opacity, { 60 | toValue: 1, 61 | duration: 300, 62 | useNativeDriver: true, 63 | }).start(toggleModal); 64 | }; 65 | 66 | const calculateItemWith = () => { 67 | switch (widthType) { 68 | case 'half': 69 | return windowWidth / 2; 70 | case 'full': 71 | return windowWidth; 72 | default: 73 | return componentPosition?.width; 74 | } 75 | }; 76 | 77 | const hideModal = () => { 78 | Animated.timing(opacity, { 79 | toValue: 0, 80 | duration: 300, 81 | useNativeDriver: true, 82 | }).start(toggleModal); 83 | }; 84 | 85 | const handleClick = (onClickItem: Props['items'][0]['onPress']) => { 86 | const method = isModalOpen ? hideModal : openModal; 87 | method(); 88 | 89 | onClickItem(); 90 | }; 91 | 92 | const calculatePosition = (event: LayoutChangeEvent) => { 93 | const width = event.nativeEvent.layout.width; 94 | const height = event.nativeEvent.layout.height; 95 | if (!componentPosition && buttonRef.current) { 96 | buttonRef.current.measureInWindow((x, y) => { 97 | setComponentPosition({ 98 | x, 99 | y, 100 | width, 101 | height, 102 | }); 103 | }); 104 | } 105 | }; 106 | 107 | return ( 108 | 109 | calculatePosition(event)} 112 | > 113 | {children} 114 | 115 | 116 | 117 | 122 | 131 | 132 | {children} 133 | 134 | 135 | 150 | {items.map((item, index) => { 151 | const classes = []; 152 | 153 | if (labelContainerStyle) { 154 | classes.push(labelContainerStyle); 155 | } 156 | 157 | if (index !== items.length - 1) { 158 | classes.push(styles.tooltipMargin); 159 | } 160 | 161 | return ( 162 | handleClick(item.onPress)} 166 | containerStyle={classes} 167 | labelStyle={labelStyle} 168 | testID={item.testID} 169 | /> 170 | ); 171 | })} 172 | 173 | 194 | 195 | 196 | 197 | ); 198 | }; 199 | 200 | TooltipMenu.defaultProps = { 201 | widthType: 'auto', 202 | onRequestClose: () => {}, 203 | trianglePosition: 'center', 204 | }; 205 | 206 | const styles = StyleSheet.create({ 207 | overlay: { 208 | ...StyleSheet.absoluteFillObject, 209 | backgroundColor: 'rgba(0,0,0,0.5)', 210 | }, 211 | tooltipMargin: { 212 | borderBottomWidth: 1, 213 | borderBottomColor: '#E1E1E1', 214 | }, 215 | component: { 216 | position: 'absolute', 217 | }, 218 | tooltipContainer: { 219 | backgroundColor: 'white', 220 | borderRadius: 10, 221 | position: 'absolute', 222 | }, 223 | triangle: { 224 | position: 'absolute', 225 | width: 10, 226 | height: 10, 227 | backgroundColor: 'transparent', 228 | borderStyle: 'solid', 229 | borderTopWidth: 10, 230 | borderRightWidth: 10, 231 | borderBottomWidth: 0, 232 | borderLeftWidth: 10, 233 | borderTopColor: 'white', 234 | borderRightColor: 'transparent', 235 | borderBottomColor: 'transparent', 236 | borderLeftColor: 'transparent', 237 | }, 238 | }); 239 | -------------------------------------------------------------------------------- /src/TooltipMenuItem.tsx: -------------------------------------------------------------------------------- 1 | import React, { ReactNode } from 'react'; 2 | import { Text, StyleSheet, TouchableOpacity, ViewStyle } from 'react-native'; 3 | 4 | type Props = { 5 | onPress: () => void; 6 | label: string | (() => ReactNode); 7 | containerStyle?: ViewStyle | ViewStyle[]; 8 | touchableStyle?: ViewStyle; 9 | labelStyle?: ViewStyle; 10 | testID?: string; 11 | }; 12 | 13 | export const TooltipMenuItem = ({ 14 | onPress, 15 | containerStyle, 16 | label, 17 | labelStyle, 18 | testID, 19 | }: Props) => ( 20 | 25 | {typeof label === 'string' ? ( 26 | {label} 27 | ) : ( 28 | label() 29 | )} 30 | 31 | ); 32 | 33 | TooltipMenuItem.defaultProps = { 34 | labelStyle: null, 35 | containerStyle: null, 36 | touchableStyle: null, 37 | testID: undefined, 38 | }; 39 | 40 | const styles = StyleSheet.create({ 41 | container: { 42 | padding: 10, 43 | }, 44 | }); 45 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './TooltipMenu'; 2 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "react-native-test2": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "strict": true, 25 | "target": "esnext" 26 | } 27 | } 28 | --------------------------------------------------------------------------------