Skip to content

Vital's react native library

License

Notifications You must be signed in to change notification settings

tryVital/vital-react-native

Repository files navigation

vital-react-native

The official React Native Library for Vital API, HealthKit and Devices.

Documentation

Installation

The documentation can be found here.

SDK requirements

The SDKs require a minimum deployment target of 14.0+ on iOS. Note that you might need to update your Podfile in addition to the Xcode project:

# Podfile

-platform :ios, min_ios_version_supported
+platform :ios, '14.0'

Building the example app

The Vital React Native Library requires the following toolchains being present in the environment:

  • Node.js + Yarn package manager
  • Ruby + Bundler dependency manager (for iOS builds)
  • JDK/JRE (for Android builds)

The example app can be built and launched in three simple steps:

# Resolve and install dependencies.
yarn install

# Build all the packages.
yarn run example:build:ios
yarn run example:build:android

# Run the sample app via the Metro bundler
yarn run example:start:ios
yarn run example:start:android

Android Gradle setting notes

In your root project Gradle file (./build.gradle), make sure that:

  1. Your Kotlin Gradle Plugin version is in sync with the Kotlin version.

  2. You are compiling and targeting with Android SDK 34.

  3. You are minimally targeting at least Android SDK 26.

 buildscript {
   ext {
     kotlinVersion = "1.8.22"
     buildToolsVersion = "34.0.0"
     minSdkVersion = 26
     compileSdkVersion = 34
     targetSdkVersion = 34
   }

   dependencies {
-    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
+    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
   }
 }

Expo installation

This package cannot be used in the "Expo Go" app because it requires custom native code.

First install the package with yarn, npm, or npx expo install.

expo install @tryvital/vital-core-react-native
expo install @tryvital/vital-health-react-native

After installing this npm package, add the config plugin to the plugins array of your app.json or app.config.js:

{
  "expo": {
    "plugins": [
      "@tryvital/vital-core-react-native",
      "@tryvital/vital-health-react-native"
    ]
  }
}

Next, rebuild your app as described in the "Adding custom native code" guide.

API

The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and prebuild) the native app. If no extra properties are added, defaults will be used.

  • healthSharePermission (string): Sets the iOS NSHealthShareUsageDescription permission message to the Info.plist. Defaults to Allow $(PRODUCT_NAME) to check health info.

app.config.js

{
  "expo": {
    "plugins": [
      "@tryvital/vital-core-react-native",
      [
        "@tryvital/vital-health-react-native",
        {
          "healthSharePermission": "Custom health share permission"
        }
      ]
    ]
  }
}

Edit your app.json again and add this to ensure you set the correct minimum android version.

{
  "expo": {
    ...
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 34,
            "targetSdkVersion": 34,
            "minSdkVersion": 26
          },
        }
      ]
    ]
   ...
  }
}

Capabilities

The Expo config plugin for Vital Health SDK would perform all the necessary code mods during EAS prebuild to enable Apple HealthKit Background Delivery.

This means your app project will declare HealthKit entitlements and will link the Apple HealthKit framework. So you must be prepared to demonstrate Apple HealthKit usage in your app in your next submission to the Apple App Store.

  • Automatic: Build the app with EAS build
  • Manual: Visit Apple developer portal and enable the HealthKit capability for your bundle identifier before building for production. This can also be done via Xcode.