├── .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 | [](https://www.npmjs.com/package/@gorhom/portal) [](https://www.npmjs.com/package/@gorhom/portal) [](https://www.npmjs.com/package/@gorhom/portal) [](https://snack.expo.io/@gorhom/portal-example)
4 |
5 | A simplified portal implementation for ⭕️ React Native ⭕️.
6 |
7 | 
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 |