[android][database] Pass previousChildName to snapshotToMap

This commit is contained in:
Elliot Hesp 2017-06-16 09:31:58 +01:00
parent d031d332e3
commit 663bf3c65f
2 changed files with 5 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package io.invertase.firebase; package io.invertase.firebase;
import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
@ -84,7 +85,7 @@ public class Utils {
* @param dataSnapshot * @param dataSnapshot
* @return * @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 snapshot = Arguments.createMap();
WritableMap eventMap = Arguments.createMap(); WritableMap eventMap = Arguments.createMap();
@ -114,6 +115,7 @@ public class Utils {
eventMap.putString("path", path); eventMap.putString("path", path);
eventMap.putMap("snapshot", snapshot); eventMap.putMap("snapshot", snapshot);
eventMap.putString("eventName", name); eventMap.putString("eventName", name);
eventMap.putString("previousChildName", previousChildName);
return eventMap; return eventMap;
} }

View File

@ -117,7 +117,7 @@ public class RNFirebaseDatabaseReference {
final ValueEventListener onceValueEventListener = new ValueEventListener() { final ValueEventListener onceValueEventListener = new ValueEventListener() {
@Override @Override
public void onDataChange(DataSnapshot dataSnapshot) { 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); 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) { 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(); WritableMap evt = Arguments.createMap();
evt.putString("eventName", name); evt.putString("eventName", name);
evt.putMap("body", data); evt.putMap("body", data);
if (previousChildName != null) {
evt.putString("previousChildName", previousChildName);
}
Utils.sendEvent(mReactContext, "database_event", evt); Utils.sendEvent(mReactContext, "database_event", evt);
} }