Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 2.33 KB

File metadata and controls

81 lines (59 loc) · 2.33 KB

Integrating moon-firestore-sync-kmp

Firestore-backed adapter for the L1 RemoteStore SPI from moon-sync-kmp. Use it to observe Firestore collections as Kotlin Flows without any platform-specific glue in your feature code.

1. Prerequisites

  • Kotlin 2.0.20, Compose Multiplatform 1.7.x, AGP 8.6.x, Gradle 8.10, Java 21.
  • A Firebase project with Firestore enabled; security rules configured.
  • Valid moonLicenseKey.
  • Koin 4.1.0.

2. Add the repository + dependency

(Repository setup is identical to the auth module — see auth/en.md §2.)

composeApp/build.gradle.kts (commonMain):

implementation("io.moondeveloper:moon-firestore-sync-kmp:1.0.0")

3. Platform setup

Android

  • google-services.json present + Google Services plugin applied.
  • Firestore must be initialized by FirebaseApp (automatic in most setups).

iOS

  • GoogleService-Info.plist added to Xcode target.
  • FirebaseApp.configure() in AppDelegate.

4. Initialize Koin

import io.moondev.firestore.sync.firestoreSyncModule

startKoin {
    modules(firestoreSyncModule /*, ... */)
}

FirestoreRemoteStore is bound to the RemoteStore contract inside the module — your code only sees RemoteStore.

5. Use in a ViewModel / Store (MVI)

class NotesStore(private val store: RemoteStore) {
    val notes: Flow<List<Note>> = store.observeCollection("notes")
}

6. Compose UI binding

@Composable
fun NotesScreen(store: NotesStore = koinInject()) {
    val items by store.notes.collectAsState(initial = emptyList())
    LazyColumn { items(items) { n -> Text(n.title) } }
}

7. Common issues

  • Empty stream / PERMISSION_DENIED — Firestore rules rejecting the request. Verify the current user is signed in (pair with moon-firebase-auth-kmp) and the path matches your rules.
  • Default FirebaseApp is not initialized on iOS — you skipped FirebaseApp.configure() in AppDelegate.
  • Backpressure warnings in logs — the stream is hot; scope your subscription to a ViewModel or a Compose LaunchedEffect so it cancels on disposal.

8. Next steps