Skip to content

Styling

PAM Native gives you two ways to style a screen, and both end up as the same typed native properties:

  • the Style object, a readonly PHP value with named arguments, for typed PHP trees; and
  • CSS in <style> blocks of single-file components (and a project-wide src/app.css), for templates.

CSS in PAM Native is not a browser engine. The style compiler reads your CSS when the component is compiled, validates every declaration, and lowers it to integer property keys and numbers. Nothing parses CSS while the app renders, there is no DOM and no cascade work per frame. Layout runs in the shared Rust engine (the same flexbox for Android and iOS); paint runs in the platform renderer.

Every element accepts ->style(new Style(...)). Colors are ARGB integers (0xFF alpha first), lengths are density-independent points (dp on Android, pt on iOS):

src/Screens/ProfileHeader.php
<?php
declare(strict_types=1);
namespace App\Screens;
use Pam\Native\Align;
use Pam\Native\Component;
use Pam\Native\Element;
use Pam\Native\FlexDirection;
use Pam\Native\Style;
use Pam\Native\UI\Image;
use Pam\Native\UI\Text;
use Pam\Native\UI\View;
final class ProfileHeader extends Component
{
public function __construct(
public string $name = 'Alice',
public string $avatar = 'https://example.com/alice.jpg',
) {
}
public function render(): Element
{
return View::make(
Image::make($this->avatar)
->accessibilityLabel("{$this->name}'s photo")
->style(new Style(width: 56, height: 56, borderRadius: 28)),
Text::make($this->name)
->style(new Style(fontSize: 20, fontWeight: 700, textColor: 0xFF0F172A)),
)->style(new Style(
flexDirection: FlexDirection::Row,
alignItems: Align::Center,
gap: 12,
padding: 16,
backgroundColor: 0xFFFFFFFF,
borderRadius: 16,
shadowOffsetY: 2,
shadowBlurRadius: 8,
shadowColor: 0x1A000000,
));
}
}

Style covers layout (width, height, minWidth…, flexGrow, flexShrink, flexDirection, flexWrap, alignItems, alignSelf, justifyContent, gap, aspectRatio), the box model (padding*, margin*, borderWidth, per-side border widths, borderRadius and per-corner radii, borderColor, borderStyle), positioning (positionType, top, right, bottom, left, their *Percent variants, zIndex), paint (backgroundColor, opacity, overflow, elevation, shadow*, blurRadius), transforms (translationX, translationY, scaleX, scaleY, rotation), text (textColor, fontSize, fontWeight, fontStyle, fontFamily, lineHeight, letterSpacing, textAlign, textTransform, textDecoration, numberOfLines) and the responsive grid (gridColumns, gridSpan*, gridOffset*, gridOrder*). Enum-valued arguments take the PHP enums (Align, Justify, FlexDirection, PositionType, Overflow…), never strings.

In a single-file component, a <style> block next to the <template> styles that component only:

