nori-ui

AspectRatio

Wraps children in a container with a fixed width-to-height ratio.

433 Bgzipped

At a glance

  • Use to constrain images, videos, maps, or any media to a known ratio.
  • Works identically on web and native — React Native's aspectRatio style property maps to the CSS aspect-ratio property via react-native-web.

Preview

Usage

import { AspectRatio } from '@nori-ui/core';
 
// 16:9 video thumbnail
<AspectRatio ratio={16 / 9}>
  <Image source={thumbnail} style={{ width: '100%', height: '100%' }} />
</AspectRatio>
 
// Square avatar placeholder
<AspectRatio ratio={1} style={{ width: 80 }}>
  <View style={{ flex: 1, backgroundColor: '#e2e8f0' }} />
</AspectRatio>

Common ratios

RatioValueUse
16 / 91.777Video, banners
4 / 31.333Classic photo
11.0Square avatar, card
2 / 30.667Portrait photo, poster
21 / 92.333Ultrawide cinema

Props

PropTypeDefaultDescription
ratio*numberThe ratio expressed as width / height. Common values: - `16 / 9` (1.777…) — widescreen video - `4 / 3` (1.333…) — classic photo - `1` — square - `2 / 3` (0.666…) — portrait
classNamestring
testIDstring

On this page

Preview theme