主机
一个用于连接 React Native 和 Jetpack Compose 的 Jetpack Compose 主机组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Host 组件是 React Native 和 Jetpack Compose 之间的桥梁。来自 @expo/ui/jetpack-compose 的每个 Jetpack Compose 组件都必须包裹在 Host 中才能正确渲染。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
匹配内容
使用 matchContents 属性让 Host 根据内容自动调整自身大小。你可以传入布尔值或对象,以独立控制垂直和水平尺寸。
import { Host, Button } from '@expo/ui/jetpack-compose'; export default function MatchContents() { return ( <Host matchContents> <Button onClick={() => console.log('Pressed')}>根据内容调整大小</Button> </Host> ); }
使用样式
将标准的 React Native 样式应用到 Host 包装器上。
import { Host, Button } from '@expo/ui/jetpack-compose'; export default function HostWithStyle() { return ( <Host style={{ padding: 16, backgroundColor: '#f0f0f0', borderRadius: 8 }}> <Button onClick={() => console.log('Pressed')}>带样式的 host</Button> </Host> ); }
API
import { Host } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<HostProps>
boolean • Default: falseWhen true, the Compose content will not perform keyboard avoidance behaviour when keyboard is shown.
Can be only set once on mount.
stringThe layout direction for the content. Defaults to the current locale direction from I18nManager.
Acceptable values are: 'leftToRight' | 'rightToLeft'
union • Default: falseWhen true, the host view will update its size in the React Native view tree to match the content's layout from Jetpack Compose. Can be only set once on mount.
Acceptable values are: boolean | {
horizontal: boolean,
vertical: boolean
}
(event: {
nativeEvent: {
height: number,
width: number
}
}) => voidCallback function that is triggered when the Jetpack Compose content completes its layout. Provides the current dimensions of the content, which may change as the content updates.
StyleProp<ViewStyle>boolean • Default: falseWhen true and no explicit size is provided, the host will use the viewport size as the proposed size for Compose layout. This is particularly useful for views that need to fill their available space.