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

Add color hooks for the mobile implementation. #21257

Merged
merged 10 commits into from
Mar 31, 2020

Conversation

SergioEstevao
Copy link
Contributor

@SergioEstevao SergioEstevao commented Mar 30, 2020

Description

Updates the mobile implementation to support the new colors hooks, effect and filters.

How has this been tested?

Screenshots

Types of changes

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.

@github-actions
Copy link

github-actions bot commented Mar 30, 2020

Size Change: +48 B (0%)

Total Size: 866 kB

Filename Size Change
build/block-editor/index.js 102 kB +27 B (0%)
build/block-library/index.js 111 kB +21 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 998 B 0 B
build/annotations/index.js 3.45 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-editor/style-rtl.css 11 kB 0 B
build/block-editor/style.css 11 kB 0 B
build/block-library/editor-rtl.css 7.21 kB 0 B
build/block-library/editor.css 7.21 kB 0 B
build/block-library/style-rtl.css 7.5 kB 0 B
build/block-library/style.css 7.51 kB 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 57.5 kB 0 B
build/components/index.js 191 kB 0 B
build/components/style-rtl.css 15.8 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 6.21 kB 0 B
build/core-data/index.js 10.7 kB 0 B
build/data-controls/index.js 1.04 kB 0 B
build/data/index.js 8.26 kB 0 B
build/date/index.js 5.36 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.05 kB 0 B
build/edit-navigation/index.js 2.4 kB 0 B
build/edit-navigation/style-rtl.css 95 B 0 B
build/edit-navigation/style.css 95 B 0 B
build/edit-post/index.js 92.3 kB 0 B
build/edit-post/style-rtl.css 8.35 kB 0 B
build/edit-post/style.css 8.34 kB 0 B
build/edit-site/index.js 9.04 kB 0 B
build/edit-site/style-rtl.css 3.41 kB 0 B
build/edit-site/style.css 3.41 kB 0 B
build/edit-widgets/index.js 4.43 kB 0 B
build/edit-widgets/style-rtl.css 2.57 kB 0 B
build/edit-widgets/style.css 2.57 kB 0 B
build/editor/editor-styles-rtl.css 423 B 0 B
build/editor/editor-styles.css 426 B 0 B
build/editor/index.js 42.8 kB 0 B
build/editor/style-rtl.css 3.38 kB 0 B
build/editor/style.css 3.38 kB 0 B
build/element/index.js 4.44 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 6.95 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 1.93 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keyboard-shortcuts/index.js 2.3 kB 0 B
build/keycodes/index.js 1.7 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 4.84 kB 0 B
build/notices/index.js 1.57 kB 0 B
build/nux/index.js 3.01 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.54 kB 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 780 B 0 B
build/redux-routine/index.js 2.83 kB 0 B
build/rich-text/index.js 14.5 kB 0 B
build/server-side-render/index.js 2.55 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 kB 0 B
build/url/index.js 4.01 kB 0 B
build/viewport/index.js 1.6 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@youknowriad
Copy link
Contributor

I was actually trying to setup a mobile env to do this. You saved me a full day of hassle downloading xcode, android studio... :) Thanks

@SergioEstevao
Copy link
Contributor Author

I was actually trying to setup a mobile env to do this. You saved me a full day of hassle downloading xcode, android studio... :) Thanks

I think you should do it anyway :)

