Developing Android Widgets
Voltra allows you to build Android Home Screen widgets using JSX and Jetpack Compose Glance primitives.
Glance Primitives
On Android, you use VoltraAndroid components which map to Glance primitives:
- Column: Vertical layout
- Row: Horizontal layout
- Box: Stacked layout
- Spacer: Flexible spacing
- Text: Displaying text
- Image: Displaying images
- Scaffold: Top-level container
Example Widget
Update API
To update a widget's content, use the updateAndroidWidget function from @use-voltra/android-client:
updateAndroidWidget only updates payload-driven widgets like this one. Calling it on a Dynamic Widget (see Dynamic Widgets) rejects with VOLTRA_WIDGET_KIND_MISMATCH.
Layout Constraints
Unlike standard React Native or iOS Stacks, Android Glance layouts are more restrictive:
- Width/Height: Use fixed numbers (dp),
"100%"to fill available space, or"auto"to wrap content. - Modifiers: Most styling is handled via the
styleprop, which maps to GlanceModifiers. See Styling for full details. - Alignment: Use
verticalAlignmentandhorizontalAlignmentprops onColumnandRow.
Advanced Features
- Querying Active Widgets: Detect active widget instances and their sizes.
- Testing and Previews: Preview layouts within your app.
- Widget Picker Previews: Configure how your widget appears in the Android widget picker.
- Image Preloading: Cache remote images for use in widgets.
- Widget Pre-rendering: Provide initial state for widgets before the app first runs.
