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

[Mobile] - Support background colors for Group block #25994

Merged
merged 21 commits into from
Nov 20, 2020

Conversation

geriux
Copy link
Member

@geriux geriux commented Oct 9, 2020

Gutenberg Mobile PR -> wordpress-mobile/gutenberg-mobile#2703
WordPress iOS PR -> wordpress-mobile/WordPress-iOS#15079
WordPress Android PR -> wordpress-mobile/WordPress-Android#13279

Part of wordpress-mobile/gutenberg-mobile#2195

Description

This PR adds rendering colors support for:

  • Group: rendering background colors.
  • Quote: inherits text colors from parent blocks, e.g Group.
  • Paragraph: rendering text/background colors and adding paddings when a background color is set.

How has this been tested?

Steps to test: Group/Paragraph

Steps:

From the web editor

  • Create a Group block
  • Set a background color and a text color in the Color settings menu
  • Add a Paragraph block and write a text
  • Expect to see the text color of the block inherited from the Group block
  • Save the post
  • Open the post from the app
  • Expect to see the correct paddings and colors

Or use this code:

<!-- wp:group {"backgroundColor":"accent","textColor":"background"} -->
<div class="wp-block-group has-background-color has-accent-background-color has-text-color has-background"><div class="wp-block-group__inner-container"><!-- wp:paragraph -->
<p>Paragraph 1</p>
<!-- /wp:paragraph -->

<!-- wp:group {"style":{"color":{"background":"#0e6056","text":"#02d414"}}} -->
<div class="wp-block-group has-text-color has-background" style="background-color:#0e6056;color:#02d414"><div class="wp-block-group__inner-container"><!-- wp:paragraph -->
<p>Paragraph 2</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:group -->

<!-- wp:group {"style":{"color":{"background":"#605582","text":"#fbd0ff"}}} -->
<div class="wp-block-group has-text-color has-background" style="background-color:#605582;color:#fbd0ff"><div class="wp-block-group__inner-container"><!-- wp:paragraph -->
<p>Paragraph 3</p>
<!-- /wp:paragraph -->

<!-- wp:group {"style":{"color":{"background":"#ee2865","text":"#ecd0f2"}}} -->
<div class="wp-block-group has-text-color has-background" style="background-color:#ee2865;color:#ecd0f2"><div class="wp-block-group__inner-container"><!-- wp:paragraph -->
<p>Paragraph 4</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:group --></div></div>
<!-- /wp:group -->

<!-- wp:paragraph -->
<p>Paragraph 5</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:group -->
Steps to test: Quote

Steps:

From the web editor

Note: You won't see the colors applied to the Quote block in the web editor

  • Create a Group block
  • Set a text color in the Color settings menu
  • Add a Quote block
  • Set some text in the block
  • Save the post
  • Open the post from the app
  • Expect to see the Quote block inheriting its parent's text color set in the web editor.

Or use this code:

<!-- wp:group {"backgroundColor":"background","style":{"color":{"text":"#4d4313"}}} -->
<div class="wp-block-group has-background-background-color has-text-color has-background" style="color:#4d4313"><div class="wp-block-group__inner-container"><!-- wp:quote -->
<blockquote class="wp-block-quote"><p>This is my cool quote</p><cite>Citation here</cite></blockquote>
<!-- /wp:quote --></div></div>
<!-- /wp:group -->

Screenshots

iOS Web editor
Template Example Template Example

Types of changes

New feature

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@geriux geriux added [Status] In Progress Tracking issues with work in progress Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Oct 9, 2020
@github-actions
Copy link

github-actions bot commented Oct 9, 2020

