Use Callbacks in getUnReadMessageAPI

This commit is contained in:
DevHossamHassan 2017-06-21 03:53:28 +02:00
parent 3148a9b529
commit 1365d040ca
3 changed files with 14 additions and 16 deletions

View File

@ -3,8 +3,7 @@
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import React, {Component} from "react";
import {
AppRegistry,
StyleSheet,
@ -17,10 +16,9 @@ import {
Image,
ListView,
TouchableHighlight,
RecyclerViewBackedScrollView,
} from 'react-native';
import Instabug from'instabug-reactnative';
RecyclerViewBackedScrollView
} from "react-native";
import Instabug from "instabug-reactnative";
let DialogAndroid = require('react-native-dialogs');
export default class InstabugSample extends Component {
@ -77,8 +75,11 @@ export default class InstabugSample extends Component {
} else if (rowID == 3) {
Instabug.showIntroMessage();
} else if (rowID == 4) {
Alert.alert("UnReadMessages", "Messages: " +
Instabug.getUnreadMessagesCount());
Instabug.getUnreadMessagesCount((count) => {
Alert.alert("UnReadMessages", "Messages: " + count);
});
} else if (rowID == 5) {
this._showLocaleActionSheet();
} else if (rowID == 6) {

View File

@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.Callback;
import com.instabug.library.Instabug;
import com.instabug.library.internal.module.InstabugLocale;
@ -450,7 +451,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
* @return number of messages that are unread for this user
*/
@ReactMethod
public int getUnreadMessagesCount() {
public void getUnreadMessagesCount(Callback messageCountCallback) {
int unreadMessages = 0;
try {
unreadMessages = mInstabug.getUnreadMessagesCount();
@ -458,7 +459,7 @@ public class RNInstabugReactnativeModule extends ReactContextBaseJavaModule {
e.printStackTrace();
}
return unreadMessages;
messageCountCallback.invoke(unreadMessages);
}
/**

View File

@ -198,14 +198,10 @@ module.exports = {
* Use this method to get the number of unread messages the user
* has, then possibly notify them about it with your own UI.
* @param {messageCountCallback} messageCountCallback callback with argument
* Notifications count, or -1 incase the SDK has not been initialized.
* Notifications count, or -1 in case the SDK has not been initialized.
*/
getUnreadMessagesCount: function (messageCountCallback) {
if (Platform.OS === 'ios') {
Instabug.getUnreadMessagesCount(messageCountCallback);
} else if (Platform.OS === 'android') {
Instabug.getUnreadMessagesCount();
}
Instabug.getUnreadMessagesCount(messageCountCallback);
},
/**