百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

react-native-root-siblings

> 编程语言
开源

一个兄弟元素管理器。

737 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个兄弟元素管理器。

react-native-root-siblings

The easiest way to create overlays(Modal, Popover, Dialog etc) for both react and react-native.

Make your own showModal and use it in any component without any isShow state or even in a pure function call.

javascript
import RootSiblingsManager from 'react-native-root-siblings';

export const showModal = (renderModal) => {
  let rootNode;
  const onClose = () => {
    rootNode?.destroy();
    rootNode = null;
  };
  rootNode = new RootSiblingsManager(renderModal(onClose));
  return onClose;
};

import WelcomeModal from './WelcomeModal';

export function showWelcomeModal() {
  showModal((onClose) => );
}

// ...
function HomeScreen() {
  return Welcome!
}

setTimeout(showWelcomeModal, 3000);

Installation

bash
npm i react-native-root-siblings

Insert RootSiblingParent between your providers and root app in your root render function.

javascript
import { RootSiblingParent } from 'react-native-root-siblings';

return (
  
      // 
  
);      

RootSiblingParent works as a mounting base and can be mounted multiple times. Only the last mounted one would be active.

In react native, a view has a higher hierarchy if it's more close to the root level.

javascript

    //  
        //  
        { /* View put in here would be transported to RootSiblingParent 
            * So it can have a same hierarchy as the RootView to cover any other views
            */}
          
          
        
      
    
  

In react we have createPortal but still it's not so convenient as it can not be used outside of a component.

react-native-root-siblings provides the most possible flexibility:

Usage

Imperative API

  1. Create sibling element
javascript
let sibling = new RootSiblings();

This will create a View element cover all of your app elements, and returns a sibling instance. You can create a sibling anywhere, no matter in a component, hook or even a pure function.

  1. Update sibling element
javascript
sibling.update();

This will update the sibling instance to a View with blue backgroundColor and cover the screen by 10 offset distance.

  1. Destroy sibling element
javascript
sibling.destroy();

This will remove the sibling element.

Component API

javascript
import { RootSiblingPortal } from 'react-native-root-siblings';

class extends Component {
    render() {
        return (
            
                
            
        )
    }
}

EXAMPLE

…

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言