├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github └── FUNDING.yml ├── .gitignore ├── .huskyrc.json ├── .prettierignore ├── .prettierrc.json ├── .release-it.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── __tests__ └── index.test.tsx ├── babel.config.js ├── commitlint.config.js ├── example ├── .expo-shared │ ├── README.md │ └── assets.json ├── app.json ├── babel.config.js ├── index.js ├── metro.config.js ├── package.json ├── src │ ├── App.tsx │ ├── components │ │ ├── Button.tsx │ │ ├── CounterModal.tsx │ │ ├── SimpleModal.tsx │ │ └── SimplePopover.tsx │ └── screens │ │ ├── BasicScreen.tsx │ │ ├── ModalScreen.tsx │ │ ├── NativeScreen.tsx │ │ ├── PopoverScreen.tsx │ │ └── index.ts ├── tsconfig.json ├── webpack.config.js └── yarn.lock ├── jest.config.js ├── mogorhom-dark.png ├── mogorhom-light.png ├── package.json ├── preview.jpg ├── release-template.hbs ├── src ├── components │ ├── portal │ │ ├── Portal.tsx │ │ └── types.d.ts │ ├── portalHost │ │ ├── PortalHost.tsx │ │ └── types.d.ts │ └── portalProvider │ │ ├── PortalProvider.tsx │ │ └── types.d.ts ├── contexts │ └── portal.ts ├── hooks │ ├── usePortal.ts │ └── usePortalState.ts ├── index.ts ├── state │ ├── constants.ts │ ├── reducer.ts │ └── types.d.ts ├── types.d.ts └── utilities │ └── logger.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 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | 3 | # generated by bob 4 | lib/ 5 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: ['@react-native-community', 'prettier'], 4 | rules: { 5 | 'prettier/prettier': [ 6 | 'error', 7 | { 8 | printWidth: 80, 9 | arrowParens: 'avoid', 10 | singleQuote: true, 11 | tabWidth: 2, 12 | trailingComma: 'es5', 13 | useTabs: false, 14 | }, 15 | ], 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: gorhom 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 | .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 | -------------------------------------------------------------------------------- /.huskyrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", 4 | "pre-commit": "yarn lint && yarn typescript" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .github 2 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "arrowParens": "avoid", 4 | "singleQuote": true, 5 | "tabWidth": 2, 6 | "trailingComma": "es5", 7 | "useTabs": false 8 | } 9 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "git": { 3 | "push": true, 4 | "tagName": "v${version}", 5 | "commitMessage": "chore: release v${version}", 6 | "changelog": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" 7 | }, 8 | "github": { 9 | "release": true, 10 | "releaseNotes": "auto-changelog --stdout --commit-limit false --ignore-commit-pattern \"^chore: release v\" --unreleased --template ./release-template.hbs --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" 11 | }, 12 | "npm": { 13 | "publish": false 14 | }, 15 | "plugins": { 16 | "@release-it/conventional-changelog": { 17 | "preset": "angular" 18 | } 19 | }, 20 | "hooks": { 21 | "after:bump": "auto-changelog -p --ignore-commit-pattern \"^chore: release v\" --template \"keepachangelog\" --tag-pattern \"^v\\d+\\.\\d+\\.\\d+$\"" 22 | } 23 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 | 8 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 9 | 10 | ## [v1.0.14](https://github.com/gorhom/react-native-portal/compare/v1.0.13...v1.0.14) 11 | 12 | ### Commits 13 | 14 | - docs: added usage example with gesture handler [`098ccdf`](https://github.com/gorhom/react-native-portal/commit/098ccdf90089db54fd9c0629970216f11fdb48d6) 15 | - fix: avoid non-defined global error on web (#30)(by @AlanSl) [`d74fd20`](https://github.com/gorhom/react-native-portal/commit/d74fd200ef82d3b86718dd6f7644a0a52816a087) 16 | - chore: fix linting in logger.ts [`74a1290`](https://github.com/gorhom/react-native-portal/commit/74a129073e52988ffb87d527a713f9aa63004426) 17 | 18 | ## [v1.0.13](https://github.com/gorhom/react-native-portal/compare/v1.0.12...v1.0.13) - 2022-04-10 19 | 20 | ### Commits 21 | 22 | - chore: upgrade nanoid (#22)(by @jeremyadavis) [`1570974`](https://github.com/gorhom/react-native-portal/commit/157097404dc7750d8fb35d402e6ed8c2f772aee6) 23 | 24 | ## [v1.0.12](https://github.com/gorhom/react-native-portal/compare/v1.0.11...v1.0.12) - 2022-01-06 25 | 26 | ### Commits 27 | 28 | - chore: updated examples [`d9c3ea6`](https://github.com/gorhom/react-native-portal/commit/d9c3ea66fa226e9bcc7277526b6b62787ef1cffb) 29 | - docs: updated readme file [`9b0fffd`](https://github.com/gorhom/react-native-portal/commit/9b0fffd5a95d5e1d63d1dc5b64e80f2d3e366b2a) 30 | - refactor: removed index files [`83c1b74`](https://github.com/gorhom/react-native-portal/commit/83c1b7471a9de9a40edb3d6a2a01a45037905aec) 31 | 32 | ## [v1.0.11](https://github.com/gorhom/react-native-portal/compare/v1.0.10...v1.0.11) - 2021-10-18 33 | 34 | ### Commits 35 | 36 | - fix: updated Portal handling types [`8eba3ea`](https://github.com/gorhom/react-native-portal/commit/8eba3ea1559687d7e76d000075e78f895802e000) 37 | 38 | ## [v1.0.10](https://github.com/gorhom/react-native-portal/compare/v1.0.9...v1.0.10) - 2021-10-17 39 | 40 | ### Commits 41 | 42 | - refactor: added handleOnUpdate to Portal [`b000935`](https://github.com/gorhom/react-native-portal/commit/b000935d0950ff299e888d1f1d2117804e4d39a2) 43 | - refactor: removed duplicated method "update" [`c312e4c`](https://github.com/gorhom/react-native-portal/commit/c312e4cc5c0efc7f6fb0a70a2bbfbca54405ed70) 44 | 45 | ## [v1.0.9](https://github.com/gorhom/react-native-portal/compare/v1.0.8...v1.0.9) - 2021-09-21 46 | 47 | ### Commits 48 | 49 | - refactor: removing immer to fix max call stack error with production … (#20)(by @egadstar) [`809c3bc`](https://github.com/gorhom/react-native-portal/commit/809c3bc0e5d9e8a18a7ef15874e68b7c4c68b09a) 50 | 51 | ## [v1.0.8](https://github.com/gorhom/react-native-portal/compare/v1.0.7...v1.0.8) - 2021-08-23 52 | 53 | ### Commits 54 | 55 | - fix: allow PortalHost to mount/unmount safely #18 [`05042e5`](https://github.com/gorhom/react-native-portal/commit/05042e5636bc5421cdc60d755cbec47bbc0101d8) 56 | 57 | ## [v1.0.7](https://github.com/gorhom/react-native-portal/compare/v1.0.6...v1.0.7) - 2021-06-10 58 | 59 | ### Commits 60 | 61 | - fix: error messages on development [`dae78b5`](https://github.com/gorhom/react-native-portal/commit/dae78b51243fbb3bbaa3dae2f23075b5eda28c23) 62 | 63 | ## [v1.0.6](https://github.com/gorhom/react-native-portal/compare/v1.0.5...v1.0.6) - 2021-06-10 64 | 65 | ### Commits 66 | 67 | - refactor: removed returned draft from immer produce [`4547623`](https://github.com/gorhom/react-native-portal/commit/45476237e3f16b5a4f0ddcf10475d7691bc02eec) 68 | 69 | ## [v1.0.5](https://github.com/gorhom/react-native-portal/compare/v1.0.4...v1.0.5) - 2021-06-10 70 | 71 | ### Commits 72 | 73 | - chore: updated dependencies [`3a8db0c`](https://github.com/gorhom/react-native-portal/commit/3a8db0c6d551da19dbb832754c83676cc117f4e5) 74 | - chore: updated expo [`96eec0f`](https://github.com/gorhom/react-native-portal/commit/96eec0fc2235d5841c6653e1d6460204617757c3) 75 | 76 | ## [v1.0.4](https://github.com/gorhom/react-native-portal/compare/v1.0.3...v1.0.4) - 2021-03-04 77 | 78 | ### Merged 79 | 80 | - fix: disable immer auto freeze [`#13`](https://github.com/gorhom/react-native-portal/pull/13) 81 | 82 | ## [v1.0.3](https://github.com/gorhom/react-native-portal/compare/v1.0.1...v1.0.3) - 2021-02-27 83 | 84 | ### Commits 85 | 86 | - refactor: updated added portal logic [`708f8f3`](https://github.com/gorhom/react-native-portal/commit/708f8f322b1bd8139a35e26144f59355f9078057) 87 | - bump version [`cd3fcb7`](https://github.com/gorhom/react-native-portal/commit/cd3fcb725e75744e5a4d69281d46de7a4548cfdf) 88 | 89 | ## [v1.0.1](https://github.com/gorhom/react-native-portal/compare/v1.0.0...v1.0.1) - 2021-02-24 90 | 91 | ### Commits 92 | 93 | - fix: enable es5 for immer [`74bd72a`](https://github.com/gorhom/react-native-portal/commit/74bd72a594acbd034f779afc19e85ef2ed72dba6) 94 | 95 | ## [v1.0.0](https://github.com/gorhom/react-native-portal/compare/v0.2.0...v1.0.0) - 2021-02-21 96 | 97 | ### Merged 98 | 99 | - feat: added multi hosts [`#8`](https://github.com/gorhom/react-native-portal/pull/8) 100 | 101 | ## [v0.2.0](https://github.com/gorhom/react-native-portal/compare/v0.1.4...v0.2.0) - 2021-01-28 102 | 103 | ### Merged 104 | 105 | - feat: added mounting handlers [`#7`](https://github.com/gorhom/react-native-portal/pull/7) 106 | - chore: added popover example [`#6`](https://github.com/gorhom/react-native-portal/pull/6) 107 | - chore: updated examples [`#5`](https://github.com/gorhom/react-native-portal/pull/5) 108 | - chore: updated dependencies [`#4`](https://github.com/gorhom/react-native-portal/pull/4) 109 | 110 | ### Commits 111 | 112 | - docs: updated readme file [`708bca3`](https://github.com/gorhom/react-native-portal/commit/708bca3dc26067215650e9b90cc0e5b55c984978) 113 | 114 | ## [v0.1.4](https://github.com/gorhom/react-native-portal/compare/v0.1.3...v0.1.4) - 2020-12-15 115 | 116 | ### Commits 117 | 118 | - chore: added update node logic [`8ee8292`](https://github.com/gorhom/react-native-portal/commit/8ee82927d028ff248cf4905ee3cc49b0bcb4e768) 119 | 120 | ## [v0.1.3](https://github.com/gorhom/react-native-portal/compare/v0.1.2...v0.1.3) - 2020-12-14 121 | 122 | ### Commits 123 | 124 | - fix: prevent unwanted re-mounting whenever children updates [`e4f1eb9`](https://github.com/gorhom/react-native-portal/commit/e4f1eb951e9d6c2c759aaf78f13cdc90602a781f) 125 | 126 | ## [v0.1.2](https://github.com/gorhom/react-native-portal/compare/v0.1.1...v0.1.2) - 2020-12-12 127 | 128 | ### Commits 129 | 130 | - chore: renamed Portal prop key to name, to avoid react warnings [`bf6cf1e`](https://github.com/gorhom/react-native-portal/commit/bf6cf1e2209c7eeecef883c4ea85a872a88da0dc) 131 | 132 | ## v0.1.1 - 2020-12-08 133 | 134 | ### Commits 135 | 136 | - chore: init project [`d7980b6`](https://github.com/gorhom/react-native-portal/commit/d7980b6b8b709e6d48984109d506a0fbfe0d4b62) 137 | - chore: added initial implementaion [`044c266`](https://github.com/gorhom/react-native-portal/commit/044c26621b46e033faf6306f1e89734f618216fa) 138 | - docs: updated readme file [`488a977`](https://github.com/gorhom/react-native-portal/commit/488a9778286ecd49e340a063641df61b29561b54) 139 | -------------------------------------------------------------------------------- /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 example start 19 | ``` 20 | 21 | To run the example app on Android: 22 | 23 | ```sh 24 | yarn example android 25 | ``` 26 | 27 | To run the example app on iOS: 28 | 29 | ```sh 30 | yarn example 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/PortalExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-portal`. 53 | 54 | To edit the Kotlin files, open `example/android` in Android studio and find the source files at `reactnativeportal` under `Android`. 55 | 56 | ### Commit message convention 57 | 58 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 59 | 60 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 61 | - `feat`: new features, e.g. add new method to the module. 62 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 63 | - `docs`: changes into documentation, e.g. add usage example for the module.. 64 | - `test`: adding or updating tests, e.g. add integration tests using detox. 65 | - `chore`: tooling changes, e.g. change CI config. 66 | 67 | Our pre-commit hooks verify that your commit message matches this format when committing. 68 | 69 | ### Linting and tests 70 | 71 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 72 | 73 | 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. 74 | 75 | Our pre-commit hooks verify that the linter and tests pass when committing. 76 | 77 | ### Scripts 78 | 79 | The `package.json` file contains various scripts for common tasks: 80 | 81 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 82 | - `yarn typescript`: type-check files with TypeScript. 83 | - `yarn lint`: lint files with ESLint. 84 | - `yarn test`: run unit tests with Jest. 85 | - `yarn example start`: start the Metro server for the example app. 86 | - `yarn example android`: run the example app on Android. 87 | - `yarn example ios`: run the example app on iOS. 88 | 89 | ### Sending a pull request 90 | 91 | > **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). 92 | 93 | When you're sending a pull request: 94 | 95 | - Prefer small pull requests focused on one change. 96 | - Verify that linters and tests are passing. 97 | - Review the documentation to make sure it looks good. 98 | - Follow the pull request template when opening a pull request. 99 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 100 | 101 | ## Code of Conduct 102 | 103 | ### Our Pledge 104 | 105 | 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. 106 | 107 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 108 | 109 | ### Our Standards 110 | 111 | Examples of behavior that contributes to a positive environment for our community include: 112 | 113 | - Demonstrating empathy and kindness toward other people 114 | - Being respectful of differing opinions, viewpoints, and experiences 115 | - Giving and gracefully accepting constructive feedback 116 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 117 | - Focusing on what is best not just for us as individuals, but for the overall community 118 | 119 | Examples of unacceptable behavior include: 120 | 121 | - The use of sexualized language or imagery, and sexual attention or 122 | advances of any kind 123 | - Trolling, insulting or derogatory comments, and personal or political attacks 124 | - Public or private harassment 125 | - Publishing others' private information, such as a physical or email 126 | address, without their explicit permission 127 | - Other conduct which could reasonably be considered inappropriate in a 128 | professional setting 129 | 130 | ### Enforcement Responsibilities 131 | 132 | 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. 133 | 134 | 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. 135 | 136 | ### Scope 137 | 138 | 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. 139 | 140 | ### Enforcement 141 | 142 | 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. 143 | 144 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 145 | 146 | ### Enforcement Guidelines 147 | 148 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 149 | 150 | #### 1. Correction 151 | 152 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 153 | 154 | **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. 155 | 156 | #### 2. Warning 157 | 158 | **Community Impact**: A violation through a single incident or series of actions. 159 | 160 | **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. 161 | 162 | #### 3. Temporary Ban 163 | 164 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 165 | 166 | **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. 167 | 168 | #### 4. Permanent Ban 169 | 170 | **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. 171 | 172 | **Consequence**: A permanent ban from any sort of public interaction within the community. 173 | 174 | ### Attribution 175 | 176 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 177 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 178 | 179 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 180 | 181 | [homepage]: https://www.contributor-covenant.org 182 | 183 | For answers to common questions about this code of conduct, see the FAQ at 184 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 185 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mo Gorhom 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 Portal 2 | 3 | [![React Native Portal](https://img.shields.io/npm/v/@gorhom/portal?style=flat-square)](https://www.npmjs.com/package/@gorhom/portal) [![npm](https://img.shields.io/npm/l/@gorhom/portal?style=flat-square)](https://www.npmjs.com/package/@gorhom/portal) [![npm](https://img.shields.io/badge/types-included-blue?style=flat-square)](https://www.npmjs.com/package/@gorhom/portal) [![runs with expo](https://img.shields.io/badge/Runs%20with%20Expo-4630EB.svg?style=flat-square&logo=EXPO&labelColor=f3f3f3&logoColor=000)](https://snack.expo.io/@gorhom/portal-example) 4 | 5 | A simplified portal implementation for ⭕️ React Native ⭕️. 6 | 7 | ![React Native Portal](./preview.jpg) 8 | 9 | --- 10 | 11 | ## Features 12 | 13 | - Multi portals handling. 14 | - Multi portal hosts handling. 15 | - Allow override functionality. 16 | - Compatible with `React Native Web`. 17 | - Compatible with `Expo`, [check out the project Expo Snack](https://snack.expo.io/@gorhom/portal-example). 18 | - Written in `TypeScript`. 19 | 20 | ## Installation 21 | 22 | ```sh 23 | yarn add @gorhom/portal 24 | ``` 25 | 26 | ## Usage 27 | 28 | ### Simple Portal 29 | 30 | This is the very simple usage of this library, where you will teleport your content to the `PortalProvider` layer of the app. 31 | 32 | First, you will need to add `PortalProvider` to your root component - this usually be the `App.tsx`. 33 | 34 | ```tsx 35 | export const App = () => ( 36 | 37 | {... your app goes here} 38 | 39 | ); 40 | ``` 41 | 42 | Last, you wrap the content that you want to teleport with `Portal`. 43 | 44 | ```tsx 45 | const BasicScreen = () => { 46 | return ( 47 | { ... } 48 | 49 | 50 | Text to be teleported to the root host 51 | 52 | 53 | { ... } 54 | ); 55 | }; 56 | ``` 57 | 58 | ### Custom Portal Host 59 | 60 | This is when you need to teleport your content to a custom portal host `PortalHost` at any layer in the app. 61 | 62 | First, you will need to add `PortalProvider` to your root component - this usually be the `App.tsx`. 63 | 64 | ```tsx 65 | export const App = () => ( 66 | 67 | {... your app goes here ...} 68 | 69 | ); 70 | ``` 71 | 72 | Second, you will need to add `PortalHost` at any layer in your app, with a custom name. 73 | 74 | ```tsx 75 | const CustomView = () => { 76 | return ( 77 | { ... } 78 | 79 | { ... } 80 | ); 81 | }; 82 | ``` 83 | 84 | Last, you wrap the content that you want to teleport with `Portal` and the custom portal host name. 85 | 86 | ```tsx 87 | const BasicScreen = () => { 88 | return ( 89 | { ... } 90 | 91 | 92 | Text to be teleported to the CustomView component 93 | 94 | 95 | { ... } 96 | ); 97 | }; 98 | ``` 99 | 100 | ### React Native Screens integration 101 | 102 | In order to get your teleported content on top of all native views, you will need to wrap your content with `FullWindowOverlay` from `react-native-screens`. 103 | 104 | ```tsx 105 | import { FullWindowOverlay } from 'react-native-screens'; 106 | 107 | const BasicScreen = () => { 108 | return ( 109 | { ... } 110 | 111 | 112 | 113 | Text to be teleported to the CustomView component 114 | 115 | 116 | 117 | { ... } 118 | ); 119 | }; 120 | ``` 121 | ### React Native Gesture Handler 122 | 123 | To avoid issues when using the React Native Portal with React Native Gesture Handler, you must place the `PortalProvider` under the `GestureHandlerRootView`, otherwise it might freeze your app. 124 | 125 | ```tsx 126 | export const App = () => ( 127 | 128 | 129 | {... your app goes here} 130 | 131 | 132 | ); 133 | ``` 134 | 135 | > Read more about the [app freezing issue](https://github.com/gorhom/react-native-portal/issues/24). 136 | 137 | ## Props 138 | 139 | ### Portal Props 140 | 141 | #### `name` 142 | 143 | Portal's key or name to be used as an identifer. 144 | 145 | > `required:` NO | `type:` string | `default:` auto generated unique key 146 | 147 | #### `hostName` 148 | 149 | Host's key or name to teleport the portal content to. 150 | 151 | > `required:` NO | `type:` string | `default:` 'root' 152 | 153 | #### `handleOnMount` 154 | 155 | Override internal mounting functionality, this is useful if you want to trigger any action before mounting the portal content. 156 | 157 | ```ts 158 | type handleOnMount = (mount?: () => void) => void; 159 | ``` 160 | 161 | > `required:` NO | `type:` function | `default:` undefined 162 | 163 | #### `handleOnUnmount` 164 | 165 | Override internal un-mounting functionality, this is useful if you want to trigger any action before un-mounting the portal content. 166 | 167 | ```ts 168 | type handleOnUnmount = (unmount?: () => void) => void; 169 | ``` 170 | 171 | > `required:` NO | `type:` function | `default:` undefined 172 | 173 | #### `children` 174 | 175 | Portal's content. 176 | 177 | > `required:` NO | `type:` ReactNode | ReactNode[] | `default:` undefined 178 | 179 | ### PortalHost Props 180 | 181 | #### `name` 182 | 183 | Host's key or name to be used as an identifier. 184 | 185 | > `required:` YES | `type:` string 186 | 187 | ## Hooks 188 | 189 | ### `usePortal` 190 | 191 | To access internal functionalities of all portals. 192 | 193 | ```ts 194 | /** 195 | * @param hostName host name or key. 196 | */ 197 | type usePortal = (hostName: string = 'root') => { 198 | /** 199 | * Register a new host. 200 | */ 201 | registerHost: () => void; 202 | /** 203 | * Deregister a host. 204 | */ 205 | deregisterHost: () => void; 206 | /** 207 | * Add portal to the host container. 208 | * @param name portal name or key 209 | * @param node portal content 210 | */ 211 | addPortal: (name: string, node: ReactNode) => void; 212 | /** 213 | * Update portal content. 214 | * @param name portal name or key 215 | * @param node portal content 216 | */ 217 | updatePortal: (name: string, node: ReactNode) => void; 218 | /** 219 | * Remove portal from host container. 220 | * @param name portal name or key 221 | */ 222 | removePortal: (name: string) => void; 223 | }; 224 | ``` 225 | 226 |

