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

[RNMobile] Support Theme Colors and Gradients #22197

Merged
merged 15 commits into from
Jun 3, 2020

Conversation

chipsnyder
Copy link
Contributor

@chipsnyder chipsnyder commented May 7, 2020

Fixes: wordpress-mobile/gutenberg-mobile#1744

Related PRs
gutenberg-mobile wordpress-mobile/gutenberg-mobile#2241
WordPress-Android wordpress-mobile/WordPress-Android#12041
WordPress-FluxC-Android wordpress-mobile/WordPress-FluxC-Android#1593
WordPress-iOS wordpress-mobile/WordPress-iOS#14085


Description

Adds support for theme defined colors and gradients to be injected into the editor from the mobile apps.

Colors can then be displayed by the same mechanisms that utilize the settings lookup for colors and gradients. This is currently supported on Cover and Button blocks

How has this been tested?

Note Atomic sites don't seem to support the wp/v2/themes API changes yet so this can be tested with a free site or a self-hosted site

To help with testing this theme can be added to a self-hosted site: twentytwenty-copy.zip

Colors

1.) Select a theme with custom colors (such as TwentyTwenty)
2.) Create a post with blocks that have a custom color set (such as Cover or Button)
3.) Load editor on mobile

Expect to see the custom color on the block

Gradients

1.) Select a theme with custom gradients or add gradients to a theme
2.) Create a post with blocks that have a custom gradient set (such as Cover or Button)
3.) Load editor on mobile

Expect to see the custom gradient on the block

No Wifi

1.) Set up blocks for custom color and gradient
2.) View the post on mobile to cache the theme
3.) Turn off wifi to the device
4.) Reload the editor

Expect to see the custom colors on the blocks

No Wifi - Force kill the app

1.) Set up blocks for custom color and gradient
2.) View the post on mobile to cache the theme
3.) Turn off wifi to the device
4.) Stop the app from running in the background
5.) Reload the editor

Expect to see the custom colors on the blocks

Screenshots

Types of changes

New feature: Theme support

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.

@chipsnyder chipsnyder added this to the Future milestone May 7, 2020
@github-actions
Copy link

github-actions bot commented May 7, 2020

Size Change: +4.34 kB (0%)

Total Size: 1.12 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B
build/annotations/index.js 3.62 kB +2 B (0%)
build/autop/index.js 2.82 kB -2 B (0%)
build/block-directory/index.js 6.74 kB +263 B (3%)
build/block-directory/style-rtl.css 892 B +105 B (11%) ⚠️
build/block-directory/style.css 892 B +105 B (11%) ⚠️
build/block-editor/index.js 106 kB +323 B (0%)
build/block-editor/style-rtl.css 11.4 kB +12 B (0%)
build/block-editor/style.css 11.4 kB +12 B (0%)
build/block-library/index.js 126 kB +94 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB -1 B
build/block-serialization-spec-parser/index.js 3.1 kB -1 B
build/blocks/index.js 48.2 kB -3 B (0%)
build/components/index.js 193 kB +3.31 kB (1%)
build/components/style.css 19.5 kB +4 B (0%)
build/compose/index.js 9.32 kB +9 B (0%)
build/core-data/index.js 11.4 kB -3 B (0%)
build/data-controls/index.js 1.29 kB +1 B
build/data/index.js 8.44 kB +14 B (0%)
build/date/index.js 5.47 kB +3 B (0%)
build/deprecated/index.js 771 B -1 B
build/edit-navigation/index.js 8.25 kB +4 B (0%)
build/edit-post/index.js 302 kB -1 B
build/edit-site/index.js 14.1 kB +24 B (0%)
build/edit-widgets/index.js 8.83 kB +20 B (0%)
build/editor/index.js 44.7 kB +46 B (0%)
build/element/index.js 4.65 kB +1 B
build/format-library/index.js 7.72 kB +5 B (0%)
build/hooks/index.js 2.13 kB +1 B
build/html-entities/index.js 621 B -1 B
build/keyboard-shortcuts/index.js 2.51 kB -2 B (0%)
build/keycodes/index.js 1.94 kB +1 B
build/list-reusable-blocks/index.js 3.12 kB -2 B (0%)
build/media-utils/index.js 5.29 kB +1 B
build/notices/index.js 1.79 kB +1 B
build/nux/index.js 3.4 kB -4 B (0%)
build/plugins/index.js 2.56 kB -3 B (0%)
build/primitives/index.js 1.5 kB +1 B
build/redux-routine/index.js 2.85 kB -2 B (0%)
build/rich-text/index.js 14.8 kB -1 B
build/server-side-render/index.js 2.67 kB -1 B
build/url/index.js 4.02 kB -1 B
build/viewport/index.js 1.85 kB +7 B (0%)
build/wordcount/index.js 1.17 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/api-fetch/index.js 3.4 kB 0 B
build/blob/index.js 620 B 0 B
build/block-library/editor-rtl.css 7.87 kB 0 B
build/block-library/editor.css 7.88 kB 0 B
build/block-library/style-rtl.css 7.69 kB 0 B
build/block-library/style.css 7.68 kB 0 B
build/block-library/theme-rtl.css 684 B 0 B
build/block-library/theme.css 686 B 0 B
build/components/style-rtl.css 19.5 kB 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.11 kB 0 B
build/edit-navigation/style-rtl.css 878 B 0 B
build/edit-navigation/style.css 876 B 0 B
build/edit-post/style-rtl.css 5.43 kB 0 B
build/edit-post/style.css 5.43 kB 0 B
build/edit-site/style-rtl.css 2.96 kB 0 B
build/edit-site/style.css 2.96 kB 0 B
build/edit-widgets/style-rtl.css 2.4 kB 0 B
build/edit-widgets/style.css 2.4 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/style-rtl.css 4.26 kB 0 B
build/editor/style.css 4.27 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/priority-queue/index.js 789 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

