Modifiers
contentShape
Defines the content shape for hit-testing purposes.
contentShape(shape)
| Parameter | Type | Description |
|---|---|---|
shape | Shape | A shape configuration from the shapes API (rectangle, circle, capsule, ellipse, roundedRectangle). |
Defines the content shape for hit-testing purposes.
This modifier is essential for making entire view areas (including Spacer or empty space) interactive. Without it, only visible elements like Text or Image respond to tap gestures.
Returns: ModifierConfig
See: Official SwiftUI documentation.
Example
import { HStack, List, Section, Spacer, Text } from "@expo/ui/swift-ui";
import { contentShape, onTapGesture } from "@expo/ui/swift-ui/modifiers";
import { shapes } from "@expo/ui/swift-ui/modifiers";
function InteractiveRow() {
return (
<List>
<Section title="Settings">
<HStack
modifiers={[
contentShape(shapes.rectangle()),
onTapGesture(() => console.log("Row tapped!"))
]}
>
<Text>Label</Text>
<Spacer />
<Text>Value</Text>
</HStack>
</Section>
</List>
);
}Works with
This modifier works with any view. These components accept it:
- VStack
- HStack
- ZStack
- LazyVStack
- LazyHStack
- Group
- Spacer
- Divider
- Overlay
- ScrollView
- Button
- Toggle
- Checkbox
- Slider
- Picker
- DatePicker
- ColorPicker
- Link
- ControlGroup
- Menu
- ContextMenu
- TextField
- SecureField
- Text
- Label
- Image
- List
- Form
- Section
- DisclosureGroup
- SwipeActions
- BottomSheet
- Alert
- ConfirmationDialog
- Popover
- ProgressView
- Gauge
- TabView
- AccessoryWidgetBackground
Sources
The original Expo docs for this page:
- contentShape (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)