Built With ❤️

227 | 228 | - [@react-native-community/bob](https://github.com/react-native-community/bob) 229 | 230 | ## Author 231 | 232 | - [Mo Gorhom](https://gorhom.dev/) 233 | 234 | ## Sponsor & Support 235 | 236 | To keep this library maintained and up-to-date please consider [sponsoring it on GitHub](https://github.com/sponsors/gorhom). Or if you are looking for a private support or help in customizing the experience, then reach out to me on Twitter [@gorhom](https://twitter.com/gorhom). 237 | 238 | ## License 239 | 240 | [MIT](./LICENSE) 241 | 242 | --- 243 | 244 |

245 | 246 | Mo Gorhom 247 | 248 | 249 | Mo Gorhom 250 | 251 |

252 | -------------------------------------------------------------------------------- /__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['@commitlint/config-conventional'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/.expo-shared/README.md: -------------------------------------------------------------------------------- 1 | > Why do I have a folder named ".expo-shared" in my project? 2 | 3 | The ".expo-shared" folder is created when running commands that produce state that is intended to be shared with all developers on the project. For example, "npx expo-optimize". 4 | 5 | > What does the "assets.json" file contain? 6 | 7 | The "assets.json" file describes the assets that have been optimized through "expo-optimize" and do not need to be processed again. 8 | 9 | > Should I commit the ".expo-shared" folder? 10 | 11 | Yes, you should share the ".expo-shared" folder with your collaborators. 12 | -------------------------------------------------------------------------------- /example/.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "React Native Portal", 3 | "displayName": "React Native Portal Example", 4 | "expo": { 5 | "name": "@gorhom/portal-example", 6 | "slug": "portal-example", 7 | "owner": "gorhom", 8 | "description": "A simplified portal implementation for ⭕️ React Native ⭕️", 9 | "privacy": "public", 10 | "version": "1.0.0", 11 | "githubUrl": "https://github.com/gorhom/react-native-portal", 12 | "platforms": [ 13 | "ios", 14 | "android", 15 | "web" 16 | ], 17 | "ios": { 18 | "supportsTablet": true 19 | }, 20 | "userInterfaceStyle": "automatic", 21 | "assetBundlePatterns": [ 22 | "**/*" 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = function (api) { 5 | api.cache(true); 6 | 7 | return { 8 | presets: ['babel-preset-expo'], 9 | plugins: [ 10 | [ 11 | 'module-resolver', 12 | { 13 | alias: { 14 | // For development, we want to alias the library to the source 15 | [pak.name]: path.join(__dirname, '..', pak.source), 16 | }, 17 | }, 18 | ], 19 | ], 20 | }; 21 | }; 22 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { registerRootComponent } from 'expo'; 2 | 3 | import App from './src/App'; 4 | 5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App); 6 | // It also ensures that whether you load the app in the Expo client or in a native build, 7 | // the environment is set up appropriately 8 | registerRootComponent(App); 9 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 22 | ) 23 | ), 24 | 25 | extraNodeModules: modules.reduce((acc, name) => { 26 | acc[name] = path.join(__dirname, 'node_modules', name); 27 | return acc; 28 | }, {}), 29 | }, 30 | 31 | transformer: { 32 | getTransformOptions: async () => ({ 33 | transform: { 34 | experimentalImportSupport: false, 35 | inlineRequires: true, 36 | }, 37 | }), 38 | }, 39 | }; 40 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@gorhom/portal-example", 3 | "description": "Example app for @gorhom/portal", 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 | "@gorhom/showcase-template": "^2.1.0", 16 | "@react-native-community/masked-view": "0.1.11", 17 | "@react-native-masked-view/masked-view": "0.2.6", 18 | "@react-navigation/bottom-tabs": "^6.0.9", 19 | "@react-navigation/native": "^6.0.6", 20 | "@react-navigation/native-stack": "^6.2.5", 21 | "@react-navigation/stack": "^6.0.11", 22 | "expo": "^44.0.0", 23 | "expo-splash-screen": "~0.14.1", 24 | "react": "17.0.1", 25 | "react-dom": "17.0.1", 26 | "react-native": "0.64.3", 27 | "react-native-gesture-handler": "~2.1.0", 28 | "react-native-reanimated": "~2.3.1", 29 | "react-native-safe-area-context": "3.3.2", 30 | "react-native-screens": "~3.10.1", 31 | "react-native-unimodules": "~0.15.0", 32 | "react-native-web": "0.17.1" 33 | }, 34 | "devDependencies": { 35 | "@babel/core": "^7.12.9", 36 | "@babel/runtime": "^7.12.18", 37 | "@expo/webpack-config": "~0.16.2", 38 | "@types/react": "~17.0.21", 39 | "@types/react-native": "~0.64.12", 40 | "babel-loader": "^8.2.3", 41 | "babel-plugin-module-resolver": "^4.1.0", 42 | "babel-preset-expo": "9.0.1", 43 | "typescript": "~4.3.5" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'react'; 2 | import { ShowcaseApp } from '@gorhom/showcase-template'; 3 | import { PortalProvider, enableLogging } from '@gorhom/portal'; 4 | import { screens } from './screens'; 5 | import { version, description } from '../../package.json'; 6 | 7 | enableLogging(); 8 | 9 | const App = () => { 10 | // variables 11 | const author = useMemo( 12 | () => ({ 13 | username: 'Mo Gorhom', 14 | url: 'https://gorhom.dev', 15 | }), 16 | [] 17 | ); 18 | return ( 19 | 20 | 27 | 28 | ); 29 | }; 30 | 31 | export default App; 32 | -------------------------------------------------------------------------------- /example/src/components/Button.tsx: -------------------------------------------------------------------------------- 1 | import React, { ReactNode } from 'react'; 2 | import { ViewStyle, TextStyle, StyleSheet } from 'react-native'; 3 | import { ShowcaseButton, ShowcaseLabel } from '@gorhom/showcase-template'; 4 | 5 | interface ButtonProps { 6 | label: string; 7 | endContent?: string | ReactNode; 8 | style?: ViewStyle; 9 | labelStyle?: TextStyle; 10 | onPress: () => void; 11 | } 12 | 13 | export const Button = ({ 14 | label, 15 | endContent, 16 | style, 17 | labelStyle, 18 | onPress, 19 | }: ButtonProps) => ( 20 | 25 | {label} 26 | {endContent && endContent} 27 | 28 | ); 29 | 30 | const styles = StyleSheet.create({ 31 | container: { 32 | flexDirection: 'row', 33 | justifyContent: 'space-between', 34 | alignContent: 'center', 35 | alignItems: 'center', 36 | }, 37 | }); 38 | -------------------------------------------------------------------------------- /example/src/components/CounterModal.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | GestureResponderEvent, 4 | StyleSheet, 5 | Text, 6 | TouchableOpacity, 7 | TouchableWithoutFeedback, 8 | View, 9 | } from 'react-native'; 10 | 11 | interface SimpleModalProps { 12 | count: number; 13 | onIncrease: () => void; 14 | onPress: (event: GestureResponderEvent) => void; 15 | } 16 | 17 | export const CounterModal = ({ 18 | count, 19 | onIncrease, 20 | onPress, 21 | }: SimpleModalProps) => { 22 | return ( 23 | 24 | 25 | 26 | Counter Modal 27 | 35 | {count} 36 | 37 | 41 | + 42 | 43 | 47 | - 48 | 49 | 50 | 51 | 52 | 53 | 54 | ); 55 | }; 56 | 57 | const styles = StyleSheet.create({ 58 | backdropContainer: { 59 | ...StyleSheet.absoluteFillObject, 60 | backgroundColor: 'rgba(0, 0, 0, 0.5)', 61 | justifyContent: 'center', 62 | alignItems: 'center', 63 | }, 64 | buttonContainer: { 65 | ...StyleSheet.absoluteFillObject, 66 | justifyContent: 'center', 67 | alignItems: 'center', 68 | }, 69 | modalContainer: { 70 | padding: 24, 71 | backgroundColor: 'white', 72 | }, 73 | actionButton: { 74 | width: 25, 75 | height: 25, 76 | borderRadius: 25, 77 | marginHorizontal: 2, 78 | justifyContent: 'center', 79 | alignItems: 'center', 80 | backgroundColor: 'rgba(0, 0, 0, 0.5)', 81 | }, 82 | }); 83 | -------------------------------------------------------------------------------- /example/src/components/SimpleModal.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | GestureResponderEvent, 4 | StyleSheet, 5 | Text, 6 | TouchableWithoutFeedback, 7 | View, 8 | } from 'react-native'; 9 | 10 | interface SimpleModalProps { 11 | onPress: (event: GestureResponderEvent) => void; 12 | } 13 | 14 | const SimpleModal = ({ onPress }: SimpleModalProps) => { 15 | return ( 16 | 17 | 18 | 19 | Simple Modal 20 | 21 | 22 | 23 | ); 24 | }; 25 | 26 | const styles = StyleSheet.create({ 27 | backdropContainer: { 28 | ...StyleSheet.absoluteFillObject, 29 | backgroundColor: 'rgba(0, 0, 0, 0.5)', 30 | justifyContent: 'center', 31 | alignItems: 'center', 32 | }, 33 | buttonContainer: { 34 | ...StyleSheet.absoluteFillObject, 35 | justifyContent: 'center', 36 | alignItems: 'center', 37 | }, 38 | modalContainer: { 39 | padding: 24, 40 | backgroundColor: 'white', 41 | }, 42 | }); 43 | 44 | export default SimpleModal; 45 | -------------------------------------------------------------------------------- /example/src/components/SimplePopover.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useMemo, useState } from 'react'; 2 | import { 3 | GestureResponderEvent, 4 | LayoutChangeEvent, 5 | LayoutRectangle, 6 | StyleSheet, 7 | Text, 8 | TouchableWithoutFeedback, 9 | View, 10 | } from 'react-native'; 11 | 12 | const SPACE = 10; 13 | 14 | interface SimplePopoverProps { 15 | position: 'top' | 'bottom' | string; 16 | targetLayout: LayoutRectangle; 17 | onPress: (event: GestureResponderEvent) => void; 18 | } 19 | 20 | const SimplePopover = ({ 21 | position, 22 | targetLayout, 23 | onPress, 24 | }: SimplePopoverProps) => { 25 | const [layout, setLayout] = useState({ 26 | width: 0, 27 | height: 0, 28 | }); 29 | 30 | const popoverPosition = useMemo( 31 | () => ({ 32 | opacity: layout.height === 0 || layout.width === 0 ? 0 : 1, 33 | top: 34 | position === 'bottom' 35 | ? targetLayout.y + targetLayout.height + SPACE 36 | : targetLayout.y - layout.height - SPACE, 37 | left: targetLayout.x + targetLayout.width / 2 - layout.width / 2, 38 | }), 39 | [position, layout, targetLayout] 40 | ); 41 | 42 | const popoverContainerStyle = useMemo( 43 | () => [styles.popoverContainer, popoverPosition], 44 | [popoverPosition] 45 | ); 46 | 47 | // callbacks 48 | const handlePopoverLayout = useCallback( 49 | ({ 50 | nativeEvent: { 51 | layout: { height, width }, 52 | }, 53 | }: LayoutChangeEvent) => { 54 | setLayout(state => { 55 | if (state.height === height && state.width === width) { 56 | return state; 57 | } 58 | 59 | return { 60 | height, 61 | width, 62 | }; 63 | }); 64 | }, 65 | [] 66 | ); 67 | 68 | return ( 69 | 70 | 71 | 72 | Simple Popover 73 | 74 | 75 | 76 | ); 77 | }; 78 | 79 | const styles = StyleSheet.create({ 80 | backdropContainer: { 81 | ...StyleSheet.absoluteFillObject, 82 | backgroundColor: 'rgba(0, 0, 0, 0.5)', 83 | }, 84 | buttonContainer: { 85 | ...StyleSheet.absoluteFillObject, 86 | }, 87 | popoverContainer: { 88 | position: 'absolute', 89 | alignSelf: 'center', 90 | padding: 24, 91 | backgroundColor: 'white', 92 | }, 93 | }); 94 | 95 | export default SimplePopover; 96 | -------------------------------------------------------------------------------- /example/src/screens/BasicScreen.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Portal, PortalHost } from '@gorhom/portal'; 3 | import { StyleSheet, Text, View } from 'react-native'; 4 | 5 | const BasicScreen = () => { 6 | return ( 7 | 8 | 9 | 10 | Text won't be teleported! 11 | 12 | 13 | Text to be teleported to the custom host #1 14 | 15 | 16 | 17 | 18 | Text to be teleported to the custom host #2 19 | 20 | 21 | 22 | 23 | 24 | Text to be teleported to the root host 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ); 34 | }; 35 | 36 | const styles = StyleSheet.create({ 37 | container: {}, 38 | box: { 39 | padding: 24, 40 | backgroundColor: '#333', 41 | }, 42 | customHostBox: { 43 | position: 'absolute', 44 | bottom: 0, 45 | left: 0, 46 | right: 0, 47 | padding: 24, 48 | backgroundColor: '#333', 49 | }, 50 | text: { 51 | alignSelf: 'center', 52 | textAlign: 'center', 53 | margin: 24, 54 | backgroundColor: '#eee', 55 | }, 56 | }); 57 | 58 | export default BasicScreen; 59 | -------------------------------------------------------------------------------- /example/src/screens/ModalScreen.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useState } from 'react'; 2 | import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'; 3 | import { Portal } from '@gorhom/portal'; 4 | import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; 5 | import SimpleModal from '../components/SimpleModal'; 6 | 7 | const Tab = createBottomTabNavigator(); 8 | 9 | const BasicScreen = () => { 10 | const [showModal, setShowModal] = useState(false); 11 | 12 | const handleOnModalPress = useCallback(() => { 13 | setShowModal(state => !state); 14 | }, []); 15 | 16 | return ( 17 | 18 | 19 | {showModal ? 'Hide' : 'Show'} Modal 20 | 21 | {showModal && ( 22 | 23 | 24 | 25 | )} 26 | 27 | ); 28 | }; 29 | 30 | const styles = StyleSheet.create({ 31 | container: { 32 | flex: 1, 33 | justifyContent: 'center', 34 | alignItems: 'center', 35 | alignContent: 'center', 36 | }, 37 | button: { 38 | paddingHorizontal: 24, 39 | paddingVertical: 12, 40 | borderRadius: 24, 41 | backgroundColor: '#333', 42 | }, 43 | text: { 44 | color: 'white', 45 | }, 46 | }); 47 | 48 | export default () => ( 49 | 50 | 51 | 52 | 53 | ); 54 | -------------------------------------------------------------------------------- /example/src/screens/NativeScreen.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useState } from 'react'; 2 | import { Platform, StyleSheet, View } from 'react-native'; 3 | import { Portal } from '@gorhom/portal'; 4 | import { ShowcaseLabel } from '@gorhom/showcase-template'; 5 | import { createNativeStackNavigator } from '@react-navigation/native-stack'; 6 | import { useNavigation } from '@react-navigation/native'; 7 | import { FullWindowOverlay } from 'react-native-screens'; 8 | import { Button } from '../components/Button'; 9 | import { CounterModal } from '../components/CounterModal'; 10 | 11 | const Stack = createNativeStackNavigator(); 12 | 13 | const DummyScreen = () => { 14 | const [showModal, setShowModal] = useState(false); 15 | const [count, setCount] = useState(0); 16 | const { navigate } = useNavigation(); 17 | 18 | const handleModalTogglePress = useCallback(() => { 19 | setShowModal(state => !state); 20 | }, []); 21 | 22 | const handleNavigatePress = useCallback(() => { 23 | navigate({ 24 | // @ts-ignore 25 | name: 'B', 26 | key: `screen-a-${Math.random()}`, 27 | }); 28 | }, [navigate]); 29 | 30 | return ( 31 | 32 | 33 |