GuidesComponentsApp UI components

BackgroundSyncSetting

Let a user enable Bluetooth background scanning

  • Stable unknown
  • Release candidate since 1.16.1-rc.3
  • Development since 1.16.1-dev.2111+9796905

BackgroundSyncSetting is a themed switch for Bluetooth background scanning. Render it beneath BTProvider, where useBackgroundSync can reach the active Bluetooth runtime:

import { useState } from "react";
import { BackgroundSyncSetting } from "@ovok/native/ui";
import { BTProvider } from "@ovok/native/bt-management";

function MonitoringSettings() {
  const [backgroundEnabled, setBackgroundEnabled] = useState(false);

  return (
    <BTProvider
      bleManager={bleManager}
      acceptedDevices={acceptedDevices}
      backgroundSync={{
        enabled: backgroundEnabled,
        storage: measurementStorage,
        onResult: uploadMeasurement,
      }}
    >
      <BackgroundSyncSetting
        enabled={backgroundEnabled}
        canEnable={platformPolicy.allowsBluetoothBackground}
        onEnabledChange={async (enabled) => {
          setBackgroundEnabled(enabled);
          await saveBackgroundPreference(enabled);
        }}
      />
    </BTProvider>
  );
}

The app owns the preference. Pass its current value to both the setting and BTProvider.backgroundSync.enabled, and persist changes in onEnabledChange. The setting's enabled prop initializes its local switch state; it does not subscribe to later prop changes. Keep the two values in sync from app-owned state.

Props

Every prop, with its type and description, is listed in the @ovok/native/ui API reference.

Last updated on

On this page