diff --git a/android/src/main/java/io/invertase/firebase/Utils.java b/android/src/main/java/io/invertase/firebase/Utils.java index 55cbb64b..96287961 100644 --- a/android/src/main/java/io/invertase/firebase/Utils.java +++ b/android/src/main/java/io/invertase/firebase/Utils.java @@ -1,5 +1,6 @@ package io.invertase.firebase; +import android.support.annotation.Nullable; import android.util.Log; import java.util.ArrayList; @@ -84,7 +85,7 @@ public class Utils { * @param dataSnapshot * @return */ - public static WritableMap snapshotToMap(String name, int refId, Integer listenerId, String path, DataSnapshot dataSnapshot) { + public static WritableMap snapshotToMap(String name, int refId, Integer listenerId, String path, DataSnapshot dataSnapshot, @Nullable String previousChildName) { WritableMap snapshot = Arguments.createMap(); WritableMap eventMap = Arguments.createMap(); @@ -114,6 +115,7 @@ public class Utils { eventMap.putString("path", path); eventMap.putMap("snapshot", snapshot); eventMap.putString("eventName", name); + eventMap.putString("previousChildName", previousChildName); return eventMap; } diff --git a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java index 5e053b02..182219f9 100644 --- a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java +++ b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabaseReference.java @@ -117,7 +117,7 @@ public class RNFirebaseDatabaseReference { final ValueEventListener onceValueEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { - WritableMap data = Utils.snapshotToMap("value", mRefId, null, mPath, dataSnapshot); + WritableMap data = Utils.snapshotToMap("value", mRefId, null, mPath, dataSnapshot, null); callback.invoke(null, data); } @@ -169,13 +169,10 @@ public class RNFirebaseDatabaseReference { } private void handleDatabaseEvent(final String name, final Integer listenerId, final DataSnapshot dataSnapshot, @Nullable String previousChildName) { - WritableMap data = Utils.snapshotToMap(name, mRefId, listenerId, mPath, dataSnapshot); + WritableMap data = Utils.snapshotToMap(name, mRefId, listenerId, mPath, dataSnapshot, previousChildName); WritableMap evt = Arguments.createMap(); evt.putString("eventName", name); evt.putMap("body", data); - if (previousChildName != null) { - evt.putString("previousChildName", previousChildName); - } Utils.sendEvent(mReactContext, "database_event", evt); }