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

Rich text image centre fix #507

Merged
merged 3 commits into from
Dec 20, 2019
Merged

Rich text image centre fix #507

merged 3 commits into from
Dec 20, 2019

Conversation

rt4914
Copy link
Contributor

@rt4914 rt4914 commented Dec 3, 2019

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:
Screenshot_1575389556

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.

image-issue-2

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The PR follows the style guide.
  • The PR does not contain any unnecessary auto-generated code from Android Studio.
  • The PR is made from a branch that's not called "develop".
  • The PR is made from a branch that is up-to-date with "develop".
  • The PR's branch is based on "develop" and not on any other branch.
  • The PR is assigned to an appropriate reviewer in both the Assignees and the Reviewers sections.

Copy link
Contributor

@veena14cs veena14cs left a 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.

@veena14cs veena14cs assigned rt4914 and unassigned veena14cs Dec 4, 2019
@rt4914 rt4914 removed their assignment Dec 4, 2019
}

// Reference: https://stackoverflow.com/a/51865494
fun <T : View> T.width(calculateWidth: (Int) -> Unit) {
Copy link
Member

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.

Copy link
Member

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'

Copy link
Contributor Author

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.

Copy link
Member

@BenHenning BenHenning left a 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!

@BenHenning BenHenning assigned rt4914 and unassigned BenHenning Dec 4, 2019
@rt4914 rt4914 assigned BenHenning and unassigned rt4914 Dec 4, 2019
@BenHenning
Copy link
Member

NB: because I'm unsure of the solution, I'm only merging this in the temp-integration-pt3 branch for now.

@BenHenning
Copy link
Member

BenHenning commented Dec 5, 2019

Also as I hoped, this does seem to fix the jankiness issues. Nice!

Copy link
Contributor

@nikitamarysolomanpvt nikitamarysolomanpvt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nikitamarysolomanpvt nikitamarysolomanpvt removed their assignment Dec 5, 2019
@BenHenning
Copy link
Member

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.

@BenHenning BenHenning assigned rt4914 and unassigned BenHenning Dec 17, 2019
@rt4914
Copy link
Contributor Author

rt4914 commented Dec 18, 2019

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 HtmlParserTestActivity and I have observed that even with or without this solution the image does not have jankiness in HtmlParserTestActivity.

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 HtmlParserTestActivity. After checking this again and again, I was able to confirm that the jankiness is in StateFragment somewhere. Now I need to investigate on that for exact reason behind the jankiness.

@rt4914
Copy link
Contributor Author

rt4914 commented Dec 19, 2019

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 HtmlParserTestActivity and I have observed that even with or without this solution the image does not have jankiness in HtmlParserTestActivity.

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 HtmlParserTestActivity. After checking this again and again, I was able to confirm that the jankiness is in StateFragment somewhere. Now I need to investigate on that for exact reason behind the jankiness.

@BenHenning as discussed in meeting, the reason behind the jankiness is mainly because of state implementation. So what should we do here ?

@rt4914 rt4914 assigned BenHenning and unassigned rt4914 Dec 19, 2019
@BenHenning
Copy link
Member

Let's check this in as-is. We'll need to continue chipping away at the jankiness issue as part of #434.

@rt4914
Copy link
Contributor Author

rt4914 commented Dec 20, 2019

@BenHenning Merging this now with develop.

@rt4914 rt4914 merged commit 4bfbbab into develop Dec 20, 2019
@rt4914 rt4914 deleted the rich-text-image-fix branch December 20, 2019 05:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants