BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

Universal UI

One component tree for every target with @bake-native/react/ui - the @expo/ui Universal components (Host, Column, Row, Spacer, Text, Button, Switch, Checkbox, Slider, Picker, TextInput) plus Header and TabBar.

@bake-native/react/ui is the Universal layer of Native UI. It follows @expo/ui's Universal components: the same component names, the same props, the same meaning. One source runs on iOS, macOS, Android, web and Windows.

Use it when a part of the screen needs the platform's own UI toolkit, such as SwiftUI controls and their system look. Build the rest of the screen from the built-in views and supported HTML (Use built-in views first). Use a platform package (@bake-native/react/ui/swift-ui) only for what this layer does not have. This layer's Text draws inside a Host and is a different component from the built-in Text. Inside a Host, this layer's Column, Row, and Spacer arrange the controls. Outside a Host, use the built-in views.

Install

@bake-native/react/ui ships with @bake-native/react. Octane apps use @bake-native/octane/ui. There is nothing else to install. Set up an app as in Installation, then import the components by name:

import { Host, Column, Text, Button } from '@bake-native/react/ui';

ui/index.d.ts gives your editor the types. There is no default export.

An Octane screen

import { useState } from 'octane';
import { Host, Column, Row, Text, Button, Switch, Slider, Picker, TextInput, Header, TabBar } from '@bake-native/octane/ui';

export function App() @{
  const [tab, setTab] = useState('home');
  const [on, setOn] = useState(true);
  const [volume, setVolume] = useState(0.4);
  const [theme, setTheme] = useState('system');
  const [name, setName] = useState('');
  <>
    <Header title="Settings" />
    <Host style={{ padding: '16px' }}>
      <Column spacing={12}>
        <Text textStyle={{ fontSize: 22, fontWeight: 'bold' }}>Settings</Text>
        <Switch label="Notifications" value={on} onValueChange={setOn} />
        <Row spacing={12} alignment="center">
          <Text>Volume</Text>
          <Slider value={volume} onValueChange={setVolume} />
        </Row>
        <Picker selectedValue={theme} onValueChange={setTheme}>
          <Picker.Item label="System" value="system" />
          <Picker.Item label="Dark" value="dark" />
        </Picker>
        <TextInput value={name} placeholder="Name" onChangeText={setName} />
        <Button label="Save" onPress={() => save()} />
      </Column>
    </Host>
    <TabBar
      tabs={[{ id: 'home', title: 'Home', icon: 'home' }, { id: 'me', title: 'Me', icon: 'person' }]}
      selected={tab}
      onSelect={(id) => setTab(id)}
    />
  </>
}

Header and TabBar are the screen's chrome. Put them next to the Host, not inside it.

The full example is examples/ui. Build it for every target with bake build --target web,windows,mac,ios,android.

State is controlled from JS

Every control shows the value you pass (value, selectedValue). It reports a change through its callback (onValueChange, onChangeText). Render the new value to apply it.

const [on, setOn] = useState(false);
<Switch value={on} onValueChange={setOn} />

There is no native state to keep in sync. @expo/ui's useNativeState is not needed: use useState from react in React and from octane in Octane.

TextInput's value is a plain string. Pass defaultValue alone for a field you do not control.

Components

Host

The root of a Universal tree. A block box sized by its CSS.

<Host style={{ padding: '16px' }} colorScheme="dark">…</Host>
PropMeaning
styleSize and place the Host like any element
matchContentstrue: as large as its content instead
colorScheme'light' or 'dark': forces the scheme of its content
testID, hiddenas on every component

Put Universal components inside a Host. On iOS and macOS the Host hands its tree to SwiftUI (see Platform hosts). The Host itself is a CSS box: its style places and pads it, and SwiftUI lays out what is inside, as tall as its content. Components outside a Host are drawn as elements on every target.

Column, Row

Children top to bottom (Column) or left to right (Row), spacing px apart.

<Row spacing={8} alignment="center">
  <Text>Volume</Text>
  <Slider value={volume} onValueChange={setVolume} />
</Row>

alignment is the cross axis: 'start' (default), 'center' or 'end'.

Spacer

Empty space along the stack. size is a fixed length in px. flexible takes the free space.

<Row>
  <Text>Name</Text>
  <Spacer flexible />
  <Button label="Edit" variant="text" />
</Row>

Text

