Skip to main content

DeviceListProvider

DeviceListProvider owns a DeviceListItem[] state initialized from the SDK's default device list. It is a UI state provider, not a Bluetooth scan provider.

import {
BTDeviceList,
DeviceListProvider,
useDeviceList,
} from "@ovok/native/bt-device";

function Count() {
const { deviceListItems } = useDeviceList();
return <Text>{deviceListItems.length} devices</Text>;
}

export function DevicesScreen() {
return (
<DeviceListProvider>
<Count />
<BTDeviceList />
</DeviceListProvider>
);
}

Context shape​

type DeviceListContextValue = {
deviceListItems: DeviceListItem[];
setDeviceListItems: React.Dispatch<React.SetStateAction<DeviceListItem[]>>;
};

useDeviceList() must be called beneath DeviceListProvider; otherwise it throws a clear provider-required error. Mount the provider around every consumer that needs list state.

Connecting it to BTProvider​

BTProvider owns Bluetooth runtime state and does not require or mutate DeviceListProvider state. Bridge status changes into an app-owned list with onDeviceStatusChanged, or read live connection state with useDeviceConnection. The app can also update its own labels or add app-only entries:

function DeviceStatusBridge() {
const { setDeviceListItems } = useDeviceList();

return (
<BTProvider
bleManager={bleManager}
acceptedDevices={[IntegratedDevices.BP2] as const}
onDeviceStatusChanged={({ deviceData, status }) => {
setDeviceListItems((items) =>
items.map((item) =>
item.deviceType === deviceData.name ? { ...item, status } : item,
),
);
}}
>
<BTDeviceList />
</BTProvider>
);
}

The callback above is the explicit integration point: map the device identifier or model used by your app to its list row and update it there. The Bluetooth provider can be placed at the app boundary independently of DeviceListProvider.

The list type currently uses IntegratedDevices for deviceType. A custom Bluetooth declaration can still be integrated with BTProvider, but a custom catalog row needs an app-owned list model rather than pretending it is a built-in enum member.