@SergioEstevao SergioEstevao 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 Mar 30, 2020
@@ -7,7 +7,6 @@ import {
AlignmentToolbar,
Copy link
Contributor

Choose a reason for hiding this comment

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

The new hook is implemented in several blocks. I guess we might need similar removals in other blocks (heading, group, columns, media & text)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on how the block was implemented, for example heading now shares the same edit code as the web, so no changes needed.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

code wise, this looks good.

import InspectorControls from '../components/inspector-controls';
import { getBlockDOMNode } from '../utils/dom';

export default function ColorPanel( { colorSettings, clientId } ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I this this should live in block-editor/src/components instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have so many color related components there that need some cleanup, maybe we should avoid a new reusable component there for now. Potentially the hooks/color could be a folder?

Copy link
Contributor

@Tug Tug left a comment

Choose a reason for hiding this comment

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

Code looks good.

Given that we're also missing those 2 lines on the native version of the block editor hooks:

import { AlignmentHookSettingsProvider } from './align';
import './anchor';

I wouldn't be surprised if we also had inconsistencies between web and mobile around those attributes.

@dratwas
Copy link
Contributor

dratwas commented Mar 30, 2020

Code looks good, however, I'm afraid of merging that since if the gutenberg-mobile will be released before the wordpress.com release, it will break custom colors in all paragraphs after the page is opened on mobile. So let's say the gutenberg-mobile is released with that change but the wordpress.com still uses the old version. The user creates the page on the web with custom colors in paragraphs, then opens the page on mobile and loses all colors on the web because mobile app will migrate custom colors to the new system.

@SergioEstevao
Copy link
Contributor Author

SergioEstevao commented Mar 30, 2020

Code looks good.

Given that we're also missing those 2 lines on the native version of the block editor hooks:

import { AlignmentHookSettingsProvider } from './align';
import './anchor';

I wouldn't be surprised if we also had inconsistencies between web and mobile around those attributes.

While I agree with you those changes look older and still don't have an impact on mobile, the only use of the AlignHookSettingProvider I see is in the Buttons block (not in Button)

@pinarol
Copy link
Contributor

pinarol commented Mar 30, 2020

Code looks good, however, I'm afraid of merging that since if the gutenberg-mobile will be released before the wordpress.com release,

No worries, the new release will ship with WP mobile app 14.6 which will be released at Apr 20th.

@pinarol
Copy link
Contributor

pinarol commented Mar 30, 2020

@SergioEstevao Could you explain a bit about real life implications of this PR? What are we fixing exactly? Are we just preventing the loss of the new style prop on mobile?

What else should we do to make color rendering work as it did before? see wordpress-mobile/gutenberg-mobile#2068

@Tug
Copy link
Contributor

Tug commented Mar 30, 2020

While I agree with you those changes look older and still don't have an impact on mobile, the only use of the AlignHookSettingProvider I see is in the Buttons block (not in Button)

I'm more concerned with the hooks registered in those 2 files. But then if we haven't noticed any unwanted behavior I guess we can investigate those separately 👍

@pinarol
Copy link
Contributor

pinarol commented Mar 30, 2020

We are using withColors in button, cover, group, media-text. Do we not need to update those blocks as well?

@SergioEstevao
Copy link
Contributor Author

@SergioEstevao Could you explain a bit about real-life implications of this PR? What are we fixing exactly? Are we just preventing the loss of the new style prop on mobile?
@pinarol
So the main changes on this PR are to update the code on the native side to be compatible with the new colour and style hooks. This was a major change done by the web side and we are updating the code to use it.

The change discarded the use of the TextColor HOC that I believe you were using to pass the colors down from blocks to the RichText component. The only simple way to update your code is to implement something similar to what TextColor was doing and use it on the native paragraph edit code.

Maybe @youknowriad as a better suggestion?

@youknowriad
Copy link
Contributor

youknowriad commented Mar 31, 2020

The only simple way to update your code is to implement something similar to what TextColor was doing and use it on the native paragraph edit code.

The "style" attribute is going to be something widely used across blocks in a very generic and defined way. It just generates CSS variables, I wonder if there's a way to "support" CSS variables on mobile somehow which would solve the issue for all these customizations?

const tagName = 'h' + level;

const styles = {
color: style && style.color && style.color.text
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this in a more generic way, in a hook or something because this will apply to all blocks with that flag enabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure we know how to do that. Could you maybe explain with some sample code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youknowriad can you help us with that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now the "style" prop is injected into the Block Wrapper using getEditWrapperProps in the hook for the web. Can we do the same for mobile to inject styles?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/hooks/color.js#L110-L116

The difference here would be that we should run the "save" logic in the "edit" one because the props will be different on mobile.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@youknowriad I don't think we are in a position in native to do this like that, we will need to change our components to always read from styles props and this is not happening at the moment. I think for now we should merge this PR as it is to solve our breakages and then try to do follow up PRs on updating our native code to better support this generic styles in a more generic way.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not suggesting it should be solved now but mking getEditWrapperProps work on mobile is key yes.

@pinarol
Copy link
Contributor

pinarol commented Mar 31, 2020

It just generates CSS variables, I wonder if there's a way to "support" CSS variables on mobile

We don't have a way to declare selectors and inherit styles from a generic place, we need to pass each style object to the component explicitly.

Copy link
Contributor

@pinarol pinarol left a comment

Choose a reason for hiding this comment

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

Color issues are fixed! Thank you all! @SergioEstevao @dratwas @Tug

Screen Shot 2020-03-31 at 13 53 51

# Conflicts:
#	packages/block-editor/src/hooks/color.js
@Tug
Copy link
Contributor

Tug commented Mar 31, 2020

@SergioEstevao I saw you merged master in (though we still have a conflict with packages/block-library/src/heading/edit.js).
Feel free to cherry pick 798c6f51015d81585ba4560e3a633b9f83741a50 which has the fix for the bottomsheet

# Conflicts:
#	packages/block-library/src/heading/edit.js
# Conflicts:
#	packages/block-library/src/heading/edit.js
@SergioEstevao SergioEstevao merged commit ddd3fff into master Mar 31, 2020
@SergioEstevao SergioEstevao deleted the rnmobile/fix_color_breakage branch March 31, 2020 14:30
@github-actions github-actions bot added this to the Gutenberg 7.9 milestone Mar 31, 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.

None yet

5 participants