<Text textStyle={{ fontSize: 22, fontWeight: 'bold', color: '#6e6e73' }} numberOfLines={1}>Settings</Text>

textStyle takes color, fontFamily, fontSize, fontWeight, letterSpacing, lineHeight and textAlign. Numbers are px at the default text size; fontSize and lineHeight follow the system text size, as React Native's do (Font size on Android, Text size on Windows, the browser's font size on the web: 16 is 1rem). The text of every Universal component (buttons, labels, pickers, text inputs) follows it the same way. numberOfLines={1} keeps the text on one line and ends it with an ellipsis. numberOfLines={N} with N > 1 shows at most N lines and ends the last one with an ellipsis: it is the CSS line clamp (display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: N; overflow: hidden), which every native target draws as Chrome does. A clamped Text keeps textAlign at start: another alignment with a clamp is a build error on native targets (css-line-clamp-align).

Button

<Button label="Save" onPress={save} />
<Button label="Share" variant="outlined" onPress={share} />
<Button label="Later" variant="text" onPress={later} />
<Button label="Disabled" disabled />

variant is 'filled' (default), 'outlined' or 'text'. Children replace label.

Switch, Checkbox

<Switch label="Notifications" value={on} onValueChange={setOn} />
<Checkbox label="Remember me" value={remember} onValueChange={setRemember} />

Both take value, onValueChange(value), label, disabled and testID.

Slider

<Slider value={volume} min={0} max={1} step={0.1} onValueChange={setVolume} />

min defaults to 0 and max to 1. Without step, the value is continuous.

Picker

<Picker selectedValue={size} onValueChange={setSize} accessibilityLabel="Size">
  <Picker.Item label="Small" value={1} />
  <Picker.Item label="Medium" value={2} />
</Picker>

An item's value is a string or a number. onValueChange gets the item's own value, so a number stays a number. appearance is 'menu' (default) or 'wheel'. iOS draws a wheel. macOS has no wheel picker, so both are a menu there. On web, Windows and Android both open a menu, as @expo/ui does on Android and the web. enabled={false} disables it. Picker.Item is also exported as PickerItem.

TextInput

<TextInput value={name} placeholder="Name" onChangeText={setName} autoCapitalize="words" />
<TextInput value={notes} placeholder="Notes" multiline rows={3} onChangeText={setNotes} />
PropMeaning
value, onChangeText(text)The text you control
defaultValueThe first text of a field you do not control
placeholder, maxLength, secureTextEntryAs in @expo/ui
multiline, rowsA text area
autoCapitalize'none', 'characters', 'words', 'sentences'
autoCorrect, autoCompleteKeyboard hints (autoComplete is the text content type on iOS)
inputMode'none', 'text', 'decimal', 'numeric', 'tel', 'search', 'email', 'url'
enterKeyHint'enter', 'done', 'go', 'next', 'previous', 'search', 'send'
onSubmitEditing({ text })Return in a single-line field
onFocus, onBlur, accessibilityLabel

Header, TabBar

The screen's header and tab bar. They are not in @expo/ui. Their props follow React Navigation's native-stack header and bottom tabs.

<Header title="Settings" rightItems={[{ id: 'add', systemImage: 'plus' }]} onItemPress={(id) => add()} />
<TabBar tabs={[{ id: 'home', title: 'Home', icon: 'home' }]} selected={tab} onSelect={(id) => setTab(id)} />

Render one Header per screen. It can sit anywhere in the page and takes no space there; if several render, the last one wins.

Header propMeaning
title, subtitleThe title, and a subtitle under it (iOS 26)
largeTitleThe large title, which collapses into the bar as the page scrolls
transparentNo bar background, and the page starts under the bar
blurEffectThe bar's blur: 'systemMaterial', 'systemThinMaterial', 'systemUltraThinMaterial', 'regular', 'prominent'…
backgroundColor, tintColor, titleColorThe bar color, the bar buttons' color and the title color
shadowVisibleThe bar's bottom hairline (default true)
backTitleThe back button title on the next screen
hiddenNo bar
leftItems, rightItemsBar buttons: [{ id, title?, systemImage?, badge?, disabled? }]. A press calls onItemPress(id)

