OpenBand UI (openband--ui)
A modern, high-performance, zero-overhead UI component library for Zepp OS 1.0+, engineered specifically for the Xiaomi Smart Band 7 (192x490 pill display, Dialog DA14697 MCU, QuickJS engine) while fully compatible with square and round Zepp OS watches.
Why OpenBand UI? (Comparison with Legacy Libraries)
Legacy community libraries like melianmiko--ZeppOS-Libraries (ListScreen.js, TouchEventManager.js) were pioneering, but carried heavy architectural overhead on low-RAM devices:
| Metric / Feature | Legacy ListScreen (melianmiko) | OpenBand UI (openband--ui) |
|---|---|---|
| Widget Hierarchy | Wraps every row in nested hmUI.widget.GROUP + child rects/images | Flat hierarchy: minimal native widgets, zero GROUP nesting |
| Memory Footprint | ~40-60 native widgets for a 10-item screen (causes QuickJS OOM) | ~10-15 native widgets total for equivalent screens |
| Touch Interaction | Transparent IMG overlays with manual pointer coordinates | Native hardware buttons: instant press tint, smooth scrolling |
| Curved Pill Padding | Hardcoded margins leave bottom items clipped by curved bezel | Dynamic scroll spacer: automatically ensures bottom elements are scrollable |
| Toggle Switches | Requires external PNG image assets for states | Pure vector switches: renders sharp pill track & thumb with zero assets |
| Lifecycle Safety | Manual cleanup often leads to zombie timers and memory leaks | screen.destroy(): bulk deletes all widgets & clears timers in onDestroy() |
| AMOLED Palette | Inconsistent colors across apps | Unified AMOLED palette: pure blacks (0x000000), rich cards (0x1A1A1E), vibrant accents |
Quick Start
import UI, { Screen, Colors } from './lib/openband-ui';
Page({
build() {
const screen = new Screen();
this.screen = screen;
// 1. Navigation Header
UI.header(screen, {
title: 'Smart Home',
showBack: true
});
// 2. Metric / Status Card
UI.metricCard(screen, {
title: 'Temperature',
value: '23.5',
unit: '°C',
status: 'Target: 22.0°C'
});
// 3. Vector Toggle Switch
UI.toggle(screen, {
title: 'Auto Lights',
value: true,
onChange: (enabled) => {
UI.toast(screen, enabled ? 'Lights ON' : 'Lights OFF');
}
});
// 4. Action Button with Haptics
UI.button(screen, 'Activate Scene', () => {
UI.toast(screen, 'Scene activated!');
}, { type: 'primary' });
// 5. Finalize layout (adds Band 7 bottom scroll padding)
screen.finalize();
},
onDestroy() {
// Bulk teardown prevents memory leaks across page transitions
if (this.screen) {
this.screen.destroy();
}
}
});
Component Reference
1. Screen (Layout & Lifecycle Manager)
Manages the vertical layout cursor, tracks all created widgets, and guarantees leak-free destruction.
const screen = new Screen({
autoStatusBar: true, // Hides status bar to maximize 192x490 canvas
paddingTop: 34, // Top inset
paddingBottom: 52, // Bottom scroll safety padding
marginX: 8, // Horizontal margin
gap: 8 // Default spacing between components
});
screen.gap(12); // Add vertical gap
screen.finalize(); // Call at the end of build() to append scroll spacer
screen.destroy(); // Call inside onDestroy() to free all native widgets
2. UI.header(screen, options)
Renders a top title bar with optional back navigation.
UI.header(screen, {
title: 'Settings',
showBack: true, // Shows '<' back button
onBack: () => hmApp.goBack() // Custom back handler (optional)
});
3. UI.metricCard(screen, options)
Dashboard status tile featuring large metric numbers and secondary info.
const tempCard = UI.metricCard(screen, {
title: 'Living Room',
value: '24.2',
unit: '°C',
status: 'Air Conditioner: ON',
accentColor: Colors.primary,
onClick: () => { ... }
});
// Update dynamically:
tempCard.setValue('25.0', '°C');
tempCard.setStatus('Target Reached');
4. UI.toggle(screen, options)
Pure vector toggle switch (no PNG images needed). Automatically handles press feedback, state transitions, and light haptics.
const myToggle = UI.toggle(screen, {
title: 'Haptic Feedback',
value: true,
colorOn: Colors.success,
colorOff: Colors.secondary,
onChange: (newValue) => {
console.log('Toggle state:', newValue);
}
});
// External control:
myToggle.setValue(false);
const isChecked = myToggle.getValue();
5. UI.button(screen, text, onClick, options)
Native touch button with rounded corners, automatic press color pairing, and haptic buzz.
UI.button(screen, 'Submit', () => {
// Tap handler
}, {
type: 'primary', // 'primary' | 'secondary' | 'danger' | 'success' | 'outline'
h: 46, // Height in pixels
haptic: true // Trigger light buzz on tap
});
6. UI.listItem(screen, options)
Menu row or data tile with title, subtitle, and right-aligned value or chevron.
UI.listItem(screen, {
title: 'Firmware',
subtitle: 'Zepp OS 1.0.3',
value: 'UPDATE', // Right accessory text
onClick: () => {
UI.toast(screen, 'Checking updates...');
}
});
7. UI.progressBar(screen, options)
Smooth rounded progress bar.
const bar = UI.progressBar(screen, {
progress: 75, // 0 to 100
h: 8,
fillColor: Colors.primary
});
bar.setProgress(90); // Dynamically updates fill width
8. UI.toast(screen, text, durationMs)
Floating on-screen notification that auto-dismisses and cleans up its own timer.
UI.toast(screen, 'Synced with phone', 2000);
9. UI.vibrate(scene)
Non-blocking safe haptic pulse.
UI.vibrate(25); // 25 = light tap, 23 = alert buzz, 24 = confirm
Color Palette (Colors)
Optimized for high-contrast AMOLED screens with minimal battery consumption:
| Token | Hex Value | Visual Purpose |
|---|---|---|
Colors.bg | 0x000000 | AMOLED pure black canvas |
Colors.card | 0x1A1A1E | Card / container background |
Colors.cardPress | 0x2A2A30 | Interactive card pressed state |
Colors.primary | 0x00D2FF | Electric Cyan accent |
Colors.success | 0x00E676 | Emerald Green active/success |
Colors.warning | 0xFFAB00 | Amber caution |
Colors.danger | 0xFF5252 | Coral Red danger / delete |
Colors.text | 0xFFFFFF | Primary text |
Colors.textSecondary | 0xA0A0A8 | Subtitle / secondary text |
Colors.textMuted | 0x66666E | Disabled / caption text |
Directory Structure
openband--ui/
├── README.md # Documentation & API reference
├── package.json # Library metadata
├── index.js # Unified export entry point
├── src/
│ ├── Theme.js # Color palette, screen metrics & typography
│ ├── Core.js # Screen class, layout cursor & lifecycle cleanup
│ ├── Components.js # Header, Card, Button, ListItem, Toggle, Metric, Toast
│ └── Utils.js # Haptics, widget property updater & safe text measure
└── examples/
├── demo_page.js # Full feature showroom page
└── settings_page.js # Settings & preferences menu page
License
MIT