Size Change: +742 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/annotations/index.js 3.8 kB +30 B (0%)
build/block-directory/index.js 8.72 kB +10 B (0%)
build/block-editor/index.js 133 kB -83 B (0%)
build/block-editor/style-rtl.css 11.3 kB -2 B (0%)
build/block-editor/style.css 11.3 kB -3 B (0%)
build/block-library/editor-rtl.css 8.95 kB +38 B (0%)
build/block-library/editor.css 8.95 kB +35 B (0%)
build/block-library/index.js 147 kB +225 B (0%)
build/blocks/index.js 48 kB +17 B (0%)
build/components/index.js 172 kB +354 B (0%)
build/compose/index.js 9.95 kB +54 B (0%)
build/core-data/index.js 14.8 kB +65 B (0%)
build/data-controls/index.js 827 B +6 B (0%)
build/data/index.js 8.8 kB +58 B (0%)
build/date/index.js 11.2 kB -2 B (0%)
build/edit-navigation/index.js 11.2 kB +19 B (0%)
build/edit-post/index.js 306 kB +95 B (0%)
build/edit-post/style-rtl.css 6.45 kB -53 B (0%)
build/edit-post/style.css 6.44 kB -54 B (0%)
build/edit-site/index.js 23.2 kB -106 B (0%)
build/edit-site/style-rtl.css 3.85 kB -132 B (3%)
build/edit-site/style.css 3.85 kB -131 B (3%)
build/edit-widgets/index.js 26.4 kB +87 B (0%)
build/edit-widgets/style-rtl.css 3.13 kB -38 B (1%)
build/edit-widgets/style.css 3.13 kB -36 B (1%)
build/editor/index.js 42.7 kB +154 B (0%)
build/keyboard-shortcuts/index.js 2.54 kB +22 B (0%)
build/list-reusable-blocks/index.js 3.1 kB +2 B (0%)
build/media-utils/index.js 5.32 kB +2 B (0%)
build/notices/index.js 1.81 kB +23 B (1%)
build/nux/index.js 3.42 kB +25 B (0%)
build/plugins/index.js 2.56 kB +2 B (0%)
build/redux-routine/index.js 2.84 kB -2 B (0%)
build/reusable-blocks/index.js 3.06 kB +16 B (0%)
build/rich-text/index.js 13.3 kB +23 B (0%)
build/server-side-render/index.js 2.77 kB +2 B (0%)
build/viewport/index.js 1.86 kB +20 B (1%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 664 B 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/style-rtl.css 8.1 kB 0 B
build/block-library/style.css 8.1 kB 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.92 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.16 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.05 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@geriux
Copy link
Member Author

geriux commented Oct 9, 2020

Hey @iamthomasbishop @kyleaparker 👋 I've made a build with the ongoing work to support background colors for Group block, just in case you want to test some of the templates. It also has the latest full-width changes (except Columns).

@kyleaparker
Copy link

Nice, this is working well for me!

@iamthomasbishop
Copy link

iamthomasbishop commented Oct 12, 2020

@geriux This is looking solid, nice work! I found one issue, but I'm not sure if it's related to the changes you've made — I'm guessing it's specific to recent work done on the BottomSheet component.

The issue is on block settings sheets; when you open them, they get stuck at ~40-60px height. Here's a screenshot:

And fwiw, I'm only seeing it happen on these blocks (and not only in the context of Group block):

  • Heading
  • Group
  • List
  • Media & Text

@kyleaparker
Copy link

I just noticed after making some edits on a page with this build, it starts to give me these errors on the desktop editor:
Edit Page ‹ Overton — WordPress com 2020-10-13 18-53-31

The page was working fine on the web immediately before I made changes in the mobile editor.

@geriux
Copy link
Member Author

geriux commented Oct 13, 2020

I found one issue, but I'm not sure if it's related to the changes you've made — I'm guessing it's specific to recent work done on the BottomSheet component.

The issue is on block settings sheets; when you open them, they get stuck at ~40-60px height. Here's a screenshot:

Oops, forgot to disable that 😅. The issue you're seeing is that it's trying to show the Color Settings since the block has colors set but this is not available on mobile yet.

Thanks for testing @iamthomasbishop!

@geriux
Copy link
Member Author

geriux commented Oct 13, 2020

I just noticed after making some edits on a page with this build, it starts to give me these errors on the desktop editor:

There's an ongoing issue with the Columns block and it's included in the build I created so sorry for that, hope you were able to recover your changes 🤞

Once this issue is solved I'll do more testing to double check is not giving any issues between the app and the web editor.

Thanks for testing @kyleaparker!

@geriux
Copy link
Member Author

geriux commented Oct 13, 2020

@iamthomasbishop The issue is now solved, I added the Color picker to the blocks that support text/background colors:

The build now includes this just in case you wanted to try it out =)

@iamthomasbishop
Copy link

This looks great! Not sure why, but I didn't realize we were also adding color support for non-Group blocks — so exciting! Are we planning on adding some padding to any block with .has-background? For example:

