Skip to content

Commit 28fa878

Browse files
Add new API: Replies.showNotificationAndroid
1 parent d3bf8fc commit 28fa878

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
import com.facebook.react.bridge.ReactApplicationContext;
88
import com.facebook.react.bridge.ReactContextBaseJavaModule;
99
import com.facebook.react.bridge.ReactMethod;
10+
import com.facebook.react.bridge.ReadableMap;
11+
import com.facebook.react.bridge.ReadableType;
12+
import com.facebook.react.bridge.ReadableMapKeySetIterator;
1013
import com.instabug.chat.Replies;
1114
import com.instabug.library.Feature;
1215
import com.instabug.reactlibrary.utils.InstabugUtil;
1316
import com.instabug.reactlibrary.utils.MainThreadHandler;
1417

1518
import javax.annotation.Nonnull;
19+
import java.util.HashMap;
20+
import java.util.Map;
1621

1722
public class RNInstabugRepliesModule extends ReactContextBaseJavaModule {
1823

@@ -169,6 +174,41 @@ public void run() {
169174
});
170175
}
171176

177+
/**
178+
* Show in-app Messaging's notifications
179+
*
180+
* @param data the data bundle related to Instabug
181+
*/
182+
@ReactMethod
183+
public void showNotification(final ReadableMap data) {
184+
MainThreadHandler.runOnMainThread(new Runnable() {
185+
@Override
186+
public void run() {
187+
try {
188+
Map<String, String> map = new HashMap<>();
189+
ReadableMapKeySetIterator iterator = data.keySetIterator();
190+
191+
while (iterator.hasNextKey()) {
192+
String key = iterator.nextKey();
193+
ReadableType type = data.getType(key);
194+
195+
switch(type) {
196+
case String:
197+
String value = data.getString(key);
198+
map.put(key, value);
199+
break;
200+
}
201+
}
202+
if (Replies.isInstabugNotification(map)) {
203+
Replies.showNotification(map);
204+
}
205+
} catch (Exception e) {
206+
e.printStackTrace();
207+
}
208+
}
209+
});
210+
}
211+
172212
/**
173213
* Set the push notification's icon that will be shown with Instabug notifications
174214
*

index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export namespace Replies {
119119
): void;
120120
function setInAppNotificationSound(shouldPlaySound: boolean): void;
121121
function setPushNotificationRegistrationTokenAndroid(token: string): void;
122-
function setNotificationIconAndroid(notificationIcon: int): void;
122+
function showNotificationAndroid(data: object): void;
123+
function setNotificationIconAndroid(notificationIcon: number): void;
123124
function setPushNotificationChannelIdAndroid(pushNotificationChannelId: string): void;
124125
function setSystemReplyNotificationSoundEnabledAndroid(shouldPlaySound: boolean): void;
125126
}

modules/Replies.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ export default {
110110
}
111111
},
112112

113+
/**
114+
* Show in-app Messaging's notifications
115+
*
116+
* @param data the data bundle related to Instabug
117+
*/
118+
showNotificationAndroid(data) {
119+
if (Platform.OS === 'android') {
120+
IBGReplies.showNotification(data);
121+
}
122+
},
123+
113124
/**
114125
* Set the push notification's icon that will be shown with Instabug notifications
115126
*

0 commit comments

Comments
 (0)