-
Notifications
You must be signed in to change notification settings - Fork 551
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
Rich text image centre fix #507
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This fixes image alignment thanks.
} | ||
|
||
// Reference: https://stackoverflow.com/a/51865494 | ||
fun <T : View> T.width(calculateWidth: (Int) -> Unit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not keen on this extension function because it has a high hidden cost, and potentially leaks a OnGlobalLayoutListener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please name this something closer to what it's doing, e.g. 'computeWidthOnGlobalLayout'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the code like this:
private fun TextView.width(computeWidthOnGlobalLayout: (Int) -> Unit) {
if (width == 0) {
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
viewTreeObserver.removeOnGlobalLayoutListener(this)
computeWidthOnGlobalLayout(width)
}
})
} else {
computeWidthOnGlobalLayout(width)
}
}
@BenHenning does this look correct? If it is correct, then you can merge this directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments--please address & verify the changes work before merging.
Thanks!
NB: because I'm unsure of the solution, I'm only merging this in the temp-integration-pt3 branch for now. |
Also as I hoped, this does seem to fix the jankiness issues. Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
As mentioned in #494 I think we still have some image jankiness issues, and I wasn't confident a few weeks ago whether it was caused by the global layout listener introduced here. Can you investigate? It'd be good to better understand where that jankiness is coming from before we settle on this solution. |
I have checked this implementation mainly on Also, with this solution, the image is actually rendering really well in exploration as compared to on develop. The issue is the image in HtmlParser is not janky otherwise it would have not been working correctly in |
@BenHenning as discussed in meeting, the reason behind the jankiness is mainly because of state implementation. So what should we do here ? |
Let's check this in as-is. We'll need to continue chipping away at the jankiness issue as part of #434. |
@BenHenning Merging this now with develop. |
Explanation
@BenHenning had observed one issue in which if we open exploration, again and again quickly, then in some cases (approximately 10-20% times) the image in content card would cut from the very start. Check below image:

This has been fixed to keep image always in centre.
Also, to test this, you will need to open exploration again and again quickly as shown in gif. Make sure you test this atleast 10 times quickly.
Checklist