As a side note, playing around with this makes me think we should add an explicit default color button on the color sheets so the user can "reset" back to the default. Perhaps at the bottom right of the sheet like so? // cc @lukewalczak

@geriux
Copy link
Member Author

geriux commented Oct 14, 2020

Hey @iamthomasbishop 👋

This looks great! Not sure why, but I didn't realize we were also adding color support for non-Group blocks — so exciting! Are we planning on adding some padding to any block with .has-background? For example:

Well, when I activated it for Groups I saw those were working too so I didn't limit this feature for Groups just yet.

I just added paddings for those as well, can you check and let me know if it works as expected?

As a side note, playing around with this makes me think we should add an explicit default color button on the color sheets so the user can "reset" back to the default. Perhaps at the bottom right of the sheet like so?

Yeah I saw we might need that when I was testing and I couldn't remove any colors =D what do you think?:

Thanks for the feedback and for testing! I updated the test build with the latest changes.

@iamthomasbishop
Copy link

@geriux Thanks for the updated build and the quick turn-around!

Yeah I saw we might need that when I was testing and I couldn't remove any colors =D what do you think?:

Positioning looks good, but I think "Reset" or "Use default" for the label might be more appropriate. I also think we might want to keep the user on that same sheet after they've pressed the clear button, although that might just be a personal preference.

I just added paddings for those as well, can you check and let me know if it works as expected?

Paddings work as I would expect. Nice work!


One thing I wanted to raise — I am concerned about the side-effects WRT light vs. dark modes. For example, let's say I have dark mode enabled. If I change the background of a Group to dark gray, it'll look fine in the editor in dark mode because the base text color is white. However, if I preview it, I will see that the output is black text because the theme's base text color is black. Here's what I mean:

Editor Preview

I think if we had a mechanism to calculate color contrast and adjust the color of an element based on the ratio between it and another element's color (i.e. text color vs background color), we would be in great shape. But as it stands, we'll be stuck in the middle — and I'm not sure if it's a good idea to ship in this state.

Another thing that might help is if we can read and apply the theme's base color values (likely with global styles?), but until then we'll need to figure out a way to support both light and dark modes dynamically. I believe the web has a mechanism for auto-converting the text color based on the color behind it, but they also have a color contrast mechanism that alerts the user when the color contrast ratio between two colors isn't sufficient — perhaps we can utilize these in some way?

@kyleaparker
Copy link

I've been trying to edit some of the homepage layout designs on this build to see how they look with the new colour settings and the page seems to freeze each time, I have been going back and forth between the mobile and web editor so it may be related to that issue? The app is also crashing when I try to add the spacer block to any post/page. I can send more details about the content on the homepages if you need :)

@geriux
Copy link
Member Author

geriux commented Oct 16, 2020

Hey @iamthomasbishop thanks for giving it another test 👋

Positioning looks good, but I think "Reset" or "Use default" for the label might be more appropriate. I also think we might want to keep the user on that same sheet after they've pressed the clear button, although that might just be a personal preference.

Sounds good! I'll change it to "Reset" and keep the user on the same sheet.

Paddings work as I would expect. Nice work!

Yay!

I think if we had a mechanism to calculate color contrast and adjust the color of an element based on the ratio between it and another element's color (i.e. text color vs background color), we would be in great shape. But as it stands, we'll be stuck in the middle — and I'm not sure if it's a good idea to ship in this state.

Another thing that might help is if we can read and apply the theme's base color values (likely with global styles?), but until then we'll need to figure out a way to support both light and dark modes dynamically. I believe the web has a mechanism for auto-converting the text color based on the color behind it, but they also have a color contrast mechanism that alerts the user when the color contrast ratio between two colors isn't sufficient — perhaps we can utilize these in some way?

The thing is we are still missing information from the theme like the default text color, or background. What we currently have is all of the colors the theme uses but even with that, we don't really know what color to pick. Of course, we can compare the background color with the colors from the theme and pick the light color if the background is dark but it might have different results from web.

What web does is just using the CSS classes from the theme and applying the text colors for each background. As of today, we don't have a way to get that.

Regarding the color contrast mechanism, we could use that but we need both background and text color to compare. If the user doesn't select a text color we wouldn't be able to know if the background color is right for the theme text color.

If we don't want to ship this like this, we could disable the color picker unless a block already has colors set. So for layouts, they could tweak them. But if they create a new block there won't be an option to customize colors.

