@exodus/gorhom-portal

中文文档
1.0.14-exodus.0发布于 2023/10/13MITTypeScriptESM + CJS近 30 天下载 1万

QQ React Native 的简化门户网站执行

中文使用文档
文档目录16 节
  1. 特征
  2. 安装
  3. 使用量
  4. 简单门户
  5. 自定义门户主机
  6. 反应原生屏幕集成
  7. 反应原生手势
  8. 道具
  9. 门户道具
  10. 门厅道具
  11. 钩子
  12. usePortal
  13. 由 QQ 创建
  14. 作者
  15. 赞助和支持
  16. 许可证

反应原生门户

React Native Portal npm npm runs with expo

QQ React Natural 的简化出入口执行.

React Native Portal


特征

  • 多门户处理.
  • 多门户主机处理.
  • 允许覆盖功能 .
  • 兼容 React Native Web。 。 。 .
  • 兼容 Expo, (中文(简体) ), 看看博览会小吃项目。 。 。 .
  • 写入 TypeScript。 。 。 .

安装

yarn add @gorhom/portal

使用量

简单门户

这是这个图书馆非常简单的用途,在那里,你将把内容传送到 PortalProvider 程序层.

首先,你需要添加 PortalProvider 到您的根组件 - 这通常是 App.tsx。 。 。 .

export const App = () => (
  <PortalProvider>
  {... your app goes here}
  </PortalProvider>
);

最后,将您想要传送的内容包起来 Portal。 。 。 .

const BasicScreen = () => {
  return (
    { ... }
    <Portal>
      <Text>
        Text to be teleported to the root host
      </Text>
    </Portal>
    { ... }
  );
};

自定义门户主机

当您需要将您的内容传送到自定义的门户主机时 PortalHost 在应用程序的任何一层.

首先,你需要添加 PortalProvider 到您的根组件 - 这通常是 App.tsx。 。 。 .

export const App = () => (
  <PortalProvider>
  {... your app goes here ...}
  </PortalProvider>
);

第二,你需要添加 PortalHost 使用自定义名称.

const CustomView = () => {
  return (
    { ... }
    <PortalHost name="CustomPortalHost" />
    { ... }
  );
};

最后,将您想要传送的内容包起来 Portal 和自定义门户主机名.

const BasicScreen = () => {
  return (
    { ... }
    <Portal hostName="CustomPortalHost">
      <Text>
        Text to be teleported to the CustomView component
      </Text>
    </Portal>
    { ... }
  );
};

反应原生屏幕集成

为了将您传送的内容放在所有本地视图之上, 您需要用 FullWindowOverlay 从 react-native-screens。 。 。 .

import { FullWindowOverlay } from 'react-native-screens';

const BasicScreen = () => {
  return (
    { ... }
    <Portal>
      <FullWindowOverlay style={StyleSheet.absoluteFill}>
        <Text>
          Text to be teleported to the CustomView component
        </Text>
      </FullWindowOverlay>
    </Portal>
    { ... }
  );
};

反应原生手势

为了避免在使用“反动土著手势”时出现问题,您必须设置 PortalProvider 下划线 GestureHandlerRootView否则它可能会冻结你的应用程序.

export const App = () => (
  <GestureHandlerRootView>
    <PortalProvider>
    {... your app goes here}
    </PortalProvider>
  </GestureHandlerRootView>
);

更多关于 应用程序冻结问题。 。 。 .

道具

门户道具

name

Portal)的密钥或取名来作代号.

required: 没有 type: 字符串% 1 default: 自动生成唯一密钥

hostName

主机的密钥或名称可以传送门户内容到.

required: 没有 type: 字符串% 1 default: '根' (英语)

handleOnMount

覆盖内部挂起功能, 如果您想在挂起门户内容前触发任何动作, 则此功能是有用的 .

type handleOnMount = (mount?: () => void) => void;

required: 没有 type: 函数 qq default: 未定义

handleOnUnmount

覆盖内部卸载功能, 如果您想在卸载门户内容之前触发任何动作, 则此功能是有用的 .

type handleOnUnmount = (unmount?: () => void) => void;

required: 没有 type: 函数 qq default: 未定义

children

门户网站内容.

required: 没有 type: 反向节点 QQ反向节点 [] QQ default: 未定义

门厅道具

name

主机的密钥或名称用作标识符.

required: 对 type: 字符串

钩子

usePortal

访问所有门户的内部功能.

/**
 * @param hostName host name or key.
 */
type usePortal = (hostName: string = 'root') => {
  /**
   * Register a new host.
   */
  registerHost: () => void;
  /**
   * Deregister a host.
   */
  deregisterHost: () => void;
  /**
   * Add portal to the host container.
   * @param name portal name or key
   * @param node portal content
   */
  addPortal: (name: string, node: ReactNode) => void;
  /**
   * Update portal content.
   * @param name portal name or key
   * @param node portal content
   */
  updatePortal: (name: string, node: ReactNode) => void;
  /**
   * Remove portal from host container.
   * @param name portal name or key
   */
  removePortal: (name: string) => void;
};

由 QQ 创建

作者

赞助和支持

为了保持该图书馆的维持和更新,请考虑 在GitHub上赞助或者,如果你寻求私人支持或帮助 定制经验,然后通过Twitter联系我 @gorhom (英语)。 。 。 .

许可证

麻省理工学院


Mo Gorhom Mo Gorhom

版本与发布记录

@exodus/gorhom-portal 共发布 1 个版本,首次发布于 2023/10/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.14-exodus.0latest2023/10/133 年前

关于 @exodus/gorhom-portal 的常见问题

@exodus/gorhom-portal 是什么?

QQ React Native 的简化门户网站执行

如何安装 @exodus/gorhom-portal?

在项目目录运行 npm install @exodus/gorhom-portal,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@exodus/gorhom-portal 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/gorhom-portal 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@exodus/gorhom-portal 可以商用吗?

@exodus/gorhom-portal 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/gorhom-portal 的下载量有多少?

根据 npm 官方下载统计,@exodus/gorhom-portal 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,364 次,日均约 345 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/gorhom-portal 还在维护吗?

最新版本 1.0.14-exodus.0 发布于 2023/10/13(3 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/10/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。