Aspect Ratio
Native aspect-ratio container for images, video, and other media.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add aspect-ratioSource files
Expand a file to read the source the installer copies into your app.
components/ui/aspect-ratio/AspectRatio.tsx
import * as React from 'react'
import { View, type ViewProps } from 'react-native'
import { cn } from '@/lib/utils'
export interface AspectRatioProps extends ViewProps {
ratio?: number
className?: string
}
export const AspectRatio = React.forwardRef<React.ComponentRef<typeof View>, AspectRatioProps>(
({ ratio = 16 / 9, className, style, ...props }, ref) => (
<View
ref={ref}
{...props}
className={cn('relative overflow-hidden', className)}
style={[{ width: '100%', aspectRatio: Number.isFinite(ratio) && ratio > 0 ? ratio : 1 }, style]}
/>
),
)
AspectRatio.displayName = 'AspectRatio'
components/ui/aspect-ratio/index.ts
export * from './AspectRatio'