Skip to content

Commit 3365be2

Browse files
Use Callbacks in getAllUserAttribute API
1 parent 4471d3b commit 3365be2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.facebook.react.bridge.ReadableMap;
1111
import com.facebook.react.bridge.WritableArray;
1212
import com.facebook.react.bridge.WritableNativeArray;
13+
import com.facebook.react.bridge.WritableMap;
14+
import com.facebook.react.bridge.WritableNativeMap;
1315
import com.facebook.react.bridge.Callback;
1416

1517
import com.instabug.library.Instabug;
@@ -676,8 +678,17 @@ public void removeUserAttribute(String key) {
676678
* @return all user attributes as HashMap<String, String>
677679
*/
678680
@ReactMethod
679-
public HashMap<String, String> getAllUserAttributes() {
680-
return mInstabug.getAllUserAttributes();
681+
public void getAllUserAttributes(Callback userAttributesCallback) {
682+
WritableMap writableMap = new WritableNativeMap();
683+
try {
684+
HashMap<String, String> map = mInstabug.getAllUserAttributes();
685+
for (HashMap.Entry<String, String> entry : map.entrySet()) {
686+
writableMap.putString(entry.getKey(), entry.getValue());
687+
}
688+
} catch (Exception e) {
689+
e.printStackTrace();
690+
}
691+
userAttributesCallback.invoke(writableMap);
681692
}
682693

683694
/**

index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,7 @@ module.exports = {
631631
* or an empty dictionary if no user attributes have been set.
632632
*/
633633
getAllUserAttributes: function (userAttributesCallback) {
634-
if (Platform.OS === 'ios') {
635-
return Instabug.getAllUserAttributes(userAttributesCallback);
636-
} else if (Platform.OS === 'android') {
637-
return Instabug.getAllUserAttributes();
638-
}
634+
Instabug.getAllUserAttributes(userAttributesCallback);
639635
},
640636

641637
/**

0 commit comments

Comments
 (0)