@chipsnyder chipsnyder added the Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) label May 8, 2020
@chipsnyder
Copy link
Contributor Author

@dratwas same thing here as the question here whenever you have a minute

@chipsnyder chipsnyder marked this pull request as ready for review May 8, 2020 19:18
@dratwas
Copy link
Contributor

dratwas commented May 11, 2020

@chipsnyder I'm afraid that it will not work with the color picker since we use the defaults from block-editor here - https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/block-settings/container.native.js#L14

I think that the colors from settings should be used in the color-picker too. You should be able to test that since this feature is merged already. Just open button settings and check if the palette is correct.

@chipsnyder
Copy link
Contributor Author

Thanks for the guidance @dratwas. I should be able to refactor that to pull from the updated settings instead of from the default pre-loaded ones. I'll work on that adjustment now.

@chipsnyder
Copy link
Contributor Author

Tested and updated this for the color picker. Those changes are in place now
https://github.com/WordPress/gutenberg/pull/22197/files#diff-54b382c14de06585cb37a3dee03b803cR39

Instead of loading from Settings_Defaults I was able to just load in the updated settings

@pinarol
Copy link
Contributor

pinarol commented May 11, 2020

Is it possible to use the primary color of theme when we first create the button? Currently we are still using gray.

It can be worth exploring web side to find out how they decide which one is the primary color.

Linking @lukewalczak in case he might have an opinion since he developed the Button block.

@chipsnyder
Copy link
Contributor Author

It can be worth exploring web side to find out how they decide which one is the primary color.

This would probably be the main challenge but I'll do some digging and see what I can find.

@chipsnyder
Copy link
Contributor Author

Looking through the code and at the twenty-twenty theme, for buttons, it seems to default to what's defined in the theme's class wp-block-button__link.

Twenty-Twenty theme:

.editor-styles-wrapper .wp-block-button__link,
.editor-styles-wrapper .wp-block-file__button {
	background: #cd2653;
	border-radius: 0;
	color: #fff;
	font-size: 15px;
	font-weight: 600;
	letter-spacing: 0.0333em;
	line-height: 1.25;
	padding: 1.1em 1.44em;
	text-transform: uppercase;
}

So for this case it will display #cd2653 which is the Accent Color. This also happens to be the first color in the list of colors but that's just a coincidence.

We could default to displaying the first color set in editor-color-palette without any trouble. But this would be very theme dependent that those settings are coordinated.

@lukewalczak
Copy link
Member

I agree with @chipsnyder, Button should display accent color, which should be also the first color in palette.

@pinarol
Copy link
Contributor

pinarol commented May 12, 2020

The case where Button is created on mobile is easier to resolve as far as I see, we can initially set the first color in the palette to the block attributes that way it'll be displayed correctly on web as well.

Let's decide what to do if the Button is created on web without any color info. What should mobile display? @iamthomasbishop was mentioning we could show a warning message somewhere in this case. Can you describe where that message could be @iamthomasbishop ?

In addition to the warning message which color do you think we should fallback to? @iamthomasbishop

  1. Gray color we currently have(it'll make it more explicit that the color can not be resolved)
  2. 1st color of the palette since it looks like for most of the cases it matches the web, it is just not guaranteed. (but we'll have a warning message? 🤷‍♀️ )

@pinarol
Copy link
Contributor

pinarol commented May 12, 2020

@youknowriad We can really use your opinion on this. Do you think it makes sense to create Button blocks with an initial palette color on web? Currently they have no color info that mobile can render until somebody sets a color for them.

@youknowriad
Copy link
Contributor

We can really use your opinion on this. Do you think it makes sense to create Button blocks with an initial palette color on web?

I'm not certain. Themes might have a default color and a palette to change it. It's all theme specific. I guess you can't load the default CSS on mobile which makes this hard. Maybe we can accept that mobile apps are not wysiwyg and just use the default gray buttons. It's not ideal but I suspect that this issue will come up for any block and not just for the background color which means trying to solve it in adhoc way won't get us that far

@pinarol
Copy link
Contributor

pinarol commented May 13, 2020

Thanks for the context @youknowriad .

@pinarol
Copy link
Contributor

pinarol commented May 20, 2020

I guess you can't load the default CSS on mobile which makes this hard.

@youknowriad one more question on this, what do you mean by default CSS here?

@youknowriad
Copy link
Contributor

I mean the theme's CSS that style button for instance. (editor styles)

@chipsnyder
Copy link
Contributor Author

I opened a new issue for the button enhancement (wordpress-mobile/gutenberg-mobile#2278) so that we can come up with our path forward and continue to discuss that in a different thread.

@chipsnyder
Copy link
Contributor Author

No new updates were needed here for the Android side so I went ahead and updated this with master, @dratwas can you take a look for me?

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.

Good job @chipsnyder 🚀

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.

None yet

5 participants