This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
RNHostView
一个组件,可在 Jetpack Compose 中启用 React Native 视图。
一个组件,用于在 React Native 视图渲染在 Jetpack Compose 组件内部时,启用正确的布局行为。它通过更新 shadow node 的大小,将 Jetpack Compose 的布局信息同步回 React Native 的 Yoga 布局系统。
当 React Native 视图被放置在像 ModalBottomSheet、Card、Row、Column 等 Jetpack Compose 组件内部时,两个布局系统需要进行通信。RNHostView 负责连接这两者:
- 使用
matchContents时:shadow node 的大小会被设置为匹配子 React Native 视图的固有大小,从而允许 Jetpack Compose 父组件根据 React Native 内容来自行决定大小。 - 不使用
matchContents时:shadow node 的大小会被设置为匹配父 Jetpack Compose 视图的大小,从而允许 React Native 内容填充可用空间(适用于flex: 1布局)。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
带有 matchContents 的基本用法
当你希望 Jetpack Compose 父组件根据 React Native 内容来自行决定大小时,请使用 matchContents。
不使用 matchContents 的灵活内容
当你的 React Native 内容中使用了 flex: 1 时,请省略 matchContents 属性,这样内容就会填充可用的 Jetpack Compose 空间。
在 ModalBottomSheet 中使用
RNHostView 在 ModalBottomSheet 内部也能很好地工作,用于展示交互式 React Native 内容。
底部弹窗中的灵活 React Native 内容
使用不带 matchContents 的 RNHostView,让 React Native 视图填充弹窗内剩余的空间。配合父级 Column 上的 height 修饰符来控制弹窗大小。
API
import { RNHostView } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<RNHostProps>
boolean • Default: falseWhen true, the RNHost will update its size in the Jetpack Compose view tree to match the children's size.
When false, the RNHost will use the size of the parent Jetpack Compose View.
Can be only set once on mount.