mirror of
https://github.com/status-im/react-native-firebase.git
synced 2026-09-02 07:01:14 +00:00
[auth] Pass previousChildName back to callback
This commit is contained in:
+11
-6
@@ -3,6 +3,8 @@ package io.invertase.firebase.database;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -50,28 +52,28 @@ public class RNFirebaseDatabaseReference {
|
||||
@Override
|
||||
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
|
||||
if ("child_added".equals(eventName)) {
|
||||
handleDatabaseEvent("child_added", listenerId, dataSnapshot);
|
||||
handleDatabaseEvent("child_added", listenerId, dataSnapshot, previousChildName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
|
||||
if ("child_changed".equals(eventName)) {
|
||||
handleDatabaseEvent("child_changed", listenerId, dataSnapshot);
|
||||
handleDatabaseEvent("child_changed", listenerId, dataSnapshot, previousChildName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildRemoved(DataSnapshot dataSnapshot) {
|
||||
if ("child_removed".equals(eventName)) {
|
||||
handleDatabaseEvent("child_removed", listenerId, dataSnapshot);
|
||||
handleDatabaseEvent("child_removed", listenerId, dataSnapshot, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
|
||||
if ("child_moved".equals(eventName)) {
|
||||
handleDatabaseEvent("child_moved", listenerId, dataSnapshot);
|
||||
handleDatabaseEvent("child_moved", listenerId, dataSnapshot, previousChildName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +96,7 @@ public class RNFirebaseDatabaseReference {
|
||||
ValueEventListener valueEventListener = new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
handleDatabaseEvent("value", listenerId, dataSnapshot);
|
||||
handleDatabaseEvent("value", listenerId, dataSnapshot, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -166,11 +168,14 @@ public class RNFirebaseDatabaseReference {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDatabaseEvent(final String name, final Integer listenerId, final DataSnapshot dataSnapshot) {
|
||||
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 evt = Arguments.createMap();
|
||||
evt.putString("eventName", name);
|
||||
evt.putMap("body", data);
|
||||
if (previousChildName != null) {
|
||||
evt.putString("previousChildName", previousChildName);
|
||||
}
|
||||
|
||||
Utils.sendEvent(mReactContext, "database_event", evt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user