iOS and macOS draw any SF Symbol in systemImage. The web, Android and Windows have no SF Symbols, so there systemImage takes a name from @bake-native/core/swift-ui/header-icons.json (Material Icons geometry, and a Segoe Fluent Icons glyph for Windows). Any other name is a build error on those targets (header-icon). Use a name from the table, or give the item a title instead; // bake-allow header-icon on the line accepts one name anyway, and targets without the symbol show the item's title.

TabBar propMeaning
tabs[{ id, title?, label?, icon?, systemImage?, badge?, disabled? }]. The tab shows label, or title when there is no label
iconA name from TAB_ICONS (home, search, person, settings, bell, heart, star, list, chart, chat, inbox, grid, box, bag), or { sf, sfSelected?, path, pathSelected? }
selected, onSelectThe selected tab's id (app state), and onSelect(id, { reselect })
tintColor, inactiveTintColor, backgroundColorColors of the selected item, the other items and the bar
labeledLabels under the icons (default true)
hiddenNo bar
minimizeBehavioriOS 26: 'automatic', 'never', 'onScrollDown' or 'onScrollUp'

The tabs are controlled: keep the selected tab in app state (useState). The bar shows the tab you render as selected, so the bar and the page switch in the same frame. On iOS, macOS and Android each tab keeps its scroll position. Both bars are part of the first screen: the build bakes them into app.baked, so they show before JavaScript runs.

Header: title, subtitle, largeTitle, transparent, blurEffect, backgroundColor, tintColor, titleColor, shadowVisible, backTitle, hidden, leftItems, rightItems, onItemPress.

TabBar: tabs, selected, onSelect(id, { reselect }), tintColor, inactiveTintColor, backgroundColor, labeled, hidden, minimizeBehavior. A tab's icon is a name from TAB_ICONS ('home', 'search', 'person', 'settings', …) or { sf, path }.

Common props

testID is on every component; on iOS and macOS it is the accessibility identifier. style and hidden are on Host, Column, Row, Text, Button and TextInput. On web, Windows and Android style is CSS and overrides the component's own styles, as do your class rules.

On iOS and macOS, SwiftUI draws what is inside a Host, so style below the Host takes only the keys SwiftUI draws: padding (1 to 4 lengths), paddingTop, paddingRight, paddingBottom, paddingLeft, width, height, minWidth, maxWidth, minHeight, maxHeight, opacity, backgroundColor and borderRadius. Lengths are px. Write the object in place (style={{ maxWidth: '300px' }}) so the build can check its keys. Another key, a % length or a style passed in a variable is a build error on ios and mac (ui-style). The Host's own style is CSS on every target.

Blocked and alternatives

The component table above is checked at build time (ui/scope.js). bake build checks every module that imports @bake-native/react/ui, for every target, the web included. Anything outside the table is a build error, never a silent no-op.

RuleWhen
ui-componentan import or a tag @bake-native/react/ui does not have (a later @expo/ui component, a typo, a default import)
ui-propa prop the component does not take
ui-prop-valuea literal value the prop does not take (variant="ghost", alignment="stretch")
ui-spread{...props} onto a component: its keys cannot be checked. Pass the props one by one
ui-swift-ui-targeta component of @bake-native/react/ui/swift-ui rendered on Android or Windows, which have no SwiftUI (see SwiftUI platforms)
ui-swift-ui-propignoreSafeArea on the SwiftUI Host, which SwiftUI does not draw. Use the ignoresSafeArea() modifier
ui-styleon ios and mac: a style key below the Host that SwiftUI does not draw, a length that is not px, or a style that is not an object literal (see Common props)

The message names what to use instead. These @expo/ui Universal components are not in v0.1:

@expo/uiInstead
BottomSheeta <dialog open>, or BottomSheet from @bake-native/react/ui/swift-ui on iOS and macOS
Collapsiblea <details> element
FieldGroupColumn with your own section styles
Iconan inline <svg>
List, ListItemColumn, or VirtualList from @bake-native/octane; Row
ScrollViewa <div> with overflow: auto
RNHostViewplain elements next to the Host
useNativeStateuseState from octane

These props are not in v0.1:

PropInstead
modifiersstyle. Platform modifiers are in @bake-native/react/ui/swift-ui
onAppear, onDisappearuseEffect and its cleanup in the component that renders it
editable, readOnlyrender the value as Text. TextInput has no read-only state in v0.1. Button, Switch, Checkbox and Slider take disabled, Picker takes enabled
autoFocusnothing yet
Host's ignoreSafeArea, layoutDirection, seedColor, onLayoutContentnothing yet

