Skip to content

Commit 04d0248

Browse files
committed
Improve Reactions dialog positions (x, y) and fix position when using Jetpack Compose
1 parent 341cf97 commit 04d0248

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

reactbutton/src/main/java/com/amrdeveloper/reactbutton/ReactButton.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.Context;
77
import android.content.DialogInterface;
88
import android.graphics.Color;
9+
import android.graphics.Rect;
910
import android.os.Build;
1011
import android.util.AttributeSet;
1112
import android.util.DisplayMetrics;
@@ -267,14 +268,22 @@ public boolean onTouch(View v, MotionEvent event) {
267268
// Setup dialog gravity and dynamic position
268269
WindowManager.LayoutParams windowManagerAttributes = window.getAttributes();
269270
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;
272282

273283
mReactAlertDialog.show();
284+
274285
if (mOnReactionDialogStateListener != null) mOnReactionDialogStateListener.onDialogOpened();
275286

276-
int dialogWidth = REACTION_ICON_SIZE * mDialogColumnsNumber;
277-
if (dialogWidth > SCREEN_MAX_WIDTH) dialogWidth = SCREEN_MAX_WIDTH;
278287
window.setLayout(dialogWidth, WindowManager.LayoutParams.WRAP_CONTENT);
279288

280289
mReactAlertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

0 commit comments

Comments
 (0)