ConnectivityKMP

Enables checking network connectivity status with a Compose-first API, offering real-time updates across Android, iOS, JVM/Desktop, and Web platforms. Lightweight and dependency-free.

Android JVMJVMKotlin/NativeWasm
GitHub stars12
Open issues0
LicenseMIT License
Creation date6 months ago

Last activity6 months ago
Latest release0.0.2 (6 months ago)

Maven Central GitHub License GitHub Issues GitHub Pull Requests GitHub Last Commit GitHub Stars

Supported Platforms Supported Platforms Supported Platforms Supported Platforms

πŸ“‘ ConnectivityKMP

ConnectivityKMP is a Kotlin Multiplatform library that provides a unified way to check network connectivity status across platforms with a Compose-first API.

It supports:

  • βœ… Android
  • βœ… iOS
  • βœ… JVM/Desktop
  • βœ… Web (Wasm/JS)

✨ Features

  • πŸ“± Android – Uses ConnectivityManager callbacks to detect real-time connectivity changes.
  • 🍏 iOS – Uses Apple’s nw_path_monitor for monitoring connectivity.
  • πŸ’» JVM/Desktop – Fallback mechanism via socket reachability checks.
  • 🌐 Web (Wasm/JS) – Detects online/offline using browser events (navigator.onLine).
  • 🧩 Composable API – Exposes a simple rememberNetworkStatus() you can use anywhere in Compose.
  • ⚑ Lightweight and dependency-free.

πŸš€ Getting Started

Add the dependency from Maven Central:

kotlin {
    sourceSets {
        commonMain.dependencies {
           implementation("io.github.khubaibkhan4:connectivity-kmp:0.0.2")
        }
    }
}
@Composable
fun App() {

   // get the Network Status
   val isNetworkAvailable by rememberNetworkStatus()
   
   // Network Status
   // NetworkStatus.Available, NetworkStatus.NoInternet, NetworkStatus.Lost, NetworkStatus.Unavailable, NetworkStatus.Slow


   Box(
      modifier = Modifier.fillMaxSize().background(Color.White),
      contentAlignment = Alignment.Center
   ) {
      if (isNetworkAvailable == NetworkStatus.Available){
         BasicText("Connected")
      } else {
         BasicText("Disconnected")
      }
   }
}

iOS

Image

Android

https://github.com/user-attachments/assets/a5a2251a-6ebe-422d-a928-4c216bb01269

Desktop & WasmJs

https://github.com/user-attachments/assets/5aa984cf-93bf-4a86-b362-f511f3c19a04

Run Sample App

  • Desktop JVM: ./gradlew :sample:composeApp:run
  • Android: open project in Android Studio and run the sample app
  • iOS: open 'sample/iosApp/iosApp.xcodeproj' in Xcode and run the sample app
  • Wasm: ./gradlew :sample:composeApp:wasmJsBrowserRun

Publish to MavenLocal

  1. Run ./gradlew :shared:publishToMavenLocal
  2. Open ~/.m2/repository/my/connectivity/kmp/

Publish to MavenCentral

  1. Create an account and a namespace on Sonatype:
    https://central.sonatype.org/register/central-portal/#create-an-account
  2. Add developer id, name, email and the project url to
    ./shared/build.gradle.kts
  3. Generate a GPG key:
    https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/#generating-a-gpg-key-pair
    gpg --full-gen-key
    gpg --keyserver keyserver.ubuntu.com --send-keys XXXXXXXX
    gpg --export-secret-key XXXXXXXX > XXXXXXXX.gpg
    
  4. Add these lines to gradle.properties:
    signing.keyId=XXXXXXXX
    signing.password=[key password]
    signing.secretKeyRingFile=../XXXXXXXX.gpg
    mavenCentralUsername=[generated username]
    mavenCentralPassword=[generated password]
    
  5. Run ./gradlew :shared:publishAndReleaseToMavenCentral --no-configuration-cache
Android JVMJVMKotlin/NativeWasm
GitHub stars12
Open issues0
LicenseMIT License
Creation date6 months ago

Last activity6 months ago
Latest release0.0.2 (6 months ago)

Maven Central GitHub License GitHub Issues GitHub Pull Requests GitHub Last Commit GitHub Stars

Supported Platforms Supported Platforms Supported Platforms Supported Platforms

πŸ“‘ ConnectivityKMP

ConnectivityKMP is a Kotlin Multiplatform library that provides a unified way to check network connectivity status across platforms with a Compose-first API.

It supports:

  • βœ… Android
  • βœ… iOS
  • βœ… JVM/Desktop
  • βœ… Web (Wasm/JS)

✨ Features

  • πŸ“± Android – Uses ConnectivityManager callbacks to detect real-time connectivity changes.
  • 🍏 iOS – Uses Apple’s nw_path_monitor for monitoring connectivity.
  • πŸ’» JVM/Desktop – Fallback mechanism via socket reachability checks.
  • 🌐 Web (Wasm/JS) – Detects online/offline using browser events (navigator.onLine).
  • 🧩 Composable API – Exposes a simple rememberNetworkStatus() you can use anywhere in Compose.
  • ⚑ Lightweight and dependency-free.

πŸš€ Getting Started

Add the dependency from Maven Central:

kotlin {
    sourceSets {
        commonMain.dependencies {
           implementation("io.github.khubaibkhan4:connectivity-kmp:0.0.2")
        }
    }
}
@Composable
fun App() {

   // get the Network Status
   val isNetworkAvailable by rememberNetworkStatus()
   
   // Network Status
   // NetworkStatus.Available, NetworkStatus.NoInternet, NetworkStatus.Lost, NetworkStatus.Unavailable, NetworkStatus.Slow


   Box(
      modifier = Modifier.fillMaxSize().background(Color.White),
      contentAlignment = Alignment.Center
   ) {
      if (isNetworkAvailable == NetworkStatus.Available){
         BasicText("Connected")
      } else {
         BasicText("Disconnected")
      }
   }
}

iOS

Image

Android

https://github.com/user-attachments/assets/a5a2251a-6ebe-422d-a928-4c216bb01269

Desktop & WasmJs

https://github.com/user-attachments/assets/5aa984cf-93bf-4a86-b362-f511f3c19a04

Run Sample App

  • Desktop JVM: ./gradlew :sample:composeApp:run
  • Android: open project in Android Studio and run the sample app
  • iOS: open 'sample/iosApp/iosApp.xcodeproj' in Xcode and run the sample app
  • Wasm: ./gradlew :sample:composeApp:wasmJsBrowserRun

Publish to MavenLocal

  1. Run ./gradlew :shared:publishToMavenLocal
  2. Open ~/.m2/repository/my/connectivity/kmp/

Publish to MavenCentral

  1. Create an account and a namespace on Sonatype:
    https://central.sonatype.org/register/central-portal/#create-an-account
  2. Add developer id, name, email and the project url to
    ./shared/build.gradle.kts
  3. Generate a GPG key:
    https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/#generating-a-gpg-key-pair
    gpg --full-gen-key
    gpg --keyserver keyserver.ubuntu.com --send-keys XXXXXXXX
    gpg --export-secret-key XXXXXXXX > XXXXXXXX.gpg
    
  4. Add these lines to gradle.properties:
    signing.keyId=XXXXXXXX
    signing.password=[key password]
    signing.secretKeyRingFile=../XXXXXXXX.gpg
    mavenCentralUsername=[generated username]
    mavenCentralPassword=[generated password]
    
  5. Run ./gradlew :shared:publishAndReleaseToMavenCentral --no-configuration-cache