.safeAreaInset(props: {
edge: "top" | "bottom";
alignment?: "leading" | "center" | "trailing";
spacing?: number;
}, content: Component): Component
Which edge to place the inset content on.
alignment
"leading" | "center" | "trailing"
default:"center"
Horizontal alignment of the inset content within the edge.
The spacing between the inset content and the main content.
The component to place in the safe area inset.
Support
Usage
Floating bottom bar
ScrollView([
ForEach(items, (item) =>
Text(item.name).padding(12)
)
]).safeAreaInset(
{ edge: "bottom" },
HStack({ spacing: 12 }, [
Button("Cancel", () => {}),
Button("Save", () => {}),
])
.padding(16)
.background(Material("bar"))
)
Top banner
ScrollView([
ForEach(items, (item) =>
Text(item.name).padding(12)
)
]).safeAreaInset(
{ edge: "top", spacing: 0 },
Text("New items available")
.frame({ maxWidth: Infinity })
.padding(8)
.background(Color("blue"))
.foregroundStyle(Color("white"))
)
Notes
- The inset content stays fixed while the main content scrolls underneath.
- The main content’s safe area is adjusted to account for the inset, preventing overlap.
- Use for persistent toolbars, banners, or action bars that float above scrollable content.