Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 10 tooltip lagging issue #60

Open
MarioCroSite opened this issue Feb 8, 2020 · 12 comments
Open

Android 10 tooltip lagging issue #60

MarioCroSite opened this issue Feb 8, 2020 · 12 comments
Assignees
Labels

Comments

@MarioCroSite
Copy link

Hi everybody. On Android 10 I have problem with lagging tooltip. On Android 9 and lower versions all works perfect. Do you have any idea how to fix this problem. @ViHtarb

Android 10 (picture preview)
Android 10
Android 9 (picture preview)
Android 9

@ViHtarb ViHtarb self-assigned this Feb 8, 2020
@ViHtarb ViHtarb added the bug label Feb 8, 2020
@ViHtarb
Copy link
Owner

ViHtarb commented Feb 8, 2020

Hi. Thanks for report. I know about this bug and trying to fix it but i have no idea how to do this exactly

@MarioCroSite
Copy link
Author

MarioCroSite commented Feb 8, 2020

Hmm, maybe is problem in "Gravity". In Android 9 is different rendering than in android 10.
In Android 9 you need to wait few milliseconds more than in Android 10 to show tooltip.

@MarioCroSite
Copy link
Author

Hi @ViHtarb do you have any idea now why this happen ? Did you find any similar issues on stackoverflow or any other site like medium, etc. ?

@ViHtarb
Copy link
Owner

ViHtarb commented Feb 13, 2020

@MarioCroSite Hi, now i`m busy on work - we are making release. Sorry but i can't fix it soon. I think it's trouble with updating PopupWindow position on android 10.

@ViHtarb
Copy link
Owner

ViHtarb commented Feb 13, 2020

@MarioCroSite it looks like PopupWindow can't update position while playing enterAnimation

@MarioCroSite
Copy link
Author

Can you remove animation and make new snapshot ?

@ViHtarb
Copy link
Owner

ViHtarb commented Feb 14, 2020

@MarioCroSite I can but this is not a solution to the problem

@MarioCroSite
Copy link
Author

Can you maybe put here little snippet code what we need to change for workaround solution. @ViHtarb

@ViHtarb
Copy link
Owner

ViHtarb commented Feb 14, 2020

@MarioCroSite As temporary fix for android 10 the tooltips will use showAtLocation method instead of showAsDropDown it`s prevent using animations. Fix will be available in alpha06 snapshot

ViHtarb added a commit that referenced this issue Feb 14, 2020
PopupWindow#showAtLocation for android 10 to fast fix tooltip position updating #60
Fixed setting compound drawables for pre 17 API for simple Tooltip
@ViHtarb
Copy link
Owner

ViHtarb commented Feb 14, 2020

@MarioCroSite done

@MarioCroSite
Copy link
Author

Thanks @ViHtarb :)

@outofdate
Copy link

outofdate commented Mar 20, 2020

I got a little insight on this bug. Usage of addOnGlobalLayoutListener is a little bit wrong, because it's called after a while, when popup is already shown. So my proposition would be to measure and calculate things before updating popup, rather than rely on onGlobalLayout.
Brief solution just for popup(without arrow for now) would be:

 override fun show() {
        if (!isShowing) {
            //    content.viewTreeObserver.addOnGlobalLayoutListener(locationLayoutListener)
            anchor.addOnAttachStateChangeListener(onAttachStateChangeListener)
            anchor.post {
                if (anchor.isShown) {
                    val location = calculateLocation()
                    popupWindow.showAsDropDown(anchor)
                    popupWindow.isClippingEnabled = true
                    popupWindow.update(
                        location.x.toInt(),
                        location.y.toInt(),
                        content.measuredWidth,
                        content.measuredHeight
                    )
                }
            }
        }
    }

   private fun calculateLocation(): PointF {
        content.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
        val location = PointF()
        val anchorRect = calculateRectInWindow(anchor)
        val anchorCenter = PointF(anchorRect.centerX(), anchorRect.centerY())
        when (gravity) {
            Gravity.LEFT -> {
                location.x = anchorRect.left - content.measuredWidth - margin
                location.y = anchorCenter.y - content.measuredHeight / 2f
            }
            Gravity.RIGHT -> {
                location.x = anchorRect.right + margin
                location.y = anchorCenter.y - content.measuredHeight / 2f
            }
            Gravity.TOP -> {
                location.x = anchorCenter.x - content.measuredWidth / 2f
                location.y = anchorRect.top - content.measuredHeight - margin
            }
            Gravity.BOTTOM -> {
                location.x = anchorCenter.x - content.measuredWidth / 2f
                location.y = anchorRect.bottom + margin
            }
        }
        return location
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants