Voltra Documentation

repository·main·Indexed 21 days ago

https://github.com/callstackincubator/voltra

Voltra enables React Native developers to build iOS Live Activities and Android Home Screen Widgets using JSX, abstracting away the need for Swift or Kotlin UI code. It provides platform-specific client packages (@use-voltra/android-client, @use-voltra/ios-client), server-side rendering packages for Node.js (@use-voltra/android-server, @use-voltra/ios-server), and a compiler for build-time source analysis. Voltra supports both payload-driven and experimental Dynamic Widgets on Android, as well as ongoing notifications and Expo config plugin integration.

Tokens
121K
Snippets
305
Records
505
Agent score
72%

What's inside Voltra

  1. What is Voltra?

    main

    Voltra is a library for React Native that allows you to build native platform features—such as iOS Live Activities, Dynamic Island layouts, and Android Home Screen Widgets—using JavaScript and JSX.

    Instead of writing native Swift or Kotlin code, you use Voltra's JSX components. These components are serialized into a lightweight JSON format that native platform extensions interpret and render using native primitives: SwiftUI on iOS and Jetpack Compose Glance on Android.

  2. Overview of @use-voltra/expo-plugin

    main

    The @use-voltra/expo-plugin package provides shared build-time utilities used by Voltra Expo config plugins. It is designed to support the development of Live Activities and Widgets using JSX in React Native.

    Key utilities included in this package:

    • Localized label helpers: Includes localePick for handling locale fallbacks.
    • Widget config validation: Primitives for validating widget configurations.
    • Initial-state prerendering: A pipeline for prerendering initial states.

    Note that this package contains build-time utilities. For runtime client capabilities, you should use the platform-specific client plugins:

    • For iOS (Live Activities, widget extensions, push): @use-voltra/ios-client
    • For Android (home screen widgets): @use-voltra/android-client
  3. Overview of Voltra

    main

    Voltra is a framework that enables React Native developers to build native iOS Live Activities (including Dynamic Island experiences) and Home Screen widgets for both iOS and Android using React components. It eliminates the need to write manual Swift or Kotlin code by allowing developers to compose native interfaces using JSX.

    Key capabilities include:

    • Native Primitives in JSX: Use SwiftUI (iOS) and Jetpack Compose Glance (Android) primitives directly within your React code.
    • Unified Workflow: Build Live Activities and widgets for both platforms using a single React-based approach.
    • Push-to-update: Stream real-time updates to iOS Live Activities via push notifications from any JavaScript runtime, allowing activities to stay current without requiring user interaction with the app.
    • Developer Experience: Supports hot reload and includes an Expo config plugin for automatic wiring.
  4. Build Android Home Screen widgets with Voltra

    main

    Voltra allows you to define Android Home Screen widgets using JSX-based primitives that map to Jetpack Compose Glance components.

    Note: Android support is currently experimental. The API is subject to change.

    To build for Android, use the VoltraAndroid namespace to access platform-specific primitives like Column, Row, and Box. This ensures your UI adheres to Android's layout and styling rules, which differ from iOS's SwiftUI-based primitives.

    import { VoltraAndroid } from 'voltra'
    
    const MyWidget = () => (
      <VoltraAndroid.Column
        style={{
          padding: 16,
          backgroundColor: '#3DDC84',
          width: '100%',
          height: '100%'
        }}
        verticalAlignment="center-vertically"
        horizontalAlignment="center-horizontally"
      >
        <VoltraAndroid.Text
          style={{
            color: 'white',
            fontSize: 18,
            fontWeight: 'bold'
          }}
        >
          Android Widget
        </VoltraAndroid.Text>
        <VoltraAndroid.Text
          style={{
            color: 'white'
          }}
        >
          Powered by Voltra & Glance
        </VoltraAndroid.Text>
      </VoltraAndroid.Column>
    )
  5. Use Voltra for Android Home Screen Widgets

    main

    Voltra allows you to build Android Home Screen widgets using JSX. It uses Jetpack Compose Glance under the hood, mapping Voltra primitives to Glance components.

    Note: Android support is currently experimental. The API may change in future versions.

    To build Android-specific widgets, use the @use-voltra/android package and its VoltraAndroid namespace. This ensures your UI uses the correct Jetpack Compose Glance primitives like Column, Row, and Box instead of iOS-centric stacks.

    import { VoltraAndroid } from '@use-voltra/android'
    
    const MyWidget = () => (
      <VoltraAndroid.Column
        style={{
          padding: 16,
          backgroundColor: '#3DDC84',
          width: '100%',
          height: '100%'
        }}
        verticalAlignment="center-vertically"
        horizontalAlignment="center-horizontally"
      >
        <VoltraAndroid.Text
          style={{
            color: 'white',
            fontSize: 18,
            fontWeight: 'bold'
          }}
        >
          Android Widget
        </VoltraAndroid.Text>
        <VoltraAndroid.Text
          style={{
            color: 'white'
          }}
        >
          Powered by Voltra & Glance
        </VoltraAndroid.Text>
      </VoltraAndroid.Column>
    )
  6. Use @use-voltra/android-server for Android server-side rendering

    main

    The @use-voltra/android-server package is used to render Android widgets and ongoing-notification JSX into semantic payloads on the server. It provides capabilities for:

    • Android widget rendering
    • Android ongoing-notification payload rendering
    • Android widget update handlers

    CRITICAL USAGE RESTRICTION: This package must only be used in backend or server-side environments (e.g., Node.js). Do not import server renderers into your React Native app runtime code or include them in your app bundles.

  7. Available features in @use-voltra/android-client

    main

    The @use-voltra/android-client package provides the following capabilities for Android React Native development:

    • Payload-driven Home Screen widgets: Render and update widget variants with updateAndroidWidget, then reload, pin, and query widgets with reloadAndroidWidgets, getActiveWidgets, and more.
    • Dynamic Widgets (experimental): Declare widgets in app.json and render them on-device using runtime props and live environment values (size, color scheme, Material You colors, locale, configuration).
    • Ongoing notifications: Start and update promoted ongoing notifications with useAndroidOngoingNotification and related APIs.
    • Fast Refresh: Previews integrate with React Native dev workflow via VoltraWidgetPreview and VoltraView.
    • Image preloading: Download remote images for widgets with preloadImages and reloadWidgets.
    • Server-driven widgets: Store credentials for background widget fetches with setWidgetServerCredentials.
    • Expo config plugin: Declarative widget and notification configuration via app.json.
  8. Features of @use-voltra/android

    main

    The @use-voltra/android package provides the core primitives for Android rendering in Voltra, including:

    • VoltraAndroid: The Android-specific JSX namespace.
    • Dynamic Colors: Support for dynamic color rendering on Android.
    • Payload Rendering: Capabilities for rendering incoming payloads.
    • Server Entry: The @use-voltra/android/server entry point for Node.js environments.
  9. Understand the purpose of @use-voltra/server

    main

    @use-voltra/server provides the shared server-side rendering foundation for Voltra. It includes request adapters and platform-agnostic widget update handlers designed to facilitate server-driven widgets.

    Important Usage Constraint: This package is intended for Node.js / backend environments only. Do not include @use-voltra/server in your React Native app bundles.

  10. Use @use-voltra/ios-server for iOS Server Rendering

    main

    The @use-voltra/ios-server package is designed for backend environments (such as Node.js) to render iOS Live Activities and widgets from JSX into payloads. This allows you to drive iOS widget updates and Live Activity content from your server.

    Important Restriction: This package must be used in Node.js or backend environments only. Do not include it in your React Native app bundles.

  11. What is included in @use-voltra/ios

    main

    The @use-voltra/ios package provides the foundational primitives for iOS rendering in Voltra, including:

    • The Voltra JSX namespace for defining iOS-specific UI components.
    • Payload rendering capabilities.
    • The @use-voltra/ios/server entry point, which is used for server-side implementations (often used in conjunction with @use-voltra/ios-server).
  12. What is Voltra and how does it work?

    main

    Voltra is a library that allows React Native developers to build native mobile surfaces—specifically iOS Live Activities (including Dynamic Island) and Android Home Screen Widgets—using JSX.

    Core Concept

    Instead of writing Swift (SwiftUI) or Kotlin (Jetpack Compose Glance), you write React components using Voltra's specialized component set. Voltra translates your JSX into the appropriate native layouts.

    Key Capabilities

    • Native Surfaces: Directly create iOS Live Activities and Android Widgets.
    • Fast Development: Supports Fast Refresh and platform-specific payload budgets.
    • Push Notifications: Supports ActivityKit push tokens (iOS) and FCM (Android) for server-driven updates.
    • Compatibility: Works with both Expo Dev Client and bare React Native projects via Expo config plugins.