GitHub - openfluke/react-native-loom-example · GitHub
Skip to content

openfluke/react-native-loom-example

Repository files navigation

react-native-loom-example

This repo contains:

  • loom/: the Loom engine source tree (incl. the Welvet C-ABI bridge)
  • 0_75/: prebuilt Welvet (Loom C-ABI) mobile binaries for v0.75.x
    • 0_75/android_arm64/welvet.so (+ welvet.h)
    • 0_75/ios_arm64/welvet.a (+ welvet.h)
  • loom-expo/: an Expo + React Native demo app that runs a small Loom model on-device and stores events in SQLite

The goal is a realistic demo for a diabetes scenario:

“I took meds late, went out, and after walking around (e.g. Costco) my blood sugar can drop. It’d be great to have something that flags risk locally.”


What the app does

The app in loom-expo/ implements a simple “risk score” flow:

  • You enter:
    • Blood glucose (mg/dL)
    • Minutes since meds
    • Walking intensity (steps/min)
  • The app computes a risk score (0..1):
    • If Loom is available (dev client / built APK): it uses Loom/Welvet on-device
    • If Loom is not available (e.g. Expo Go): it uses a deterministic fallback heuristic
  • Each “check” is written to SQLite on-device via expo-sqlite
  • The Insights screen shows a simple trend chart using react-native-gifted-charts
  • A demo notification reminder can be scheduled via expo-notifications
  • A demo PIN is stored via expo-secure-store
  • A WebView screen demonstrates in-app web rendering

This is an example project and not medical advice. It’s structured as a foundation you can extend with real signals (CGM ingestion, step sensors, insulin-on-board estimation, personal baselines, etc.).

Demo screenshot

Loom Expo app screenshot


Tech stack (as implemented)

  • Expo (dev client) + React Native
  • TypeScript
  • expo-router (routes live under loom-expo/app)
  • expo-sqlite (local SQLite storage)
  • nativewind + tailwindcss (Tailwind-style className utilities)
  • react-native-gifted-charts + react-native-svg (charts)
  • expo-notifications (reminders)
  • expo-secure-store (secure key/value)
  • @react-native-community/datetimepicker (time picker in Settings)
  • react-native-webview (web screen)

Repo layout

App

  • loom-expo/app/
    • _layout.tsx: router layout + NativeWind CSS import
    • index.tsx: Dashboard (inputs + Train + Check now + Reminder)
    • insights.tsx: Insights (trend chart)
    • settings.tsx: Settings (SecureStore PIN + time picker)
    • web.tsx: WebView screen

Data layer

  • loom-expo/src/db/
    • client.ts: opens SQLite DB, creates schema
    • schema.ts: TypeScript row types
  • loom-expo/src/repositories/
    • EventRepository.ts: inserts and queries events
  • loom-expo/src/services/
    • RiskService.ts: computes risk + logs events
    • NotificationsService.ts: schedules a demo reminder
    • SecureStoreService.ts: demo PIN storage
    • analytics/AnalyticsService.ts: simple moving-average trend + anomaly note

Loom integration (on-device)

The Loom engine is integrated as a local React Native native module that bundles the prebuilt C-ABI binaries from 0_75/.

Where the native module lives

loom-expo/packages/loom-welvet/

Android

  • Kotlin native module:
    • packages/loom-welvet/android/src/main/java/com/openfluke/loomwelvet/LoomWelvetModule.kt
  • Bundled binary (arm64):
    • packages/loom-welvet/android/src/main/jniLibs/arm64-v8a/libwelvet.so
  • The Kotlin module uses JNA to call into the C-ABI and exposes:
    • createRiskModel()
    • trainRiskModel(handle)
    • predictRisk(handle, features)

iOS

  • ObjC++ native module:
    • packages/loom-welvet/ios/LoomWelvetModule.mm
  • Vendored library + header:
    • packages/loom-welvet/ios/Welvet/libwelvet.a
    • packages/loom-welvet/ios/Welvet/welvet.h
  • A podspec wires the vendored library/header:
    • packages/loom-welvet/loom-welvet.podspec

Important: Expo Go vs Dev Client

Because Loom is native code, you must use a dev client (or a built APK/IPA). Expo Go won’t include this module.

RiskService automatically falls back to a deterministic heuristic if NativeModules.LoomWelvet is not present.


How the “risk model” works (today)

This demo uses a very small Loom network:

  • A single dense layer: 3 inputs → 1 output
  • sigmoid activation → output is a probability-like risk score (0..1)
  • It is trained on-device using LoomTrain with a small hard-coded dataset that reflects:
    • lower BG → higher risk
    • longer time since meds → higher risk
    • higher walking intensity → higher risk

This is deliberately small so it’s easy to validate the end-to-end integration (native module → JS service → UI → SQLite → chart).


Running the app (development)

From loom-expo/:

npm install
npx expo start

To actually use Loom on-device you must build a dev client.

Android (Windows)

cd loom-expo
npx expo prebuild -p android
npx expo run:android

iOS (macOS)

cd loom-expo
npx expo prebuild -p ios
cd ios && pod install && cd ..
npx expo run:ios

Building + installing a debug APK (Windows)

Two helper scripts exist at the repo root:

  • build-apk-debug.bat: builds loom-expo/android/app/build/outputs/apk/debug/app-debug.apk
  • install-apk-debug.bat: installs the APK to the currently connected adb device/emulator

Usage from repo root:

build-apk-debug.bat
install-apk-debug.bat

Notes:

  • You need Android SDK + platform-tools (adb) on PATH.
  • The APK produced is debug and intended for development/testing.

Building + installing a standalone Release APK (Windows)

If you want the app to run without Metro / expo start, build a Release APK:

  • build-apk-release.bat: builds loom-expo\android\app\build\outputs\apk\release\app-release.apk
  • install-apk-release.bat: installs it to the preferred adb device (auto-picks 192.168.* if present)

Usage from repo root:

build-apk-release.bat
install-apk-release.bat

Notes:

  • This is still signed with the debug keystore (good for local testing, not Play Store).
  • Release builds are slower than Debug, but the app is standalone.

Files added/changed at the repo root

  • README.md (this file)
  • build-apk-debug.bat
  • install-apk-debug.bat
  • build-apk-release.bat
  • install-apk-release.bat

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

Contributors