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

react-native-root-siblings

> 编程语言
开源

一个兄弟元素管理器。

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

工具介绍

一个兄弟元素管理器。

React-native-root-siblings

为 React 和 React-native 创建覆盖层(Modal,Popover,Dialog 等)的最简单方法。 自行创建 showModal 并将其用于任何组件,无需 isShow 状态,甚至可以在纯函数调用中使用。

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);

安装

bash
npm i react-native-root-siblings

在根渲染函数中,将 RootSiblingParent 插入到您的提供者和根应用之间。

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

return (
  
      // 
  
);      

RootSiblingParent 作为安装基础,可以多次安装。只有最后一次安装的内容才会生效。 在 React Native 中,视图的层次越高,就表示它越靠近根级别。

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
            */}
          
          
        
      
    
  

在 React 中,我们有 createPortal,但它仍然不太方便,因为无法在组件之外使用。React-native-root-siblings 提供了最大的灵活性:

Issues· 0 开放

查看全部 Issues在 GitHub 打开

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

> 标签

TypeScript

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

> 工具信息

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

> 相关工具

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