Quarvis Health device SDK for React Native
npm install quarvis-device-sdk-react-nativeQuarvis Health device SDK for React Native
``sh`
npm install quarvis-device-sdk-react-native
cd ios && pod install
Add the following to your ios/Your-App/Info.plist:
`xml
`
Add the following to your android/app/proguard-rules.pro:
`proguard`
-keep class com.crrepa.ble.* { ; }
Add the following to your android/app/src/main/AndroidManifest.xml
`xml
`
You can check the usage of the SDK in the example folder.
`js
import { isBluetoothEnabled } from 'quarvis-device-sdk-react-native';
// ...
const result = await isBluetoothEnabled();
`
If you need a background synchronization, you can use the following package.
Please, follow installation instructions from the package documentation.
Check the background synchronization in the example folder.
`tsx
const initBackgroundFetch = useCallback(async () => {
const onEvent = async (taskId: string) => {
console.log('[BackgroundFetch] Received task: ', taskId);
try {
onGetTodayActivity();
const [sleepInfo, heartRateInfo, bloodOxInfo, stressInfo] =
await Promise.allSettled([
onGetSleepInfo(),
onGetHeartRate(),
onGetBloodOx(),
onGetStressInfo(),
]);
console.log('[BackgroundFetch] Received sync data:', {
sleepInfo: 'value' in sleepInfo ? sleepInfo?.value : null,
heartRateInfo:
'value' in heartRateInfo ? heartRateInfo?.value : null,
bloodOxInfo: 'value' in bloodOxInfo ? bloodOxInfo?.value : null,
stressInfo: 'value' in stressInfo ? stressInfo?.value : null,
receivedSteps,
});
} catch (error) {
console.error('[BackgroundFetch] Error in background sync:', error);
} finally {
BackgroundFetch.finish(taskId);
}
};
const onTimeout = async (taskId: string) => {
console.warn('[BackgroundFetch] TIMEOUT task: ', taskId);
BackgroundFetch.finish(taskId);
};
const status = await BackgroundFetch.configure(
{
minimumFetchInterval: 15,
stopOnTerminate: true,
enableHeadless: false,
startOnBoot: false,
forceAlarmManager: false,
requiredNetworkType: BackgroundFetch.NETWORK_TYPE_ANY,
},
onEvent,
onTimeout
);
console.log('[BackgroundFetch] configure status: ', status);
}, [
onGetBloodOx,
onGetHeartRate,
onGetSleepInfo,
onGetStressInfo,
onGetTodayActivity,
receivedSteps,
]);
useEffect(() => {
initBackgroundFetch();
}, [initBackgroundFetch]);
`
Using QuarvisDeviceSdkReactNative in Jest tests requires mocking the native modules. You can use the following steps to mock the SDK in
Jest tests.
1. In your project root directory, create __mocks__/quarvis-device-sdk-react-native directory.index.ts
2. Inside that folder, create file.quarvis-device-sdk-react-native/jest
3. Inside that file, export mock.
`ts`
export * from 'quarvis-device-sdk-react-native/jest';
1. In your Jest config (probably in package.json) add setup files location:
`json`
{
"jest": {
"setupFiles": [
"./path/to/jestSetupFile.js"
]
}
}
2. Inside your setup file, set up quarvis-device-sdk-react-nativ mocking:
`ts``
jest.mock('quarvis-device-sdk-react-native', () =>
require('quarvis-device-sdk-react-native/jest')
);
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
---
Made with create-react-native-library