This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).
Host
A Jetpack Compose Host component for bridging React Native and Jetpack Compose.
The Host component is the bridge between React Native and Jetpack Compose. Every Jetpack Compose component from @expo/ui/jetpack-compose must be wrapped in a Host to render correctly.
Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Match contents
Use the matchContents prop to make the Host size itself to fit the content. You can pass a boolean or an object to control vertical and horizontal sizing independently.
import { Host, Button } from '@expo/ui/jetpack-compose'; export default function MatchContents() { return ( <Host matchContents> <Button onPress={() => console.log('Pressed')}>Sized to content</Button> </Host> ); }
With style
Apply standard React Native styles to the Host wrapper.
import { Host, Button } from '@expo/ui/jetpack-compose'; export default function HostWithStyle() { return ( <Host style={{ padding: 16, backgroundColor: '#f0f0f0', borderRadius: 8 }}> <Button onPress={() => console.log('Pressed')}>Styled 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.