From 3365be2ef926dd697273611d7ca8da2df9c8f506 Mon Sep 17 00:00:00 2001 From: DevHossamHassan Date: Wed, 21 Jun 2017 05:42:50 +0200 Subject: [PATCH] Use Callbacks in `getAllUserAttribute` API --- .../reactlibrary/RNInstabugReactnativeModule.java | 15 +++++++++++++-- index.js | 6 +----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index f1c53ca..cf08bc4 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -10,6 +10,8 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableNativeArray; +import com.facebook.react.bridge.WritableMap; +import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.Callback; import com.instabug.library.Instabug; @@ -676,8 +678,17 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule { * @return all user attributes as HashMap */ @ReactMethod - public HashMap getAllUserAttributes() { - return mInstabug.getAllUserAttributes(); + public void getAllUserAttributes(Callback userAttributesCallback) { + WritableMap writableMap = new WritableNativeMap(); + try { + HashMap map = mInstabug.getAllUserAttributes(); + for (HashMap.Entry entry : map.entrySet()) { + writableMap.putString(entry.getKey(), entry.getValue()); + } + } catch (Exception e) { + e.printStackTrace(); + } + userAttributesCallback.invoke(writableMap); } /** diff --git a/index.js b/index.js index 754e98a..023b10d 100644 --- a/index.js +++ b/index.js @@ -631,11 +631,7 @@ module.exports = { * or an empty dictionary if no user attributes have been set. */ getAllUserAttributes: function (userAttributesCallback) { - if (Platform.OS === 'ios') { - return Instabug.getAllUserAttributes(userAttributesCallback); - } else if (Platform.OS === 'android') { - return Instabug.getAllUserAttributes(); - } + Instabug.getAllUserAttributes(userAttributesCallback); }, /**