Skip to content

Commit e453400

Browse files
committed
splitting IAM margin into top, bottom, left, right
1 parent 50562b4 commit e453400

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ interface InAppMessageViewListener {
6868
private final Handler handler = new Handler();
6969
private int pageWidth;
7070
private int pageHeight;
71-
private int marginPxSizeWidth = dpToPx(24);
72-
private int marginPxSizeHeight = dpToPx(24);
71+
private int marginPxSizeLeft = dpToPx(24);
72+
private int marginPxSizeRight = dpToPx(24);
73+
private int marginPxSizeTop = dpToPx(24);
74+
private int marginPxSizeBottom = dpToPx(24);
7375
private double dismissDuration;
7476
private boolean hasBackground;
7577
private boolean shouldDismissWhenActive = false;
@@ -116,6 +118,16 @@ void checkIfShouldDismiss() {
116118
}
117119
}
118120

121+
void useHeightMargins(boolean shouldUseMargin) {
122+
marginPxSizeBottom = shouldUseMargin ? MARGIN_PX_SIZE : 0;
123+
marginPxSizeTop = shouldUseMargin ? MARGIN_PX_SIZE : 0;
124+
}
125+
126+
void useWidthMargins(boolean shouldUseMargin) {
127+
marginPxSizeLeft = shouldUseMargin ? MARGIN_PX_SIZE : 0;
128+
marginPxSizeRight = shouldUseMargin ? MARGIN_PX_SIZE : 0;
129+
}
130+
119131
/**
120132
* This will fired when the device is rotated for example with a new provided height for the WebView
121133
* Called to shrink or grow the WebView when it receives a JS resize event with a new height.
@@ -196,22 +208,22 @@ private RelativeLayout.LayoutParams createParentRelativeLayoutParams() {
196208

197209
private DraggableRelativeLayout.Params createDraggableLayoutParams(int pageHeight, WebViewManager.Position displayLocation, boolean disableDragging) {
198210
DraggableRelativeLayout.Params draggableParams = new DraggableRelativeLayout.Params();
199-
draggableParams.maxXPos = marginPxSizeWidth;
200-
draggableParams.maxYPos = marginPxSizeHeight;
211+
draggableParams.maxXPos = marginPxSizeRight;
212+
draggableParams.maxYPos = marginPxSizeTop;
201213
draggableParams.draggingDisabled = disableDragging;
202214
draggableParams.messageHeight = pageHeight;
203215
draggableParams.height = getDisplayYSize();
204216

205217
switch (displayLocation) {
206218
case TOP_BANNER:
207-
draggableParams.dragThresholdY = marginPxSizeHeight - DRAG_THRESHOLD_PX_SIZE;
219+
draggableParams.dragThresholdY = marginPxSizeTop - DRAG_THRESHOLD_PX_SIZE;
208220
break;
209221
case BOTTOM_BANNER:
210222
draggableParams.posY = getDisplayYSize() - pageHeight;
211-
draggableParams.dragThresholdY = marginPxSizeHeight + DRAG_THRESHOLD_PX_SIZE;
223+
draggableParams.dragThresholdY = marginPxSizeBottom + DRAG_THRESHOLD_PX_SIZE;
212224
break;
213225
case FULL_SCREEN:
214-
draggableParams.messageHeight = pageHeight = getDisplayYSize() - (marginPxSizeHeight * 2);
226+
draggableParams.messageHeight = pageHeight = getDisplayYSize() - (marginPxSizeBottom + marginPxSizeTop);
215227
// fall through for FULL_SCREEN since it shares similar params to CENTER_MODAL
216228
case CENTER_MODAL:
217229
int y = (getDisplayYSize() / 2) - (pageHeight / 2);
@@ -343,7 +355,7 @@ public void onDragEnd() {
343355
cardView.setTag(IN_APP_MESSAGE_CARD_VIEW_TAG);
344356
cardView.addView(webView);
345357

346-
draggableRelativeLayout.setPadding(marginPxSizeWidth, marginPxSizeHeight, marginPxSizeWidth, marginPxSizeHeight);
358+
draggableRelativeLayout.setPadding(marginPxSizeLeft, marginPxSizeTop, marginPxSizeRight, marginPxSizeBottom);
347359
draggableRelativeLayout.setClipChildren(false);
348360
draggableRelativeLayout.setClipToPadding(false);
349361
draggableRelativeLayout.addView(cardView);
@@ -551,7 +563,7 @@ private void animateTop(View messageView, int height, Animation.AnimationListene
551563
// Animate the message view from above the screen downward to the top
552564
OneSignalAnimate.animateViewByTranslation(
553565
messageView,
554-
-height - marginPxSizeHeight,
566+
-height - marginPxSizeTop,
555567
0f,
556568
IN_APP_BANNER_ANIMATION_DURATION_MS,
557569
new OneSignalBounceInterpolator(0.1, 8.0),
@@ -563,7 +575,7 @@ private void animateBottom(View messageView, int height, Animation.AnimationList
563575
// Animate the message view from under the screen upward to the bottom
564576
OneSignalAnimate.animateViewByTranslation(
565577
messageView,
566-
height + marginPxSizeHeight,
578+
height + marginPxSizeBottom,
567579
0f,
568580
IN_APP_BANNER_ANIMATION_DURATION_MS,
569581
new OneSignalBounceInterpolator(0.1, 8.0),

0 commit comments

Comments
 (0)