To be honest (Light mode / Dark mode) will always be an issue with blocks with custom colors =(

@geriux
Copy link
Member Author

geriux commented Oct 16, 2020

Hey @kyleaparker 👋

I've been trying to edit some of the homepage layout designs on this build to see how they look with the new colour settings and the page seems to freeze each time, I have been going back and forth between the mobile and web editor so it may be related to that issue? The app is also crashing when I try to add the spacer block to any post/page. I can send more details about the content on the homepages if you need :)

So sorry for that, we had recent issues that broke some blocks. I'll update the build with the fixes.

Thanks for testing!

@iamthomasbishop
Copy link

@geriux thanks for the context, really great info.

What we currently have is all of the colors the theme uses but even with that, we don't really know what color to pick

That's a good point. I hope in the future (via global styles, perhaps) we will be able to receive some registered color properties straight from the theme, but until then it seems like we're stuck.

If we don't want to ship this like this, we could disable the color picker unless a block already has colors set. So for layouts, they could tweak them. But if they create a new block there won't be an option to customize colors.

I think that's an option (albeit a "nuclear" one), but let's try to think about some alternatives before going there.

To be honest (Light mode / Dark mode) will always be an issue with blocks with custom colors =(

We can move this discussion to another ticket if necessary, especially if we decide on a more robust approach, but I wanted to note a couple of ideas that might be worth considering in case it sparks ideas for a quick solution. Some of these are straight forward, and others conceptual departures from the current approach, but we need to come up with something until we have global styles or similar access to the theme's various properties.

  • Option A: Alert the user (in the color settings bottom sheet or via a dialog/alert) that colors may not match up, especially when they have the default value applied, so they're aware of a potential mismatch.

    • This is probably the most straight forward in terms of implementation, but opens some potentially confusion, especially if the user doesn't read the messaging (let's be honest, most users don't read this type of messaging 🤷‍♂️).
  • Option B: Upon opening the editor, present the user with an explicit choice between light mode and dark mode ("Does your site use a light or dark theme?").

    • Based on that selection, we display the canvas as such — note: the editor chrome would follow the system appearance setting — "only" the canvas contents (blocks and their contents) would be affected by this. We could also allow them to override this setting in the editor-level ••• menu, but we'd likely want to warn about the potential side-effects.
    • Question on this point: I know the WP.com theme directory has a filter for style, so I wonder if we're able to default to light/dark based on a property/tag attached to the theme?
  • Option C: Force/default to light mode.

    • This is sorta a nuclear option, but would simplify things a lot for most users. We could keep dark mode as an option, but it would need to be turned on manually. The problem is that it assumes that most users have light-background themes — an assumption that AFAIK we can't back up quantitatively. Also, even if most themes have light backgrounds, it is not always a binary thing — any give page or post can have sections with varying background/text colors. There are probably other blindspots to this approach, but it came up in a team discussion yesterday. // cc @mattmiklic @kyleaparker
  • Your ideas here: If you have other ideas (yes, you!), please feel free to share! 😄

// cc @maxme any ideas re: ⬆️ ?

@geriux geriux removed the request for review from ellatrix November 6, 2020 08:11
@geriux
Copy link
Member Author

geriux commented Nov 11, 2020

Hey @iamthomasbishop 👋 I created a new build with the fix for the extra bottom padding in Group blocks with a background color. Let me know if you find any other issues. Thanks for testing!

@iamthomasbishop
Copy link

Thanks @geriux! That padding issue looks to be fixed! 👍

@geriux
Copy link
Member Author

geriux commented Nov 17, 2020

Hey @dratwas 👋 I've updated the code to disable the Color settings for these blocks, so this PR will only focus only on rendering the colors. Would you mind giving it another review when you can? I also created new builds to test.

Thank you!

@geriux geriux requested a review from dratwas November 18, 2020 12:31
@geriux geriux requested a review from dratwas November 19, 2020 09:19
Copy link
Contributor

@dratwas dratwas left a comment

Choose a reason for hiding this comment

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

Tested it on iOS and Android and everything works well. Great job @geriux 🎉

@geriux geriux merged commit 8df048c into master Nov 20, 2020
@geriux geriux deleted the rnmobile/feature/group-background-color branch November 20, 2020 08:24
@github-actions github-actions bot added this to the Gutenberg 9.5 milestone Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants