Browse React Native
React NativeComponentsNo. 14 of 22
Separator
A hairline between items or sections, horizontal or vertical, hidden from screen readers unless it means something.
For the web: Separator, with the same name and variants.
Preview
Loading the preview
The gallery's web build, through react-native-web. On a phone the same code draws native views.
Installation
npx shadcn@latest add @corsair-native/separatorThe app's components.json needs the @corsair-native registry first; see Installation. The files land in your project as source: edit them like your own code.
- Also adds
- theme
API
Read from the source's own comments and types. Props marked * are required.
SeparatorComponent
A hairline between items or sections in the border colour. Horizontal lines fill the width; vertical ones fill the height of a row (give the row a height or alignItems: "stretch").
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "horizontal" |
decorativePurely visual (the default): screen readers skip it. Set it to false when the line separates content in a way that matters for understanding it. | boolean | true |
ref | Ref<View> | — |
Also takes every ViewProps prop (React Native docs).
Compatibility
- Expo SDK
- 54 and 57, both checked in CI
- React Native
- 0.81 and 0.86, New Architecture
- Web
- Expo's web target, through react-native-web
Source
1 file, installed as source you own
separator.tsxView on GitHubimport type { Ref } from "react";
import { StyleSheet, View, type ViewProps } from "react-native";
import { useTheme } from "@/registry/native/lib/theme";
interface SeparatorProps extends ViewProps {
orientation?: "horizontal" | "vertical";
/**
* Purely visual (the default): screen readers skip it. Set it to false when
* the line separates content in a way that matters for understanding it.
*/
decorative?: boolean;
ref?: Ref<View>;
}
/**
* A hairline between items or sections in the border colour. Horizontal lines
* fill the width; vertical ones fill the height of a row (give the row a
* height or `alignItems: "stretch"`).
*/
function Separator({
orientation = "horizontal",
decorative = true,
style,
...props
}: SeparatorProps) {
const { colors } = useTheme();
return (
<View
role={decorative ? "none" : "separator"}
aria-hidden={decorative || undefined}
style={[
orientation === "horizontal" ? styles.horizontal : styles.vertical,
{ backgroundColor: colors.border },
style,
]}
{...props}
/>
);
}
const styles = StyleSheet.create({
horizontal: {
height: StyleSheet.hairlineWidth,
alignSelf: "stretch",
},
vertical: {
width: StyleSheet.hairlineWidth,
alignSelf: "stretch",
},
});
export { Separator, type SeparatorProps };