Android applications
Embedding Unifin Charts into Android apps through a WebView - what works today and what the roadmap adds.
This page covers embedding the library into an Android app through a WebView: the page setup, the JavaScript bridge, a verified harness and the limits to know about.
Unifin Charts is a browser library: it renders on a canvas through standard web APIs, so a WebView runs it exactly like a desktop browser. No SDK is required.
How embedding works today
- Ship the page (or a small bundle) with your app assets, or serve it from your backend.
- Load it in a
WebViewwith JavaScript and DOM storage enabled. - Size the WebView to the desired chart area; the renderer adapts to any container size.
val webView = WebView(context).apply {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.mediaPlaybackRequiresUserGesture = false
loadUrl("file:///android_asset/chart/index.html")
}<!-- android_asset/chart/index.html -->
<div id="app" style="height: 100vh"></div>
<script type="module" src="./chart.js"></script>Communication between the app and the chart uses the standard WebView bridge:
addJavascriptInterface towards the page and evaluateJavascript (or URL schemes) back to the app.
What to check on device
| Area | Recommendation |
|---|---|
| Touch | The element handles pointer input; verify pan, zoom and crosshair with the on-device gestures |
| Fonts | Bundle fonts next to the assets - remote font loading is blocked on some networks |
| Performance | System WebView versions vary; test frame timing on your oldest target device |
| Theme | Pass the app theme into the page and align tokens with your app palette |
| Offline | Keep data fetching in the app; feed bars into the page through the bridge |
Harness example
The repository ships a ready harness at examples/android-webview: an offline page (assets only,
no network), a tiny native bridge and a gradle sample that loads the page from
file:///android_asset/index.html.
| Piece | What it does |
|---|---|
src/bridge.mjs | window.UnifinHost.setBars(json), setTheme(dark|light), setSymbol(symbol, timeframe); page events unifin-ready and the onCrosshair hook |
src/app.ts | Mounts the element full screen, forwards wheel/pinch zoom, repaints on resize |
app/MainActivity.kt | WebView with JavaScript and DOM storage, addJavascriptInterface, deterministic demo series |
node build.mjs | Builds assets/app.js (single IIFE) and copies index.html next to it |
Verified in automation: the bridge protocol tests (node --test), and a touch-enabled browser
emulation that loads the built page, sends bars through the bridge, zooms with a wheel event and
checks the cursor hook.
Checked on a device, confirm the same items: touch pan and zoom feel, cursor readout, fonts bundled with the assets and frame timing on your oldest target WebView. The harness page stays offline by design: keep data fetching in the native layer or in your own page.
Limitations to know
- The
JavascriptInterfacebridge must only be exposed to the offline assets page; never enable it for pages that can navigate to the network. - Some Android builds restrict cookies (FedCM-era changes) - do not rely on cookie-based sessions inside the WebView; authenticate in the native layer and pass data through the bridge.
- Very old System WebView versions lack
CustomEvent; the harness falls back to theonUnifinBridgeEventhost hook.
Caution Keep the WebView on bundled assets. A page that can reach the network hands the JavaScript interface to remote code.
See also
- Getting started - the same page code in a browser.
- Custom element - attributes, methods and events the bridge calls.
- Editions - which entry point to bundle into the app assets.
Swaps kit API (@unifin/chart-kit-swaps)
Generated reference of 35 public symbols of @unifin/chart-kit-swaps, grouped by kind and ordered as in the sources.
iOS applications
Embedding Unifin Charts into iOS apps through a WKWebView - the page setup, the Swift host, the bridge protocol and the limits to know about.
