Skip to content
Permalink
Browse files

[firestore] update sdks and implement FieldValue.increment & Timestam…

…p support

[skip ci]
  • Loading branch information...
Salakar committed Apr 6, 2019
1 parent 85dc8cc commit b84473f776314dcaad61f0f837f256b6e5feffd0
@@ -143,8 +143,8 @@ dependencies {

// Required dependencies
//noinspection GradleCompatible
compileOnly "com.google.firebase:firebase-core:16.0.6"
compileOnly "com.google.android.gms:play-services-base:16.0.1"
compileOnly "com.google.firebase:firebase-core:16.0.8"
compileOnly "com.google.android.gms:play-services-base:16.1.0"

/* -------------------------
* OPTIONAL FIREBASE SDKS
@@ -157,27 +157,27 @@ dependencies {
exclude group: 'com.android.support', module: 'customtabs'
}
// Authentication
compileOnly "com.google.firebase:firebase-auth:16.1.0"
compileOnly "com.google.firebase:firebase-auth:16.2.0"
// Analytics
compileOnly "com.google.firebase:firebase-analytics:16.0.6"
compileOnly "com.google.firebase:firebase-analytics:16.4.0"
// Performance Monitoring
compileOnly "com.google.firebase:firebase-perf:16.2.3"
compileOnly "com.google.firebase:firebase-perf:16.2.4"
// Remote Config
compileOnly "com.google.firebase:firebase-config:16.1.2"
compileOnly "com.google.firebase:firebase-config:16.4.1"
// Cloud Storage
compileOnly "com.google.firebase:firebase-storage:16.0.5"
compileOnly "com.google.firebase:firebase-storage:16.1.0"
// Invites
compileOnly "com.google.firebase:firebase-invites:16.0.6"
compileOnly "com.google.firebase:firebase-invites:16.1.1"
// Dynamic Links
compileOnly "com.google.firebase:firebase-dynamic-links:16.1.5"
compileOnly "com.google.firebase:firebase-dynamic-links:16.1.8"
// Real-time Database
compileOnly "com.google.firebase:firebase-database:16.0.5"
compileOnly "com.google.firebase:firebase-database:16.1.0"
// Cloud Functions
compileOnly "com.google.firebase:firebase-functions:16.1.3"
compileOnly "com.google.firebase:firebase-functions:16.3.0"
// Cloud Firestore
compileOnly "com.google.firebase:firebase-firestore:17.1.5"
compileOnly "com.google.firebase:firebase-firestore:18.2.0"
// Cloud Messaging / FCM
compileOnly "com.google.firebase:firebase-messaging:17.3.4"
compileOnly "com.google.firebase:firebase-messaging:17.5.0"
// Crashlytics
compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true
@@ -9,6 +9,7 @@
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.google.firebase.Timestamp;
import com.google.firebase.firestore.Blob;
import com.google.firebase.firestore.DocumentChange;
import com.google.firebase.firestore.DocumentReference;
@@ -41,6 +42,8 @@
private static final String KEY_META = "metadata";
private static final String KEY_CHANGES = "changes";
private static final String KEY_OPTIONS = "options";
private static final String KEY_SECONDS = "seconds";
private static final String KEY_NANOSECONDS = "nanoseconds";
private static final String KEY_LATITUDE = "latitude";
private static final String KEY_LONGITUDE = "longitude";
private static final String KEY_DOCUMENTS = "documents";
@@ -62,12 +65,14 @@
private static final String TYPE_OBJECT = "object";
private static final String TYPE_BOOLEAN = "boolean";
private static final String TYPE_GEOPOINT = "geopoint";
private static final String TYPE_TIMESTAMP = "timestamp";
private static final String TYPE_INFINITY = "infinity";
private static final String TYPE_REFERENCE = "reference";
private static final String TYPE_DOCUMENTID = "documentid";
private static final String TYPE_FIELDVALUE = "fieldvalue";
private static final String TYPE_FIELDVALUE_DELETE = "delete";
private static final String TYPE_FIELDVALUE_TIMESTAMP = "timestamp";
private static final String TYPE_FIELDVALUE_INCREMENT = "increment";
private static final String TYPE_FIELDVALUE_UNION = "union";
private static final String TYPE_FIELDVALUE_REMOVE = "remove";
private static final String TYPE_FIELDVALUE_TYPE = "type";
@@ -95,8 +100,9 @@ static WritableMap snapshotToWritableMap(DocumentSnapshot documentSnapshot) {

documentMap.putMap(KEY_META, metadata);
documentMap.putString(KEY_PATH, documentSnapshot.getReference().getPath());
if (documentSnapshot.exists())
if (documentSnapshot.exists()) {
documentMap.putMap(KEY_DATA, objectMapToWritable(documentSnapshot.getData()));
}

return documentMap;
}
@@ -311,6 +317,18 @@ private static WritableMap buildTypeMap(Object value) {
return typeMap;
}


if (value instanceof Timestamp) {
WritableMap timestampMap = Arguments.createMap();

timestampMap.putDouble(KEY_SECONDS, ((Timestamp) value).getSeconds());
timestampMap.putInt(KEY_NANOSECONDS, ((Timestamp) value).getNanoseconds());

typeMap.putString(TYPE, TYPE_TIMESTAMP);
typeMap.putMap(VALUE, timestampMap);
return typeMap;
}

if (value instanceof GeoPoint) {
WritableMap geoPoint = Arguments.createMap();

@@ -449,6 +467,15 @@ static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
return firestore.document(path);
}

if (TYPE_TIMESTAMP.equals(type)) {
ReadableMap timestampMap = typeMap.getMap(VALUE);

return new Timestamp(
(long) timestampMap.getDouble(KEY_SECONDS),
timestampMap.getInt(KEY_NANOSECONDS)
);
}

if (TYPE_FIELDVALUE.equals(type)) {
ReadableMap fieldValueMap = typeMap.getMap(VALUE);
String fieldValueType = fieldValueMap.getString(TYPE_FIELDVALUE_TYPE);
@@ -457,6 +484,10 @@ static Object parseTypeMap(FirebaseFirestore firestore, ReadableMap typeMap) {
return FieldValue.serverTimestamp();
}

if (TYPE_FIELDVALUE_INCREMENT.equals(fieldValueType)) {
return FieldValue.increment(fieldValueMap.getDouble(TYPE_FIELDVALUE_ELEMENTS));
}

if (TYPE_FIELDVALUE_DELETE.equals(fieldValueType)) {
return FieldValue.delete();
}
@@ -456,9 +456,9 @@ public void settings(String appName, ReadableMap settings, final Promise promise
.isSslEnabled());
}

// if (settings.hasKey("timestampsInSnapshots")) {
// // TODO: Not supported on Android yet
// }
if (settings.hasKey("timestampsInSnapshots")) {
firestoreSettings.setTimestampsInSnapshotsEnabled(settings.getBoolean("timestampsInSnapshots"));
}

firestore.setFirestoreSettings(firestoreSettings.build());
promise.resolve(null);
@@ -26,7 +26,6 @@

import io.invertase.firebase.Utils;


public class RNFirebaseFirestoreDocumentReference {
private static final String TAG = "RNFBFSDocumentReference";
private static Map<String, ListenerRegistration> documentSnapshotListeners = new HashMap<>();
@@ -384,8 +384,7 @@ - (id)init {
firestoreSettings.sslEnabled = firestore.settings.sslEnabled;
}
if (settings[@"timestampsInSnapshots"]) {
// TODO: Enable when available on Android
// firestoreSettings.timestampsInSnapshotsEnabled = settings[@"timestampsInSnapshots"];
firestoreSettings.timestampsInSnapshotsEnabled = settings[@"timestampsInSnapshots"];
}

[firestore setSettings:firestoreSettings];

0 comments on commit b84473f

Please sign in to comment.
You can’t perform that action at this time.