Skip to content

Commit 1365d04

Browse files
Use Callbacks in getUnReadMessageAPI
1 parent 3148a9b commit 1365d04

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

InstabugSample/index.android.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* https://github.com/facebook/react-native
44
* @flow
55
*/
6-
7-
import React, {Component} from 'react';
6+
import React, {Component} from "react";
87
import {
98
AppRegistry,
109
StyleSheet,
@@ -17,10 +16,9 @@ import {
1716
Image,
1817
ListView,
1918
TouchableHighlight,
20-
RecyclerViewBackedScrollView,
21-
} from 'react-native';
22-
23-
import Instabug from'instabug-reactnative';
19+
RecyclerViewBackedScrollView
20+
} from "react-native";
21+
import Instabug from "instabug-reactnative";
2422
let DialogAndroid = require('react-native-dialogs');
2523

2624
export default class InstabugSample extends Component {
@@ -77,8 +75,11 @@ export default class InstabugSample extends Component {
7775
} else if (rowID == 3) {
7876
Instabug.showIntroMessage();
7977
} else if (rowID == 4) {
80-
Alert.alert("UnReadMessages", "Messages: " +
81-
Instabug.getUnreadMessagesCount());
78+
79+
Instabug.getUnreadMessagesCount((count) => {
80+
Alert.alert("UnReadMessages", "Messages: " + count);
81+
});
82+
8283
} else if (rowID == 5) {
8384
this._showLocaleActionSheet();
8485
} else if (rowID == 6) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.facebook.react.bridge.ReactMethod;
99
import com.facebook.react.bridge.ReadableArray;
1010
import com.facebook.react.bridge.ReadableMap;
11+
import com.facebook.react.bridge.Callback;
1112

1213
import com.instabug.library.Instabug;
1314
import com.instabug.library.internal.module.InstabugLocale;
@@ -450,15 +451,15 @@ public String getAppToken() {
450451
* @return number of messages that are unread for this user
451452
*/
452453
@ReactMethod
453-
public int getUnreadMessagesCount() {
454+
public void getUnreadMessagesCount(Callback messageCountCallback) {
454455
int unreadMessages = 0;
455456
try {
456457
unreadMessages = mInstabug.getUnreadMessagesCount();
457458
} catch (Exception e) {
458459
e.printStackTrace();
459460
}
460461

461-
return unreadMessages;
462+
messageCountCallback.invoke(unreadMessages);
462463
}
463464

464465
/**

index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,10 @@ module.exports = {
198198
* Use this method to get the number of unread messages the user
199199
* has, then possibly notify them about it with your own UI.
200200
* @param {messageCountCallback} messageCountCallback callback with argument
201-
* Notifications count, or -1 incase the SDK has not been initialized.
201+
* Notifications count, or -1 in case the SDK has not been initialized.
202202
*/
203203
getUnreadMessagesCount: function (messageCountCallback) {
204-
if (Platform.OS === 'ios') {
205-
Instabug.getUnreadMessagesCount(messageCountCallback);
206-
} else if (Platform.OS === 'android') {
207-
Instabug.getUnreadMessagesCount();
208-
}
204+
Instabug.getUnreadMessagesCount(messageCountCallback);
209205
},
210206

211207
/**

0 commit comments

Comments
 (0)