Native UI
The three UI packages of BakeNative - Universal (@bake-native/react/ui), SwiftUI (@bake-native/react/ui/swift-ui) and Jetpack Compose (@bake-native/react/ui/jetpack-compose) - and which one to use.
The React adapter exposes Universal and SwiftUI components. Octane uses the corresponding @bake-native/octane/ui and @bake-native/octane/ui/swift-ui imports. Jetpack Compose is planned. They follow the structure of @expo/ui: one Universal layer and one package per platform toolkit.
| Package | Like | Platforms | Status |
|---|---|---|---|
@bake-native/react/ui | @expo/ui | iOS, macOS, Android, web, Windows | v0.1 |
@bake-native/react/ui/swift-ui | @expo/ui/swift-ui | iOS, macOS (an HTML stand-in on the web; a build error on Android and Windows) | available |
@bake-native/react/ui/jetpack-compose | @expo/ui/jetpack-compose | Android | coming soon (v0.2) |
When to use Native UI
Build the screen from the adapter's built-in views and supported HTML
(Use built-in views first). Reach for these
packages only when a part of the screen needs the platform's own UI toolkit: a SwiftUI control and
its system look on iOS and macOS, for example, or Jetpack Compose on Android once it ships. Keep
that part in its own component, inside a Host, so the rest of the screen stays on built-in views.
Within Native UI, start with the Universal layer (@bake-native/react/ui). It draws the platform
toolkit's controls where one exists and keeps one source for every target. Use a platform package
only for a control, modifier or behavior the Universal layer does not have. Examples: a SwiftUI
BottomSheet with detents, a Menu, Liquid Glass button styles.
Universal's Text draws inside a Host. It is a different component from the built-in Text
that @bake-native/react exports. Inside a Host, Universal's layout components (Column, Row,
Spacer) arrange the controls. Outside a Host, use the built-in views.
// Universal: controls inside a Host, on every target.
import { Host, Column, Text, Switch } from '@bake-native/react/ui';
<Host>
<Column spacing={12}>
<Text>Settings</Text>
<Switch label="Notifications" value={on} onValueChange={setOn} />
</Column>
</Host>// Platform package: only what Universal does not have, on iOS and macOS.
import { Host, Menu, Button } from '@bake-native/react/ui/swift-ui';
<Host matchContents>
<Menu label="Sort" systemImage="arrow.up.arrow.down">
<Button label="Name" onPress={() => setSort('name')} />
<Button label="Date" onPress={() => setSort('date')} />
</Menu>
</Host>How the three relate
- Same names. Components and props have
@expo/ui's names. Universal uses the Universal names (Switch,onValueChange). A platform package uses the toolkit's names (Toggle,isOn,onIsOnChangein SwiftUI). - State is controlled from JS in all three. A control shows the value you pass and reports a change through its callback.
Hostis the boundary. Each package draws what is inside itsHost. A screen can hold Universal and platform hosts side by side.- Universal fails closed. A component or prop outside the Universal table is a build error on every target, with the alternative in the message. See Blocked and alternatives.
- A platform package fails closed off its platform. A SwiftUI component rendered on Android or Windows is a build error (
ui-swift-ui-target) that names Universal and theBAKE_TARGETbranch. See SwiftUI platforms.
Compare
Universal (@bake-native/react/ui) | SwiftUI (@bake-native/react/ui/swift-ui) | Jetpack Compose (@bake-native/react/ui/jetpack-compose) | |
|---|---|---|---|
| Platforms | iOS, macOS, Android, web, Windows | iOS, macOS. The web gets an HTML stand-in. On Android and Windows it is a build error (ui-swift-ui-target) | Android |
| Components | Layout (Host, Column, Row, Spacer, Text), controls (Button, Switch, Checkbox, Slider, Picker, TextInput), Header, TabBar | Stacks, Form / List / Section, controls, Menu, NavigationStack, TabView, BottomSheet, GlassEffectContainer, BakeView | coming soon |
| Styling | style, textStyle (CSS) | SwiftUI modifiers (modifiers={[padding(…)]}) | coming soon |
| Unknown component or prop | build error (ui-component, ui-prop, …) | not checked yet, except the Host's ignoreSafeArea (ui-swift-ui-prop) | coming soon |
| Drawn by | SwiftUI inside a Host on iOS and macOS. Elements and CSS on web and Windows, the same pixels on both. The same elements on Android until its Compose host (v0.2) | SwiftUI (UIHostingController, NSHostingView) | Jetpack Compose |
| Use it for | platform-toolkit controls with one source for every target | a system control or look Universal does not have, on Apple platforms | the same, on Android |
Native features: spec first
Write one TypeScript spec for a native feature, implement the Swift, Kotlin, Rust and web contracts generated from it in one task with the same tests, and let the build check every platform against it.
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.