Skip to content

Commit 50562b4

Browse files
committed
using relative layout params instead of a linear layout for the draggable
I am not sure why we were using linear layout params for a relative layout but they didn't seem to do anything. Switching to Relative layout params properly centers the draggable view in the parent.
1 parent c88908d commit 50562b4

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ void showInAppMessageView(Activity currentActivity) {
161161
);
162162
webViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
163163

164-
LinearLayout.LayoutParams linearLayoutParams = hasBackground ? createParentLinearLayoutParams() : null;
164+
RelativeLayout.LayoutParams relativeLayoutParams = hasBackground ? createParentRelativeLayoutParams() : null;
165165

166166
showDraggableView(
167167
displayLocation,
168168
webViewLayoutParams,
169-
linearLayoutParams,
169+
relativeLayoutParams,
170170
createDraggableLayoutParams(pageHeight, displayLocation, disableDragDismiss)
171171
);
172172
}
@@ -175,22 +175,23 @@ private int getDisplayYSize() {
175175
return OSViewUtils.getWindowHeight(currentActivity);
176176
}
177177

178-
private LinearLayout.LayoutParams createParentLinearLayoutParams() {
179-
LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(pageWidth, LinearLayout.LayoutParams.MATCH_PARENT);
180-
178+
private RelativeLayout.LayoutParams createParentRelativeLayoutParams() {
179+
RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams(pageWidth, RelativeLayout.LayoutParams.MATCH_PARENT);
181180
switch (displayLocation) {
182181
case TOP_BANNER:
183-
linearLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
182+
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
183+
relativeLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
184184
break;
185185
case BOTTOM_BANNER:
186-
linearLayoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
186+
relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
187+
relativeLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
187188
break;
188189
case CENTER_MODAL:
189190
case FULL_SCREEN:
190-
linearLayoutParams.gravity = Gravity.CENTER;
191+
relativeLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
191192
}
192193

193-
return linearLayoutParams;
194+
return relativeLayoutParams;
194195
}
195196

196197
private DraggableRelativeLayout.Params createDraggableLayoutParams(int pageHeight, WebViewManager.Position displayLocation, boolean disableDragging) {
@@ -229,7 +230,7 @@ private DraggableRelativeLayout.Params createDraggableLayoutParams(int pageHeigh
229230

230231
private void showDraggableView(final WebViewManager.Position displayLocation,
231232
final RelativeLayout.LayoutParams relativeLayoutParams,
232-
final LinearLayout.LayoutParams linearLayoutParams,
233+
final RelativeLayout.LayoutParams draggableRelativeLayoutParams,
233234
final DraggableRelativeLayout.Params webViewLayoutParams) {
234235
OSUtils.runOnMainUIThread(new Runnable() {
235236
@Override
@@ -240,8 +241,8 @@ public void run() {
240241
webView.setLayoutParams(relativeLayoutParams);
241242

242243
Context context = currentActivity.getApplicationContext();
243-
setUpDraggableLayout(context, linearLayoutParams, webViewLayoutParams);
244-
setUpParentLinearLayout(context);
244+
setUpDraggableLayout(context, draggableRelativeLayoutParams, webViewLayoutParams);
245+
setUpParentRelativeLayout(context);
245246
createPopupWindow(parentRelativeLayout);
246247

247248
if (messageController != null) {
@@ -276,6 +277,10 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
276277
case BOTTOM_BANNER:
277278
gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
278279
break;
280+
case CENTER_MODAL:
281+
case FULL_SCREEN:
282+
gravity = Gravity.CENTER_HORIZONTAL;
283+
break;
279284
}
280285
}
281286

@@ -293,8 +298,10 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
293298
0
294299
);
295300
}
301+
/*
296302
297-
private void setUpParentLinearLayout(Context context) {
303+
*/
304+
private void setUpParentRelativeLayout(Context context) {
298305
parentRelativeLayout = new RelativeLayout(context);
299306
parentRelativeLayout.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
300307
parentRelativeLayout.setClipChildren(false);
@@ -303,11 +310,11 @@ private void setUpParentLinearLayout(Context context) {
303310
}
304311

305312
private void setUpDraggableLayout(final Context context,
306-
LinearLayout.LayoutParams linearLayoutParams,
313+
RelativeLayout.LayoutParams relativeLayoutParams,
307314
DraggableRelativeLayout.Params draggableParams) {
308315
draggableRelativeLayout = new DraggableRelativeLayout(context);
309-
if (linearLayoutParams != null)
310-
draggableRelativeLayout.setLayoutParams(linearLayoutParams);
316+
if (relativeLayoutParams != null)
317+
draggableRelativeLayout.setLayoutParams(relativeLayoutParams);
311318
draggableRelativeLayout.setParams(draggableParams);
312319
draggableRelativeLayout.setListener(new DraggableRelativeLayout.DraggableListener() {
313320
@Override

0 commit comments

Comments
 (0)