{"id":4011,"url":"https://github.com/magicismight/react-native-root-siblings","last_synced_at":"2025-05-15T03:07:06.141Z","repository":{"id":50736080,"uuid":"49612246","full_name":"magicismight/react-native-root-siblings","owner":"magicismight","description":"A sibling elements manager.","archived":false,"fork":false,"pushed_at":"2024-05-16T01:59:14.000Z","size":2236,"stargazers_count":730,"open_issues_count":15,"forks_count":134,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-14T10:01:01.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magicismight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-14T00:49:51.000Z","updated_at":"2025-05-14T07:19:35.000Z","dependencies_parsed_at":"2024-04-25T00:41:11.362Z","dependency_job_id":"0b15d709-d377-4701-ac82-50745573f930","html_url":"https://github.com/magicismight/react-native-root-siblings","commit_stats":{"total_commits":104,"total_committers":9,"mean_commits":"11.555555555555555","dds":0.6153846153846154,"last_synced_commit":"3d09e9a6e3904701cb40ed67154511e4ca3cfb8d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicismight%2Freact-native-root-siblings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicismight%2Freact-native-root-siblings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicismight%2Freact-native-root-siblings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magicismight%2Freact-native-root-siblings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magicismight","download_url":"https://codeload.github.com/magicismight/react-native-root-siblings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264766,"owners_count":22041793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:58.404Z","updated_at":"2025-05-15T03:07:01.132Z","avatar_url":"https://github.com/magicismight.png","language":"TypeScript","funding_links":[],"categories":["Components","Utilities"],"sub_categories":["UI"],"readme":"## react-native-root-siblings [![npm version](https://badge.fury.io/js/react-native-root-siblings.svg)](http://badge.fury.io/js/react-native-root-siblings)\n\nThe easiest way to create overlays(`Modal`, `Popover`, `Dialog` etc) for both `react` and `react-native`. \n\nMake your own `showModal` and use it in any component without any `isShow` state or even in a pure function call.\n\n```jsx\nimport RootSiblingsManager from 'react-native-root-siblings';\n\nexport const showModal = (renderModal) =\u003e {\n  let rootNode;\n  const onClose = () =\u003e {\n    rootNode?.destroy();\n    rootNode = null;\n  };\n  rootNode = new RootSiblingsManager(renderModal(onClose));\n  return onClose;\n};\n\nimport WelcomeModal from './WelcomeModal';\n\nexport function showWelcomeModal() {\n  showModal((onClose) =\u003e \u003cWelcomeModal onClose={onClose} /\u003e);\n}\n\n// ...\nfunction HomeScreen() {\n  return \u003cButton onClick={showWelcomeModal}\u003eWelcome!\u003c/Button\u003e\n}\n\nsetTimeout(showWelcomeModal, 3000);\n```\n\n---\n\n\n## Installation\n\n```sh\nnpm i react-native-root-siblings\n```\n\nInsert `RootSiblingParent` between your providers and root app in your root render function.\n\n```jsx\nimport { RootSiblingParent } from 'react-native-root-siblings';\n\nreturn (\n  \u003cSomeProviders\u003e\n    \u003cRootSiblingParent\u003e  // \u003c- use RootSiblingParent to wrap your root component\n      \u003cApp /\u003e\n    \u003c/RootSiblingParent\u003e\n  \u003c/SomeProviders\u003e\n);      \n```\n\n`RootSiblingParent` works as a mounting base and can be mounted multiple times. Only the last mounted one would be active.\n\nIn react native, a view has a higher hierarchy if it's more close to the root level.\n\n```jsx\n\u003cRootSiblingParent\u003e\n  \u003cRootView\u003e  //  \u003c- the highest view\n    \u003cNavigationView\u003e\n      \u003cScreenView\u003e  //  \u003c- the lowest view\n       { /* what if you want to show a fullscreen modal here?\n          * usually you have to use a Native Modal which is even higher than RootView\n          * but it's buggy and has a lot of limitations\n          */}\n        \u003cRootSiblingPortal\u003e\n        { /* View put in here would be transported to RootSiblingParent \n            * So it can have a same hierarchy as the RootView to cover any other views\n            */}\n          \u003cView\u003e\n          \u003c/View\u003e\n        \u003c/RootSiblingPortal\u003e\n      \u003c/ScreenView\u003e\n    \u003c/NavigationView\u003e\n  \u003c/View\u003e\n\u003c/RootSiblingParent\u003e\n```\n\nIn react we have `createPortal` but still it's not so convenient as it can not be used outside of a component. \n\n`react-native-root-siblings` provides the most possible flexibility:\n\n\n\n## Usage\n\n### Imperative API\n\n1. Create sibling element\n\n```jsx\nlet sibling = new RootSiblings(\u003cView\n    style={{top: 0,right: 0,bottom: 0,left: 0,backgroundColor: 'red'}}\n/\u003e);\n```\n\nThis will create a View element cover all of your app elements,\nand returns a sibling instance.\nYou can create a sibling anywhere, no matter in a component, hook or even a pure function.\n\n2. Update sibling element\n\n```jsx\nsibling.update(\u003cView\n    style={{top: 10,right: 10,bottom: 10,left: 10,backgroundColor: 'blue'}}\n/\u003e);\n```\n\nThis will update the sibling instance to a View with blue backgroundColor and cover the screen by `10` offset distance.\n\n3. Destroy sibling element\n\n```js\nsibling.destroy();\n```\n\nThis will remove the sibling element.\n\n\n### Component API\n\n```jsx\nimport { RootSiblingPortal } from 'react-native-root-siblings';\n\n\nclass extends Component {\n    render() {\n        return (\n            \u003cRootSiblingPortal\u003e\n                \u003cView style={[StyleSheet.absoluteFill, { backgroundColor: 'rgba(0, 0, 0, 0.25)' }]} /\u003e\n            \u003c/RootSiblingPortal\u003e\n        )\n    }\n}\n\n```\n\n## EXAMPLE\n\n```jsx\nimport React, {\n    AppRegistry,\n    View,\n    Component,\n    TouchableHighlight,\n    StyleSheet,\n    Text\n} from 'react-native';\nimport Dimensions from 'Dimensions';\n\n// Import library there,it will wrap everything registered by AppRegistry.registerComponent\n// And add or remove other elements after the root component\nimport RootSiblings from 'react-native-root-siblings';\n\nvar id = 0;\nvar elements = [];\nclass SiblingsExample extends Component{\n    addSibling = () =\u003e {\n        let sibling = new RootSiblings(\u003cView\n            style={[styles.sibling, {top: id * 20}]}\n        \u003e\n            \u003cText\u003eI`m No.{id}\u003c/Text\u003e\n        \u003c/View\u003e);\n        id++;\n        elements.push(sibling);\n    };\n\n    destroySibling = () =\u003e {\n        let lastSibling = elements.pop();\n        lastSibling \u0026\u0026 lastSibling.destroy();\n    };\n\n    updateSibling = () =\u003e {\n        let lastId = elements.length - 1;\n        lastId \u003e= 0 \u0026\u0026 elements[lastId].update(\u003cView\n            style={[styles.sibling, {top: lastId * 20}]}\n        \u003e\n            \u003cText\u003eI`m No.{lastId} : {Math.random()}\u003c/Text\u003e\n        \u003c/View\u003e);\n    };\n\n    render() {\n        return \u003cView style={styles.container}\u003e\n            \u003cTouchableHighlight\n                style={styles.button}\n                onPress={this.addSibling}\n            \u003e\n                \u003cText style={styles.buttonText}\u003eAdd element\u003c/Text\u003e\n            \u003c/TouchableHighlight\u003e\n            \u003cTouchableHighlight\n                style={styles.button}\n                onPress={this.destroySibling}\n            \u003e\n                \u003cText style={styles.buttonText}\u003eDestroy element\u003c/Text\u003e\n            \u003c/TouchableHighlight\u003e\n            \u003cTouchableHighlight\n                style={styles.button}\n                onPress={this.updateSibling}\n            \u003e\n                \u003cText style={styles.buttonText}\u003eUpdate element\u003c/Text\u003e\n            \u003c/TouchableHighlight\u003e\n        \u003c/View\u003e;\n    }\n}\n\nAppRegistry.registerComponent('SiblingsExample', () =\u003e SiblingsExample);\n\nvar styles = StyleSheet.create({\n    container: {\n        flex: 1,\n        alignItems: 'center',\n        justifyContent: 'center',\n        backgroundColor: 'green',\n    },\n    button: {\n        borderRadius: 4,\n        padding: 10,\n        marginLeft: 10,\n        marginRight: 10,\n        backgroundColor: '#ccc',\n        borderColor: '#333',\n        borderWidth: 1,\n    },\n    buttonText: {\n        color: '#000'\n    },\n    sibling: {\n        left: 0,\n        height: 20,\n        width: Dimensions.get('window').width / 2,\n        backgroundColor: 'blue',\n        opacity: 0.5\n    }\n});\n\n```\n\n![screen shoot](./Examples/screen-shoot.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagicismight%2Freact-native-root-siblings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagicismight%2Freact-native-root-siblings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagicismight%2Freact-native-root-siblings/lists"}