Skip to content

Fix sliding when reducing size.#3454

Merged
swissspidy merged 12 commits intodevelopfrom
fix/3447-sliding_when_reducing
Oct 14, 2019
Merged

Fix sliding when reducing size.#3454
swissspidy merged 12 commits intodevelopfrom
fix/3447-sliding_when_reducing

Conversation

@miina
Copy link
Copy Markdown
Contributor

@miina miina commented Oct 7, 2019

Summary

From investigation:

The issue here is coming from the font size going over the limits of the block while reducing the size and this making the block slide. It does not have anything to do with positioning.

Addresses issue #3447

  • Fix sliding for Text block and Meta blocks with amp-fit-text.

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Oct 7, 2019
@miina miina changed the title [WIP] Fix sliding when reducing size. Fix sliding when reducing size. Oct 7, 2019
// If we have amp-fit-text on, then reduce the font size to prevent the block
// shifting due to font size not fitting.
if ( ampFitTextElement ) {
while ( appliedWidth < scrollWidth || appliedHeight < scrollHeight ) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like the sliding issue came from the initial pre-resize amp-fit-text font size being too large for the container and this causing the container to "slide". After resizing stopping and the font calculation happened, the block "jumped" to its correct position. Note that this did not influence the top/left positioning in any way.

WDYT of this approach? Reducing the font size already while resizing.

resizing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's performant, it's a great idea and better UX than the original. Does it work well for even long texts and weird fonts (with many ligatures)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It only works when making the block smaller, not when making it larger, which is confusing. Also doesn't seem to respect MAX_FONT_SIZE and MIN_FONT_SIZE. I just made a block with lots of text very small and the text basically disappeared because the font size was set to 0px.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It definitely should have font limits. Also, if we go that way we should also implement the same logic for the post meta blocks as well to make it consistent.

On performance: seems to work well with weird fonts as well, at least as far as I tested.

On working when making the block smaller only: yep, I was doubting that it might be confusing. When turning off amp-fit-text and the previously saved font size is too large then we automatically increase the size of the block so that the text would fit inside. However, we do not reduce the block if there's a lot of room. Meaning that elsewhere we do care about the font not going over the lines, not so much about there being extra room left. Because of that, I was 50-50 that perhaps it's OK just to make sure that the text fits the block but ignore if there's more room. It's a bit different case for amp-fit-text though.

Anyway -- I'll add the size increasing as well now that you brought it out as well.

@barklund
Copy link
Copy Markdown
Contributor

barklund commented Oct 8, 2019

I see quite a few problems with this though. I have the default fitted text box on a new story, paste a lot of text in there and start resizing. I can't make the box shorter, when I make it narrower the content jumps weirdly around, when I make it wider the content font size is suddenly tiny. All this is without rotating.

In the end I ended up with this weird monstrosity - where the content doesn't take up the full width while at the same time taking up too much length.
Screenshot 2019-10-08 at 16 27 22

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 8, 2019

Thanks for testing. Yes, it's not final yet.

Was working on this but wasn't able to figure out yet why some of the things were happening as they were happening so will continue tomorrow morning.

Just pushed a fix for the specific issue that you mentioned, however, there are still a bunch of oddities happening.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 8, 2019

Related to some of the issues I'm seeing: #3398

Not sure exactly why that happens.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 8, 2019

An alternative for fixing the "sliding" specifically would be to assign absolute value to the element which contains the text for the time of resizing. Perhaps it might make more sense to just do that and leave adjusting the font size for later 🤷‍♀

Using absolute on the text element (or hidden overflow on the parent element) causes other kind of jumpiness though:

jumpiness

Anyway, will give it another try in the morning.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 9, 2019

After looking into this more then it looks like it does not make sense right now to add the font size reducing -- mostly due to the bug #3398 which means that while resizing the text is quite often switching between tiny and huge font so it looks like some odd flickering.

That would need fixing first first.

Also tried reducing/increasing the font by 1 instead of trying to find the "ideal" font size but this causes some additional issues when resizing very fast.

@googlebot
Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no Has not signed the Google CLA and removed cla: yes Signed the Google CLA labels Oct 9, 2019
@barklund
Copy link
Copy Markdown
Contributor

barklund commented Oct 9, 2019

@googlebot I consent.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Signed the Google CLA and removed cla: no Has not signed the Google CLA labels Oct 9, 2019
@barklund
Copy link
Copy Markdown
Contributor

barklund commented Oct 9, 2019

@miina, this is once again due to the slightly weird decision of displaying the inner box as inline-block. Inline block elements observe line-height and thus has some extra "padding" due to line height being added under some (but not all) circumstances.

When the overflow changes to hidden (or position to absolute), the parent element suddenly gets the extra height from the line height and this causes a slight shift for rotated elements.

I have now set the line-height to 0 for the outer block element (and re-set it to 1.15 for the inner one) and it seems to work for all the elements, but please text extensively - and remember to test them all with both fit and non-fit plus single- and multi-line texts.

We really should place that inner block correctly with display:flex on the contaner rather than display:inline-block on the element itself. But that's a future concern.

@miina miina marked this pull request as ready for review October 10, 2019 10:51
@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 10, 2019

Thanks for this!

Tested with Text block and post meta blocks (title, author, date), with both amp-fit-text on and without; with multiple lines and single lines; also with bold and italic in the middle in case of the Text block.

Didn't detect any regressions.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 10, 2019

@spacedmonkey As you haven't touched the code of this PR, would you mind reviewing?

@miina miina mentioned this pull request Oct 11, 2019
3 tasks
Copy link
Copy Markdown
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Just tested with text block (with amp-fit-text on) and it still is sliding: https://cloudup.com/cfIG3pOXUBP

@spacedmonkey
Copy link
Copy Markdown
Contributor

I can confirm that I am still seeing the slide as well :(

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

Uh, that's unexpected.

Will debug some more then.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

Weird but I'm not able to replicate it, tried for some time with different rotations etc.
Tested on Chrome and also Safari and Firefox. 🤷‍♀

not-sliding

What I did:

  • Add Text block
  • Leave amp-fit-text on.
  • Add some background color for visibility.
  • Rotate the block
  • Write "Hello there and there as content
  • Resize wider
  • Try resizing smaller.

Is there anything else you're doing when testing? Not sure what am I doing differently.

@swissspidy
Copy link
Copy Markdown
Collaborator

@miina Hmm not seeing the exact same issue as in the video anymore, but it still happens when making the block very small or very big.

See new video: https://cloudup.com/cn74fKgoQZL

Comparing with your demo, it doesn't go as far.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

@swissspidy Thanks for checking again.

On the block sliding when going very large: that seems to be a different issue, looks like it's related to the resizing logic + positioning and not the font size. We might want to report a separate issue for that for prioritization. Potentially it's less important since it's unlikely to resize the block that much over the limits of the Page. Thoughts? So many issues with resizing have appeared lately.

On the block sliding when going very small:
Could it be a caching issue and CSS not updating? I'm seeing that in your video the text goes over the block, however, since it has overflow:hidden assigned (which is the fix in this PR) then it should not be visible outside of the block.

@spacedmonkey
Copy link
Copy Markdown
Contributor

Two possiblity related issues #3461 & #3444

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

Two possiblity related issues #3461 & #3444

These two are related in terms of being related to resizing but have a different cause. #3444 still needs investigation and Implementation Brief but it's likely related to positioning the block while resizing. #3461 has Implementation Brief where the source of the issue is mentioned (see Cause of the bug and possible fix).

In this issue's case, it's the font size that causes it.

Note that #3444 might be related to sliding when making a block very big since both are related to positioning the block when resizing. We could combine those if you prefer!

@swissspidy swissspidy added this to the v1.3.1 milestone Oct 14, 2019
@swissspidy
Copy link
Copy Markdown
Collaborator

Thanks for the clarification. I'm fine with merging this for now as it's already an important improvement.

It would be good to take a more holistic approach for the remaining resizing issues, otherwise we keep chasing edge cases.

@swissspidy swissspidy merged commit 2fbe020 into develop Oct 14, 2019
@swissspidy swissspidy deleted the fix/3447-sliding_when_reducing branch October 14, 2019 13:32
@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

Most of the resizing bugs so far haven't been the quickest to resolve, and somehow each bug has brought out new bugs. Initially, I combined the newly found related bugs as well but then it started taking too much time since the issues (causes) were actually different + each one of those took some debugging time. And then one bug was fixed but waiting for another bug getting fixed, too. Also, some cases are edge cases and some more common cases, so prioritization would be good, too.

Not sure what's the best approach here, not sure if putting all the issues together would make sense in terms of having different causes + taking too much time to get anything fixed. 🤷‍♀At least that's how I felt when actually working on those.

@spacedmonkey
Copy link
Copy Markdown
Contributor

Not sure what's the best approach here, not sure if putting all the issues together would make sense in terms of having different causes

I am not sure I agree here. A fix for one issue, may effect other work another developer is working on.
I would also question, why do we have some many bugs with resizing? I see we are using re-resizable, I wonder if they are upstream bugs in this library and maybe we should replace this with another library...

@swissspidy
Copy link
Copy Markdown
Collaborator

I would also question, why do we have some many bugs with resizing? I see we are using re-resizable, I wonder if they are upstream bugs in this library and maybe we should replace this with another library...

The library is just fine. The problem lies in the complexity of resizing elements that are rotated, as we have to do re-calculate the block's top and left position constantly while resizing.

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 14, 2019

I am not sure I agree here. A fix for one issue, may effect other work another developer is working on.

In my case, I had been debugging one issue for a few days. Then another issue came out which had a completely different cause. That took quite a long time to figure out + there was some feedback rounds and it delayed the first (related but not the same) bug for more than a week. If we gather all the different bugs together then it might take quite a long time for those getting fixed although another bug got fixed already. Also -- some of these bugs are edge cases (such as #3444) and being mindful of the timeline then we should prioritize.

I would also question, why do we have some many bugs with resizing? I see we are using re-resizable, I wonder if they are upstream bugs in this library and maybe we should replace this with another library...

Nope, not upstream bugs, so far there have been a lot of regressions since resizing is quite influenced by a lot of stuff and almost every block has resizing + we've added dragging and rotating to it. So it's fully our own bugs :)

@miina
Copy link
Copy Markdown
Contributor Author

miina commented Oct 15, 2019

Just realized that there's a bug related to this PR: the fix should be for amp-fit-text only! Reopening

@miina miina mentioned this pull request Oct 15, 2019
3 tasks
@swissspidy swissspidy modified the milestones: v1.3.1, v1.4 Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes Signed the Google CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants