All Projects → GitLiveApp → Firebase Kotlin Sdk

GitLiveApp / Firebase Kotlin Sdk

Licence: apache-2.0
A Kotlin-first SDK for Firebase

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Firebase Kotlin Sdk

Internalappstore
📦 Manage your own internal Android App Store.
Stars: ✭ 295 (+37.85%)
Mutual labels:  firebase-functions, firebase, firebase-database, firebase-auth
Firebase Mock
Firebase mock library for writing unit tests
Stars: ✭ 319 (+49.07%)
Mutual labels:  firebase-functions, firebase, firebase-database, firebase-auth
Rxfirebase
Rxjava 2.0 wrapper on Google's Android Firebase library.
Stars: ✭ 509 (+137.85%)
Mutual labels:  firebase-functions, firebase, firebase-database, firebase-auth
Petshop
Pet Shop is an e-commerce application for Android built with Flutter (iOS to come soon).
Stars: ✭ 127 (-40.65%)
Mutual labels:  firebase, firebase-database, firebase-auth
Firebasecrud
Rich UI and animation flutter app backed by firebase
Stars: ✭ 121 (-43.46%)
Mutual labels:  firebase, firebase-database, firebase-auth
Firebase Android Sdk
Firebase Android SDK
Stars: ✭ 1,704 (+696.26%)
Mutual labels:  firebase-functions, firebase, firebase-database
React Firebase Authentication
🔥 Boilerplate Project for Authentication with Firebase in React.
Stars: ✭ 863 (+303.27%)
Mutual labels:  firebase, firebase-database, firebase-auth
React Firebase Hooks
React Hooks for Firebase.
Stars: ✭ 2,227 (+940.65%)
Mutual labels:  firebase, firebase-database, firebase-auth
Firebase As3
Integrate Firebase Auth, Realtime Database and Storage in your Adobe AIR projects.
Stars: ✭ 55 (-74.3%)
Mutual labels:  firebase, firebase-database, firebase-auth
Space
A real time chat app for developers built using React, Redux, Electron and Firebase
Stars: ✭ 161 (-24.77%)
Mutual labels:  firebase, firebase-database, firebase-auth
Nextjs Redux Firebase Authentication
Boilerplate Project for Authentication with Firebase in NextJs and Redux
Stars: ✭ 90 (-57.94%)
Mutual labels:  firebase, firebase-database, firebase-auth
Angular 4 Material Pos
POS written in Angular 4 with Angular Material UI
Stars: ✭ 54 (-74.77%)
Mutual labels:  firebase, firebase-database, firebase-auth
Firebase Admin Node
Firebase Admin Node.js SDK
Stars: ✭ 1,050 (+390.65%)
Mutual labels:  firebase, firebase-database, firebase-auth
Quickstart Cpp
Firebase Quickstart Samples for C++
Stars: ✭ 123 (-42.52%)
Mutual labels:  firebase, firebase-database, firebase-auth
Virapro.ru
[E-commerce] Plumbing Store
Stars: ✭ 45 (-78.97%)
Mutual labels:  firebase-functions, firebase, firebase-auth
Firebaserealtimechat
Sample real-time chat application using Firebase
Stars: ✭ 60 (-71.96%)
Mutual labels:  firebase, firebase-database, firebase-auth
The Road To React With Firebase
📓The Road to React with Firebase: Your journey to build business applications with React and Firebase.
Stars: ✭ 82 (-61.68%)
Mutual labels:  firebase, firebase-database, firebase-auth
React Firebase
🔥Declarative React bindings for Firebase Auth & Realtime Database.
Stars: ✭ 176 (-17.76%)
Mutual labels:  firebase, firebase-database, firebase-auth
React Mobx Firebase Authentication
🔥Boilerplate Project for Authentication with Firebase in React and MobX
Stars: ✭ 111 (-48.13%)
Mutual labels:  firebase, firebase-database, firebase-auth
Chatapp
Chat App with all functionality private chat, contacts, friends request, find friends,for profile settings image cropper functionality, settings, logout also send text, image and all type of files, delete your files for you and everyone , login with email and mobile number and real time database firebase and for notification purpose Node Js used.
Stars: ✭ 25 (-88.32%)
Mutual labels:  firebase-functions, firebase, firebase-database

Firebase Kotlin SDK GitHub last commit

Built and maintained with 🧡 by GitLive
Real-time code collaboration inside any IDE


The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the [Firebase Android SDK Kotlin Extensions](https://firebase.github.io/firebase-android-sdk/reference/kotlin/firebase-ktx/) but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting *iOS*, *Android* or *JS*.

Available libraries

The following libraries are available for the various Firebase products.

Service or Product Gradle Dependency API Coverage
Authentication dev.gitlive:firebase-auth:1.2.0 80%
Realtime Database dev.gitlive:firebase-database:1.2.0 70%
Cloud Firestore dev.gitlive:firebase-firestore:1.2.0 60%
Cloud Functions dev.gitlive:firebase-functions:1.2.0 80%
Cloud Messaging dev.gitlive:firebase-messaging:1.2.0 0%
Cloud Storage dev.gitlive:firebase-storage:1.2.0 0%

Is the Firebase library or API you need missing? Create an issue to request additional API coverage or be awesome and submit a PR

Kotlin-first design

Unlike the Kotlin Extensions for the Firebase Android SDK this project does not extend a Java based SDK so we get the full power of Kotlin including coroutines and serialization!

Suspending functions

Asynchronous operations that return a single or no value are represented by suspending functions in the SDK instead of callbacks, listeners or OS specific types such as Task, for example:

suspend fun signInWithCustomToken(token: String): AuthResult

It is important to remember that unlike a callback based API, wating for suspending functions to complete is implicit and so if you don't want to wait for the result you can launch a new coroutine:

//TODO don't use GlobalScope
GlobalScope.launch {
  Firebase.auth.signOut()
}

Flows

Asynchronous streams of values are represented by Flows in the SDK instead of repeatedly invoked callbacks or listeners, for example:

val snapshots: Flow<DocumentSnapshot>

The flows are cold, which means a new listener is added every time a terminal operator is applied to the resulting flow. A buffer with the default size is used to buffer values received from the listener, use the buffer operator on the flow to specify a user-defined value and to control what happens when data is produced faster than consumed, i.e. to control the back-pressure behavior. Often you are only interested in the latest value received, in this case you can use the conflate operator to disable buffering.

The listener is removed once the flow completes or is cancelled.

Serialization

The official Firebase SDKs use different platform-specific ways to support writing data with and without custom classes in Cloud Firestore, Realtime Database and Functions.

The Firebase Kotlin SDK uses Kotlin serialization to read and write custom classes to Firebase. To use Kotlin serialization in your project add the plugin to your gradle file:

plugins {
    kotlin("multiplatform") // or kotlin("jvm") or any other kotlin plugin
    kotlin("plugin.serialization") version "1.4.10"
}

Then mark you custom classes @Serializable:

@Serializable
data class City(val name: String)

Instances of these classes can now be passed along with their serializer to the SDK:

db.collection("cities").document("LA").set(City.serializer(), city, encodeDefaults = true)

The encodeDefaults parameter is optional and defaults to true, set this to false to omit writing optional properties if they are equal to theirs default values.

You can also omit the serializer but this is discouraged due to a current limitation on Kotlin/JS and Kotlin/Native

Server Timestamp

Firestore and the Realtime Database provide a sentinel value you can use to set a field in your document to a server timestamp. So you can use these values in custom classes they are of type Double:

@Serializable
data class Post(val timestamp: Double = ServerValue.TIMESTAMP)

Default arguments

To reduce boilerplate, default arguments are used in the places where the Firebase Android SDK employs the builder pattern:

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
        .setDisplayName("Jane Q. User")
        .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
        .build();

user.updateProfile(profileUpdates)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "User profile updated.");
                }
            }
        });

//...becomes...

user.updateProfile(displayName = "state", photoURL = "CA")

Named arguments

To improve readability functions such as the Cloud Firestore query operators use named arguments:

citiesRef.whereEqualTo("state", "CA")
citiesRef.whereArrayContains("regions", "west_coast")

//...becomes...

citiesRef.where("state", equalTo = "CA")
citiesRef.where("regions", arrayContains = "west_coast")

Operator overloading

In cases where it makes sense, such as Firebase Functions HTTPS Callable, operator overloading is used:

    val addMessage = functions.getHttpsCallable("addMessage")
    //In the official android Firebase SDK this would be addMessage.call(...)
    addMessage(mapOf("text" to text, "push" to true))

Multiplatform

The Firebase Kotlin SDK provides a common API to access Firebase for projects targeting iOS, Android and JS meaning you can use Firebase directly in your common code. Under the hood, the SDK achieves this by binding to the respective official Firebase SDK for each supported platform.

Accessing the underlying Firebase SDK

In some cases you might want to access the underlying official Firebase SDK in platform specific code, for example when the common API is missing the functionality you need. For this purpose each class in the SDK has android, ios and js properties which holds the equivalent object of the underlying official Firebase SDK.

These properties are only accessible from the equivalent target's source set. For example to disable persistence in Cloud Firestore on Android you can write the following in your Android specific code (e.g. androidMain or androidTest):

  Firebase.firestore.android.firestoreSettings = FirebaseFirestoreSettings.Builder(Firebase.firestore.android.firestoreSettings)
          .setPersistenceEnabled(false)
          .build()

NPM modules

If you are building a Kotlin multiplatform library which will be consumed from JS code you may need to include the SDK in your package.json, you can do it as follows:

"dependencies": {
  "@gitlive/firebase-auth": "1.2.0",
  "@gitlive/firebase-database": "1.2.0",
  "@gitlive/firebase-firestore": "1.2.0",
  "@gitlive/firebase-functions": "1.2.0",
  "@gitlive/firebase-storage": "1.2.0",
  "@gitlive/firebase-messaging": "1.2.0"
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].