Skip to content

Commit 565f476

Browse files
committed
firing onPageChanged from json event
1 parent 2d04a71 commit 565f476

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ void onFailure(int statusCode, String response, Throwable throwable) {
281281
}
282282
}
283283

284-
void onPageChanged(@NonNull final OSInAppMessage message, @NonNull final OSInAppMessagePage newPage) {
284+
void onPageChanged(@NonNull final OSInAppMessage message, @NonNull final JSONObject messageJson) {
285+
final OSInAppMessagePage newPage = new OSInAppMessagePage(messageJson);
285286
if (message.isPreview) {
286287
return;
287288
}

OneSignalSDK/onesignal/src/main/java/com/onesignal/WebViewManager.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class OSJavaScriptInterface {
155155
static final String EVENT_TYPE_KEY = "type";
156156
static final String EVENT_TYPE_RENDERING_COMPLETE = "rendering_complete";
157157
static final String EVENT_TYPE_ACTION_TAKEN = "action_taken";
158+
static final String EVENT_TYPE_PAGE_CHANGE = "page_change";
158159

159160
static final String IAM_DISPLAY_LOCATION_KEY = "displayLocation";
160161
static final String IAM_PAGE_META_DATA_KEY = "pageMetaData";
@@ -168,11 +169,20 @@ public void postMessage(String message) {
168169
JSONObject jsonObject = new JSONObject(message);
169170
String messageType = jsonObject.getString(EVENT_TYPE_KEY);
170171

171-
if (messageType.equals(EVENT_TYPE_RENDERING_COMPLETE))
172-
handleRenderComplete(jsonObject);
173-
else if (messageType.equals(EVENT_TYPE_ACTION_TAKEN) && !messageView.isDragging()) {
174-
// Added handling so that click actions won't trigger while dragging the IAM
175-
handleActionTaken(jsonObject);
172+
switch (messageType) {
173+
case EVENT_TYPE_RENDERING_COMPLETE:
174+
handleRenderComplete(jsonObject);
175+
break;
176+
case EVENT_TYPE_ACTION_TAKEN:
177+
// Added handling so that click actions won't trigger while dragging the IAM
178+
if (!messageView.isDragging())
179+
handleActionTaken(jsonObject);
180+
break;
181+
case EVENT_TYPE_PAGE_CHANGE:
182+
handlePageChange(jsonObject);
183+
break;
184+
default:
185+
break;
176186
}
177187
} catch (JSONException e) {
178188
e.printStackTrace();
@@ -226,6 +236,14 @@ private void handleActionTaken(JSONObject jsonObject) throws JSONException {
226236
if (close)
227237
dismissAndAwaitNextMessage(null);
228238
}
239+
240+
private void handlePageChange(JSONObject jsonObject) throws JSONException {
241+
JSONObject body = jsonObject.getJSONObject("body");
242+
String id = body.optString("id", null);
243+
if (id != null) {
244+
OneSignal.getInAppMessageController().onPageChanged(message, body);
245+
}
246+
}
229247
}
230248

231249
private static int pageRectToViewHeight(final @NonNull Activity activity, @NonNull JSONObject jsonObject) {

0 commit comments

Comments
 (0)