component. -->
Presents content within a chosen aspect ratio.
Install the component via your command line.
npx expo install @rn-primitives/aspect-ratio
Copy/paste the following code to ~/components/primitives/aspect-ratio.tsx
~/components/primitives/aspect-ratio.tsx
import * as React from 'react';import { View, type ViewStyle } from 'react-native';import * as Slot from '~/components/primitives/slot';import type { SlottableViewProps } from '~/components/primitives/types'; interface AspectRatioRootProps { ratio?: number; style?: ViewStyle;} export type { AspectRatioRootProps }; const Root = React.forwardRef< React.ElementRef<typeof View>, Omit<SlottableViewProps, 'style'> & AspectRatioRootProps>(({ asChild, ratio = 1, style, ...props }, ref) => { const Component = asChild ? Slot.View : View; return <Component ref={ref} style={[style, { aspectRatio: ratio }]} {...props} />;}); Root.displayName = 'RootAspectRatio'; export { Root };
import * as AspectRatio from '@rn-primitives/aspect-ratio'; function Example() { return ( <AspectRatio.Root ratio={16 / 9} /> );}
Extends View props
View
1