src/Components/PlanCard.pam.php
<?php
declare(strict_types=1);
namespace App\Components;
use Pam\Native\Component;
final class PlanCard extends Component
{
public function __construct(
public string $title = 'Pro',
public string $price = '$12 / month',
public bool $featured = false,
) {
}
}
?>
<template>
<Column class="card" :class="['featured' => $featured]">
<Text class="title">{{ $title }}</Text>
<Text class="price">{{ $price }}</Text>
</Column>
</template>
<style scoped>
.card {
padding: 20px;
gap: 8px;
border-radius: 20px;
background-color: #FFFFFF;
border: 1px solid #E2E8F0;
box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}
.featured {
border-color: #4F46E5;
border-width: 2px;
}
.title { font-size: 18px; font-weight: 700; color: #0F172A; }
.price { font-size: 15px; color: #475569; }
</style>

The block accepts four scopes:

Block Scope
<style> or <style scoped> Rules apply only to this component’s template.
<style module> Module scope for class names.
<style global> Rules apply application-wide.

A conventional src/app.css is prepended to every component’s sheet, so it is the right place for shared variables, fonts and base classes. Use @import "relative.css"; to split large sheets; imports must be relative .css files inside the project.

The compiler maps CSS to native properties. The most used groups:

Group Properties
Flexbox display, flex, flex-direction, flex-wrap, flex-grow, flex-shrink, flex-basis, justify-content, align-items, align-self, align-content, place-items, gap, row-gap, column-gap, order
Grid display: grid, grid-template-columns: repeat(N, …) (1–64 tracks), grid-column: span N
Box width, height, min-*, max-*, aspect-ratio, padding, margin (and per side, -inline, -block), box-sizing: border-box
Position position (relative, absolute, fixed), top, right, bottom, left, inset, z-index
Paint background-color, background (gradient layers plus a color), opacity, overflow, visibility, border*, border-radius, box-shadow, elevation, filter, backdrop-filter
Transform transform (translate*, scale*, rotate), transform-origin, transition
Text color, font, font-family, font-size, font-weight, font-style, line-height, letter-spacing, text-align, text-transform, text-decoration, text-shadow, text-overflow, line-clamp, white-space

PAM follows the React Native/Yoga defaults: flex-direction: column, align-items: stretch and flex-shrink: 0. A growing item without a basis starts from zero (flex-grow: 1 behaves like flex: 1 1 0); write flex-basis: auto to grow from the content size.

Text properties (color, font-*, line-height, letter-spacing, text-align, text-transform) inherit through containers, like CSS.

  • Lengths: px, dp and pt all mean density-independent points. sp, rem (16), em, %, vw, vh, vmin and vmax are also accepted.
  • Functions: calc(), min(), max(), clamp(), var(--name, fallback) and env(safe-area-inset-top|right|bottom|left, fallback). Expressions compile to bytecode and are evaluated once per render with the current window metrics, never per frame.
  • Colors: named colors, #rgb, #rrggbb, #rrggbbaa, rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() and color-mix(). Every color resolves to ARGB at compile time.

Type (Text), class, id, attribute and * selectors work, with descendant and child (>) combinators. :not(), :is() and :where() are expanded at compile time. The cascade is !important, then specificity, then source order.

Sibling combinators (+, ~) and structural pseudo-classes such as :nth-child() are not supported: bind a class from your data instead.

<Row p-for="$message in $messages" :key="$message->id" :class="['row', 'row-unread' => $message->unread]">
<Text>{{ $message->subject }}</Text>
</Row>

Declare variables in :root and package fonts with @font-face:

src/app.css
:root {
--brand: #4F46E5;
--muted: #64748B;
--radius: 16px;
}
@font-face {
font-family: "Brand";
src: url("asset://assets/fonts/Brand-Bold.ttf");
font-weight: 700;
}
.screen-title {
font-family: "Brand";
font-weight: 700;
font-size: 28px;
}

Custom properties are resolved when the sheet compiles. Unknown or circular variables are compile errors.

A small set of utility classes needs no stylesheet at all. Numeric utilities use a 4 dp scale (p-4 is 16 dp):

Utility Effect
p-N, px-N, py-N, m-N, mx-N, my-N, gap-N Padding, margin and gap of N × 4 dp
rounded-N, elevation-N Corner radius and elevation of N × 4 dp
flex-1, w-full, h-full Grow, 100 % width, 100 % height
items-start, items-center, items-end, items-stretch, items-baseline Cross-axis alignment
bg-white, bg-black, text-white, text-black Basic colors
opacity-N Opacity of N percent
grid-N, col-N, col-md-N, offset-N, order-N Twelve-column grid placement (see Responsive Layout)
<Column class="flex-1 p-4 gap-3">
<Text class="screen-title">Settings</Text>
</Column>

Language 2 components (<template language="2">) add compiled tokens and recipes. Tokens are immutable custom properties; dots become hyphens:

@tokens {
color.brand: #4F46E5;
color.surface: #FFFFFF;
space.md: 16px;
radius.card: 20px;
}
@recipe card {
base {
padding: var(--space-md);
border-radius: var(--radius-card);
background-color: var(--color-surface);
}
variant tone=featured {
background-color: var(--color-brand);
color: #FFFFFF;
}
}
<View recipe="card" variant:tone="featured">
<Text>Featured plan</Text>
</View>

An unknown recipe, variant axis or choice is a compile error instead of a silent visual fallback.

State selectors compile to native state styles. The press feedback runs on the UI thread; it never waits for PHP:

.button { background-color: #4F46E5; border-radius: 12px; }
.button:pressed { opacity: 0.72; transform: scale(0.98); }
.button:disabled { opacity: 0.4; }
.field:focus { border-color: #2563EB; }

Supported states are :pressed, :active, :focus, :focus-visible, :hover, :disabled, :checked, :selected, :loading, :error and :empty.

Queries use logical points and react to the native dimensions event. There is no layout feedback loop:

.catalog { gap: 12px; }
@media (min-width: 768dp) {
.catalog { gap: 24px; }
}
@media (prefers-color-scheme: dark) {
.card { background-color: #1E293B; }
}
@media (prefers-reduced-motion: reduce) {
.card { transition: none; }
}
@container product (min-width: 320dp) {
.title { font-size: 20px; }
}

Media features include width, height, orientation, prefers-color-scheme, prefers-reduced-motion, pointer and display-mode, plus PAM device features: device-type, refresh-rate, dynamic-range, fold-posture, input-mode, memory-class and performance-tier.

Pick Style when you build trees in PHP, compute values from data, or want refactoring tools and PHPStan to see every property:

Text::make($label)->style(new Style(
fontSize: $compact ? 14 : 16,
textColor: $danger ? 0xFFB91C1C : 0xFF0F172A,
));

Both produce the same properties, so you can mix them. In templates the cascade is deterministic: tag rules are the base, matching class rules win over tags (in stylesheet source order, not class attribute order), and a property attribute authored on the tag wins last. That makes inline attributes handy for one dynamic value:

<Text class="title" :textColor="$selected ? '#1B7A4E' : '#5C5C55'">{{ $label }}</Text>

The pam style command, shipped by pushinbr/pam-native, explains what the compiler does with a stylesheet:

Terminal window
pam style manifest # every supported CSS property, its native name and render cost
pam style inspect src/app.css # validate a sheet and print rules, queries, keyframes and source map
pam style tokens src/app.css generated/style # generate typed PHP, Kotlin and Swift token files

Every property in the manifest declares a render cost: Composite (opacity, transforms), Paint (colors, borders, shadows) or Layout. Only layout properties dirty the Rust layout tree; animating opacity or a transform never triggers a relayout.