How each target draws it

Controls and layoutHeaderTabBar
Webelements and CSS (ui/ui.css)a CSS headera CSS bar
Windowsthe same elements and CSS as the webthe native header barthe same CSS bar as the web
iOS, macOSSwiftUI inside a Host (elements outside one)the system navigation barUITabBarController / toolbar tab group
Androidthe same elements as the web for now; the Jetpack Compose host is v0.2the native top barMaterial 3 navigation bar

Web and Windows draw a screen of Universal components with the same pixels. The parity tests compare them. To get there, the controls are drawn with CSS, not as the platform's form controls, whose sizes differ between Chromium and Windows:

  • Switch and Checkbox are boxes with an SVG check.
  • Slider is a CSS track and thumb driven by pointer events. iOS, macOS and Android do not feed the core raw pointer input yet, so they get the platform's range control.
  • Picker is a CSS field with a transparent <select> over it. The menu that opens is the platform's.

Platform hosts

Host is the boundary. Inside it, each platform draws the tree with its own UI toolkit, so the controls look and behave like the system's.

iOS and macOS: SwiftUI

On iOS and macOS a Host renders a <swiftui-host> (the host of @bake-native/react/ui/swift-ui), and each component inside it renders its SwiftUI node:

@bake-native/react/uiSwiftUI
ColumnVStack(alignment: .leading / .center / .trailing, spacing:)
RowHStack(alignment: .top / .center / .bottom, spacing:)
SpacerSpacer(minLength: 0) with flexible; a size × size frame otherwise
TextText with font (size, weight, family), foregroundStyle, kerning, line spacing, multilineTextAlignment and lineLimit from textStyle and numberOfLines
ButtonButton with buttonStyle(.borderedProminent) (filled), .bordered (outlined), .borderless (text)
SwitchToggle with toggleStyle(.switch)
CheckboxToggle with toggleStyle(.checkbox) on macOS, a switch on iOS (iOS has no checkbox, as in @expo/ui)
SliderSlider(value:in:step:)
PickerPicker with pickerStyle(.menu), or .wheel on iOS; each item is a Text tagged with its value
TextInputTextField (axis: .vertical, rows lines, with multiline) or SecureField, textFieldStyle(.roundedBorder); maxLength cuts longer input; autoCapitalize, autoCorrect, inputMode, enterKeyHint and autoComplete set the keyboard on iOS
  • Events. The callbacks and their arguments are the same on every target: onPress(), onValueChange(value), onChangeText(text), onSubmitEditing({ text }), onFocus(), onBlur(). Values stay controlled from JS: a control shows what the last render passed, and a user change reaches you only through the callback.
  • Size. The Host is a CSS box. The SwiftUI tree inside it is as wide as the box and as tall as its content (with matchContents, as wide as its content too). SwiftUI measures it at the box's width.
  • First frame. The Host's SwiftUI tree is part of the first screen, drawn before JS runs. SwiftUI measures each content-sized Host on that first screen and the snapshot is laid out with those sizes before it is shown, so adoption creates no view and moves nothing.
  • Bundles. The choice is made on import.meta.env.BAKE_TARGET at module level: only the ios and mac bundles carry the SwiftUI implementation.

Android: Jetpack Compose in v0.2

Android draws the same elements as the web for now: Slider is the platform's range control and the other controls are CSS. A Jetpack Compose host for the Host tree (@bake-native/react/ui/jetpack-compose) is v0.2. Until then an Android screen looks like the web one, not like a Compose screen.

Web and Windows

Web and Windows have no platform host: they draw the elements and CSS described above, with the same pixels.

Header and TabBar are the system navigation bar and tab bar on iOS, macOS and Android, outside the Host. On Windows, Header is a Fluent page header and TabBar is the same CSS bar as on the web.

In an existing app, the header goes into the host's bar, so a pushed screen shows one bar. iOS uses the host's navigation bar. On Android, when the BakeNativeView's Activity shows an action bar (platform or AppCompat), or the host passes a Toolbar as BakeNativeView.hostToolbar, the header's title, subtitle and items go to that bar; the host keeps the bar's look and its back / up button. Without one (or with headerInHostBar = false), the view draws the header as its own Material top bar.

Platform guides: Android, Windows.

On this page