Skip to content

feat(android): WebView wrapper for Chativa (Kotlin / Jetpack Compose) #9

Description

@AimTune

Goal

Ship a Kotlin/Android library that embeds the Chativa Web Components widget inside an Android WebView, with a typed bridge so Kotlin/Java host apps can configure the widget, listen to events, and call into it — without a full native UI port.

Background

Same rationale as the iOS SwiftUI WebView wrapper: a WebView embed gives full feature parity with the web build (GenUI, themes, surveys, slash commands) and updates without a Play Store release. A native Compose UI port can come later if there's demand.

Scope

Create a new Gradle module published to Maven Central as com.chativa:chativa-android (or a dedicated repo).

  • Target minSdk 24, targetSdk current.
  • ChativaView (regular View) and ChativaComposable (Jetpack Compose wrapper). Both internally host a WebView.
  • Bundle a self-contained index.html from assets/ that imports @chativa/ui + connectors locally — no first-paint network call.
  • Typed Kotlin bridge via WebView.addJavascriptInterface(...) and evaluateJavascript(...):
    • Kotlin → web: configure(settings), sendMessage(...), setAuthToken(...), setLanguage(...).
    • Web → Kotlin: onMessage, onConnect, onDisconnect, onSurveySubmit, onLinkOpen (intercept anchor clicks → Intent.ACTION_VIEW or Custom Tabs).
  • Coroutines-friendly API: callbacks exposed as Flow<...> where it makes sense.
  • Token refresh hook for connectors that need re-auth.
  • File upload: route web <input type=file> through WebChromeClient.onShowFileChooser → native picker.
  • FCM push hook: expose a callback when a remote notification needs to surface inside the chat.
  • Handle back button: if the widget has a navigable internal state (e.g. survey screen), consume onBackPressed first.
  • JUnit + Espresso smoke tests.
  • Sample app module showing typical integration.

Acceptance

  • A fresh Android Studio project can declare the dependency and drop ChativaView into XML or ChativaComposable() into Compose, and have a working chat.
  • All Web Component events surface as Kotlin callbacks / Flows.
  • File upload, link clicks, and back navigation feel native, not web-y.

Open questions

  • Pure-Kotlin Compose UI port — large enough for its own issue if prioritised later.
  • Distribution: Maven Central vs JitPack — Maven Central is the right answer long-term, JitPack is the fast first-cut.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions