AspectRatio
Layout primitive that preserves a fixed width-to-height ratio.
Import
import { AspectRatio } from 'reactnatively';Installation
Install Reactnatively once in your React Native or Expo application, then import AspectRatio from the framework package.
pnpm add reactnativelyInteractive preview
Layout primitive that preserves a fixed width-to-height ratio.
1import { Text } from 'react-native';2import { AspectRatio } from 'reactnatively';34export function Example() {5 return (6 <AspectRatio padding="md">7 <Text>AspectRatio content</Text>8 </AspectRatio>9 );10}React Native usage example
1import { Text } from 'react-native';2import { AspectRatio } from 'reactnatively';34export function Example() {5 return (6 <AspectRatio padding="md">7 <Text>AspectRatio content</Text>8 </AspectRatio>9 );10}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | undefined | Content rendered inside the component. |
| style | StyleProp<ViewStyle> | undefined | Style applied to the outer container. |
| testID | string | undefined | Identifier used by tests and automation. |
| accessibilityLabel | string | undefined | Screen-reader label for the component. |
Variants and examples
Default
1import { Text } from 'react-native';2import { AspectRatio } from 'reactnatively';34export function Preview() {5 return (6 <AspectRatio padding="md">7 <Text>AspectRatio content</Text>8 </AspectRatio>9 );10}Composed example
1import { Text } from 'react-native';2import { AspectRatio, Box } from 'reactnatively';34export function AspectRatioComposed() {5 return (6 <Box padding="md">7 <AspectRatio>8 <Text>AspectRatio content</Text>9 </AspectRatio>10 </Box>11 );12}TypeScript IntelliSense
The component exports typed props, so editors can autocomplete prop names, union values, callbacks, and theme-aware style objects as you type.
1import type { ComponentProps } from 'react';2import { AspectRatio } from 'reactnatively';34type AspectRatioProps = ComponentProps<typeof AspectRatio>;56const exampleProps: AspectRatioProps = {7 style: undefined,8 testID: "reactnatively-example",9 accessibilityLabel: "Example control",10};1112export function TypedAspectRatio() {13 return <AspectRatio {...exampleProps} />;14}Theme support
AspectRatio participates in the Reactnatively theme system through semantic colors, spacing, radii, typography, motion, and glass tokens where those props apply. Wrap your app in ReactnativelyProvider or ThemeProvider to keep light mode, dark mode, density, and custom tokens consistent.
Accessibility
Use accessible labels, hints, roles, and focus behavior when AspectRatiois interactive. Reactnatively components are designed for React Native apps that need screen-reader support, reduced-motion handling, and consistent touch targets.
Expo compatibility
AspectRatio can be used in Expo apps with TypeScript. Glass and blur behavior depends on platform capability, so production interfaces should keep text contrast and fallback tinting readable when native blur is unavailable.