A component that enables proper layout behavior when React Native views are rendered inside SwiftUI components. It syncs layout information from SwiftUI back to React Native's Yoga layout system by updating the shadow node size.
When React Native views are placed inside SwiftUI components like BottomSheet, Popover or HStack and so on, the layout systems need to communicate. RNHostView bridges this gap:
With matchContents: The shadow node size is set to match the child React Native view's intrinsic size, allowing the SwiftUI parent to size itself based on the React Native content.
Without matchContents: The shadow node size is set to match the parent SwiftUI view's size, allowing the React Native content to fill the available space (useful for flex: 1 layouts).
Note: Pass a single React Native element as the child. RNHostView measures and lays out only its first child, so wrap several views in one parent View and let that view arrange them.
When using flex: 1 in your React Native content, omit the matchContents prop so the content fills the available SwiftUI space.
RNHostView with flex content
import{ useState }from'react';import{Text,View}from'react-native';import{Host,BottomSheet,Button,Group,RNHostView,}from'@expo/ui/swift-ui';import{ presentationDetents }from'@expo/ui/swift-ui/modifiers';functionExample(){const[isPresented, setIsPresented]=useState(false);return(<Hoststyle={{ flex:1}}><Buttonlabel="Open sheet"onPress={()=>setIsPresented(true)}/><BottomSheetisPresented={isPresented}onIsPresentedChange={setIsPresented}><Groupmodifiers={[presentationDetents(['medium','large'])]}><RNHostView><Viewstyle={{
flex:1,
backgroundColor:'#007AFF',
padding:24,}}><Textstyle={{ color:'white', fontSize:18}}>
This content fills the available space
</Text></View></RNHostView></Group></BottomSheet></Host>);}
Usage with Popover
RNHostView works well inside Popover to display interactive React Native content.
When true, the RNHost will update its size in the React Native view tree to match the
children's size.
When false, the RNHost will use the size of the parent SwiftUI View.
Pass an object to choose per axis. For example, { vertical: true } takes the width from the
parent and the height from the children, so text wraps and grows vertically.
Can be only set once on mount.