Styling & Layout
zero-native uses React Native’s style prop and familiar CSS-like property names — without Yoga. At build time, static styles are folded directly into the binary .zn.ui template; at runtime, Compose (Android) and SwiftUI/UIKit (iOS) lay out and draw everything natively.
Build-time checks: Unsupported style keys and invalid values fail the build with the exact file, line, and column. (A few React Native compatibility keys —
shadowOffset,shadowOpacity,shadowRadius, andflexShrink: 0 | 1— are accepted and ignored so ported code compiles cleanly.)
1. Authoring Styles
Section titled “1. Authoring Styles”Pass a style object, an array of styles, or StyleSheet.create(...):
import { Column, Text, StyleSheet } from "@zeronative/ui"
export function Card(props: { active: boolean }) { return ( <Column style={[s.card, { borderColor: props.active ? "#2563EB" : "#E5E7EB" }]}> <Text style={s.title}>Hello</Text> </Column> )}
const s = StyleSheet.create({ card: { padding: 16, borderRadius: 12, borderWidth: 1, backgroundColor: "#FFFFFF" }, title: { fontSize: 16, fontWeight: 600, color: "#111827" },})StyleSheet.create,StyleSheet.absoluteFill,StyleSheet.absoluteFillObject,StyleSheet.hairlineWidth(0.4), andStyleSheet.flattenall work.- Shared styles and colours go in a
.tsfile (for exampletheme.ts), not a.tsxfile. The compiler reads.tsfiles at build time, so their values fold into the templates; a value imported from a.tsxfile (or from a.tsfile that imports one) isn’t known until the app runs, and astyle={C.bar}written with it is a build error that says so. - Conditional style arrays like
[s.a, active() && s.b]are a build error — use a ternary inside a style object ({ backgroundColor: active() ? "#000" : "#FFF" }) for dynamic keys so the compiler knows the exact slot. - Units: All lengths are in
dp(Android) /pt(iOS). Text sizes respect the user’s system font-scale setting (Android’s font size, iOS Dynamic Type; cap withmaxFontScaleor disable withallowFontScaling={false}).
2. The Fixed Modifier Order
Section titled “2. The Fixed Modifier Order”In Jetpack Compose and SwiftUI, modifier order changes how a view looks (e.g., padding before vs. after background). To eliminate order-dependent bugs, zero-native always applies style properties in one fixed, predictable order:
margin → size → transform → shadow → background → border → clip → press feedback → padding → content- Box model (same as React Native):
widthandheightincludepaddingandborderWidth, and excludemargin. Borders push inner content inward. - If you ever need custom layering (such as a background inside a padding), wrap the inner content in a
<Box>or<Column>.
3. Supported Style Keys
Section titled “3. Supported Style Keys”Layout & Sizing
Section titled “Layout & Sizing”- Size:
width,height(numbers,"%","auto", or motion values),minWidth,maxWidth,minHeight,maxHeight,aspectRatio(number or"16/9") - Flex:
flex(orflexGrow),justifyContent,alignItems,alignSelf,flexWrap("wrap"/"nowrap"onRow),alignContent(on wrappedRow),gap,rowGap,columnGap - Spacing:
margin,marginHorizontal,marginVertical,marginTop,marginBottom,marginStart,marginEnd(plusmarginLeft/marginRightaliases), and matchingpadding*keys - Positioning:
position("relative"|"absolute"—position: "absolute"is a build error outside<Stack>),top,bottom,start,end(plusleft/rightaliases),zIndex,display("flex"|"none") - Direction:
flexDirection("row"|"column") works on<View>,<Pressable>, and the<Touchable*>aliases. Elsewhere, pick<Row>or<Column>directly.
Drawing & Effects
Section titled “Drawing & Effects”- Background:
backgroundColor(#hex,rgb(),rgba(),"transparent", CSS named colors, or motion color),backgroundImage("linear-gradient(...)", build-time) - Borders:
borderWidth,borderTopWidth,borderBottomWidth,borderColor,borderTopColorandborderBottomColor(the top / bottom line’s own colour; defaultborderColor),borderStyle("solid"|"dashed"|"dotted"),borderRadius, and per-corner radii (borderTopStartRadius,borderTopLeftRadius, etc.) - Shadows:
elevationandshadowColordraw shadows on both platforms (shadowOffset,shadowOpacity, andshadowRadiusare accepted for RN compatibility and ignored on both platforms). - Visual:
opacity,overflow("visible"|"hidden"),blurRadius(Android 12+, every iOS version),cameraDistance - Transforms:
transform: [{ scale, scaleX, scaleY, translateX, translateY, rotate, rotateX, rotateY }],transformOrigin(keywords or percents like"top left","50% 100%")
Text (on <Text> and <TextField>)
Section titled “Text (on <Text> and <TextField>)”color,fontSize,fontWeight("normal","bold", or numeric100–900),fontStyle("normal"|"italic"),fontFamily(custom fonts)lineHeight,letterSpacing,textAlign("start"|"center"|"end"|"left"|"right"|"auto"),numberOfLinestextDecorationLine("none"|"underline"|"line-through"),textDecorationStyle("solid"|"dashed"|"dotted")textTransform("none"|"uppercase"|"lowercase"|"capitalize"),includeFontPadding(defaultfalse),maxFontScaletextShadowColor,textShadowOffset({ width, height }),textShadowRadius: a shadow under the letters, as in React Native (white text on a photo)fontVariant:["tabular-nums"]gives every digit the same width, so a time or an amount doesn’t shift as it changes; also"small-caps","oldstyle-nums","lining-nums","proportional-nums"(the font must have the feature)- Trailing spaces: Android leaves plain spaces at the end of a line out of the text’s width. To keep room at the end of a chat bubble’s text (for the time and ticks), use no-break spaces (
"\u00A0"), which count.
4. Layout Rules (zn Flex)
Section titled “4. Layout Rules (zn Flex)”- Choose your container explicitly:
<Column>stacks children vertically (defaultalignItems: "stretch").<Row>lays children out horizontally.<Stack>layers children on top of each other (required forposition: "absolute").<Box>is a single-child / simple wrapper container.<View>compiles to<Column>(or<Row>ifstyle={{ flexDirection: "row" }}).
alignItems: "stretch"in a<Row>: Only stretches children when theRowhas an explicit height andalignItems: "stretch"is written. Otherwise it acts like"flex-start".- Scrollable containers: On
<Scroll>and<List>, padding instyle(orcontentContainerStyle) scrolls with the content. Set padding in one place only (setting both is a build error). - RTL support: Use
start/end(paddingStart,marginEnd,textAlign: "start").left/rightaliases map tostart/endso they flip automatically in right-to-left locales. - Dynamic vs. build-time style keys: Any style key not supported as a dynamic slot (
DynamicProps) with a runtime value is a build error — that includes structural keys (alignItems,justifyContent,alignSelf,position,flexDirection,flexWrap,backgroundImage,fontFamily,transformOrigin) as well asfontWeight,textAlign,overflow,zIndex,elevation,shadowColor, andborderStyle.- Colors, opacity, transforms,
borderWidth,borderColor, padding, and margin update dynamically on both platforms. - Runtime
width,height,min/max,flex,gap,aspectRatio, corner radii,top/bottom/start/end,fontSize,lineHeight,letterSpacing, anddisplayupdate dynamically on both platforms too (see Platform Differences). - A size from the window, the safe areas and the font size together, read in the JSX so it follows each change:
style={{ maxHeight: useWindowDimensions().height - insets().top - insets().bottom - 200 * useWindowDimensions().fontScale }}. A full example (a list in a bottom sheet with a button under it): components.md.
- Colors, opacity, transforms,
5. Safe Areas, Status Bar & Keyboard
Section titled “5. Safe Areas, Status Bar & Keyboard”Safe areas and keyboard avoidance are configured per route in routes.ts — no <SafeAreaView> wrapper needed:
export const routes = defineRoutes({ home: { path: "/", screen: HomeScreen, safeArea: "all", // "all" (default) | "none" | { top?: boolean; bottom?: boolean } keyboard: "resize", // "resize" (default) | "none" },})- For full-bleed screens (
safeArea: "none"), read live insets withinsets()from@zeronative/core(insets().top,insets().bottom). - Control status bar and navigation bar colors/icons declaratively inside any screen with
<StatusBar barStyle="light-content" backgroundColor="#111827" />and<NavigationBar barStyle="dark-content" />.
6. Dark Mode & Custom Fonts
Section titled “6. Dark Mode & Custom Fonts”Dark mode
Section titled “Dark mode”Read the OS theme reactively with colorScheme() (or RN’s useColorScheme() / Appearance) from @zeronative/core:
import { colorScheme } from "@zeronative/core"
const bg = () => (colorScheme() === "dark" ? "#0B0F19" : "#FFFFFF")Custom fonts
Section titled “Custom fonts”Custom fonts work on Android and iOS. On iOS, a family with no bold face draws its nearest face instead of a thickened one (Platform Differences).
Place .ttf / .otf files in app/assets/fonts/ and reference them by file name (without extension) or shared family name:
<Text style={{ fontFamily: "Poppins-SemiBold", fontSize: 18 }}>Welcome</Text>// Or by family + weight:<Text style={{ fontFamily: "Poppins", fontWeight: 600, fontSize: 18 }}>Welcome</Text>If you reference a font name that isn’t present in app/assets/fonts/ (and isn’t a system font like "System", "sans-serif", "serif", "monospace"), the build fails immediately.