Tooltip icon indicating copy to clipboard operation
Tooltip copied to clipboard

Android 10 tooltip lagging issue

Open MarioCroSite opened this issue 6 years ago • 12 comments

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

MarioCroSite avatar Feb 08 '20 14:02 MarioCroSite

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

ViHtarb avatar Feb 08 '20 20:02 ViHtarb

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 avatar Feb 08 '20 22:02 MarioCroSite

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. ?

MarioCroSite avatar Feb 13 '20 20:02 MarioCroSite

@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 avatar Feb 13 '20 22:02 ViHtarb

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

ViHtarb avatar Feb 13 '20 23:02 ViHtarb

Can you remove animation and make new snapshot ?

MarioCroSite avatar Feb 13 '20 23:02 MarioCroSite

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

ViHtarb avatar Feb 14 '20 00:02 ViHtarb

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

MarioCroSite avatar Feb 14 '20 00:02 MarioCroSite

@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 avatar Feb 14 '20 00:02 ViHtarb

@MarioCroSite done

ViHtarb avatar Feb 14 '20 00:02 ViHtarb

Thanks @ViHtarb :)

MarioCroSite avatar Feb 14 '20 00:02 MarioCroSite

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
    }

outofdate avatar Mar 20 '20 10:03 outofdate