For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/device/viewport.md.

LynxViewport

The page's size and the app window's, as signals that follow a phone folding or unfolding, a rotation and split screen. import { LynxViewport } from '@blotch/angular-lynx';

Usage

src/app/inbox.ts
import { Component, computed, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxViewport } from '@blotch/angular-lynx';

@Component({
  selector: 'app-inbox',
  imports: [LYNX_ELEMENTS],
  template: `
    <view class="flex flex-row h-full">
      <view class="flex-1"><text>Messages</text></view>
      @if (twoPane()) {
        <view class="flex-1"><text>The open message</text></view>
      }
    </view>
  `,
})
export class Inbox {
  readonly #viewport = inject(LynxViewport);
  // The message beside the list on an unfolded phone or a tablet.
  readonly twoPane = computed(() => this.#viewport.width() >= 600);
}

Lengths in %, vw, vh and rpx follow a new size without code: read these to change what's on the screen, not how big it is. See Adaptive layouts.

API

LynxViewport

@Injectable({ providedIn: 'root' })
class LynxViewport {}

Reads the sizes the host app sends in its global props, as Lynx's foldable guide describes. The apps ng build --platform makes send them, and send them again before Lynx lays the page out at a new size, so a template that reads them changes with the layout.

  • A host that doesn't send them, such as Lynx Explorer, and the web preview still get a width and height that follow. They come from the window's resize event, once Lynx has laid the page out at its new size. screenWidth and screenHeight then stay the screen's from when the page started.
  • All sizes are in CSS pixels: points on iOS, dp on Android.

LynxViewport.width and height

readonly width: Signal<number>;
readonly height: Signal<number>;

The page's size: the LynxView's. It's what 100vw, a page-wide 100% and an @media (width …) rule measure against.

  • With "edgeToEdge": false in angular.json, it's the part of the window inside the safe area.
  • On Android, the height is shorter while the keyboard is open: the app makes room for it. On iOS the keyboard covers the page instead, and the height stays.

LynxViewport.screenWidth and screenHeight

readonly screenWidth: Signal<number>;
readonly screenHeight: Signal<number>;

The app window's size. 750rpx is its width.

  • It's the window, not the display: an app sharing the screen in split screen gets its own part, and a folded phone gets its outer screen.
  • A page in a dialog or a card of your own native app can be smaller than the window. Then the two pairs differ.

LynxViewport.orientation

readonly orientation: Signal<ViewportOrientation>;

'portrait' while the page is at least as tall as it's wide, otherwise 'landscape', as @media (orientation) decides. It's the page's shape, not the way the phone is held: an unfolded phone held upright, or an app in split screen, can be landscape.

Types

ViewportOrientation

import type { ViewportOrientation } from '@blotch/angular-lynx';

type ViewportOrientation = 'portrait' | 'landscape';