|
6 | 6 | import android.content.Context;
|
7 | 7 | import android.content.DialogInterface;
|
8 | 8 | import android.graphics.Color;
|
| 9 | +import android.graphics.Rect; |
9 | 10 | import android.os.Build;
|
10 | 11 | import android.util.AttributeSet;
|
11 | 12 | import android.util.DisplayMetrics;
|
@@ -267,14 +268,22 @@ public boolean onTouch(View v, MotionEvent event) {
|
267 | 268 | // Setup dialog gravity and dynamic position
|
268 | 269 | WindowManager.LayoutParams windowManagerAttributes = window.getAttributes();
|
269 | 270 | windowManagerAttributes.gravity = Gravity.TOP | Gravity.START;
|
270 |
| - windowManagerAttributes.x = (int) getX() + (getWidth() / 2); |
271 |
| - windowManagerAttributes.y = (int) getY() + (getHeight() / 2); |
| 271 | + |
| 272 | + int dialogWidth = REACTION_ICON_SIZE * mDialogColumnsNumber; |
| 273 | + if (dialogWidth > SCREEN_MAX_WIDTH) dialogWidth = SCREEN_MAX_WIDTH; |
| 274 | + |
| 275 | + final Rect react = new Rect(); |
| 276 | + getGlobalVisibleRect(react); |
| 277 | + |
| 278 | + // Can be optimized and calculated once and modified only when size changed |
| 279 | + // Calculate x and y from global visible position to work also in Jetpack Compose |
| 280 | + windowManagerAttributes.x = react.left + react.width() / 2 - dialogWidth / 2; |
| 281 | + windowManagerAttributes.y = react.top - react.height() * 2; |
272 | 282 |
|
273 | 283 | mReactAlertDialog.show();
|
| 284 | + |
274 | 285 | if (mOnReactionDialogStateListener != null) mOnReactionDialogStateListener.onDialogOpened();
|
275 | 286 |
|
276 |
| - int dialogWidth = REACTION_ICON_SIZE * mDialogColumnsNumber; |
277 |
| - if (dialogWidth > SCREEN_MAX_WIDTH) dialogWidth = SCREEN_MAX_WIDTH; |
278 | 287 | window.setLayout(dialogWidth, WindowManager.LayoutParams.WRAP_CONTENT);
|
279 | 288 |
|
280 | 289 | mReactAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
0 commit comments