-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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] Global styles provider #21637
Conversation
Size Change: -793 B (0%) Total Size: 816 kB
ℹ️ View Unchanged
|
...oldStyle, | ||
color: style && style.color && style.color.text, | ||
...style, | ||
color: wrapperProps?.style?.color || globalStyle?.color, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this line I'm assuming that at the moment color
is the only global style and wrapper prop that we have available in mobile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ATM we support color, backgroundColor, and gradient. Other props will be added when they land on the web because we use the same logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SergioEstevao
I have checked that and we have 3 kinds of styles in wrapper props at this moment.
- lineHeight -
__experimentalLineHeight
- fontSize -
__experimentalFontSize
- color/backgroundColor/gradient -
__experimentalColor
Unfortunately, it seems like the lineHeight
doesn't work in the rich-text at all. The fontSize works only for a paragraph block but not for heading block - It's related to thetagName
that is passed to the rich-text
.
So, we have these props already in the wrapperProps
but our edit
implementations don't use them yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BackgroundColor does not work in the Paragraph block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the backgroundColor works. I should mention that in my prev comment that I refactored it a bit :)
packages/block-editor/src/components/block-list/block.native.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking and working great! Thanks for this!
Thank you @dratwas for the PR! This is a tough one but I think you are in the right direction. First of all I think we should adopt the terminology in the main issue and probably not use the term "globalStyle", because it seems like what we have here is only the container level style, or merged style? Maybe the context name is fine to include "global" but the prop name can benefit from changing. Other than that, I have some general questions:
|
@pinarol thanks for your review :)
I tried something like this just to check how it would look like but had issues with block borders. They are cut by an inner block background. I tried to change The effect is different when I moved the background color a bit deeper (View that is always inside borders since they are positioned absolutely relative to this view). Borders are not cut but it looks a bit weird. There is also an issue with a button component because the `backgroundColor` should be applied to the button, not its wrapper.
I think that it could be added on the block level - this is the best option - but the bordering needs to be fixed if we want the full-width backgroundColor
By multiple styles, you mean
It is exactly the thing why we need I used On the screen below i set background color in group but it's not applied to the button (it's expected result) |
Thanks for trying! I wonder if it is possible to cut a hole inside the border view so the rest becomes clickable? Just asking, no need to dive deep into this at the moment.
Does it look different than what we already have on media-text? And I was wondering how would that look if we applied the background color on Group block with the method you use for Media-Text? It might look a bit weird but if you think we don't have any indentation inside inner blocks it's kind of a natural result. I checked how this works on web and I am a bit surprised about the UX there, because when you add a background color it adds indentation as well. I don't think we can do the same thing in the narrow screen. 👆 Here are 2 Paragraph blocks that are both on top level. It simply adds padding when you add background color, and the interesting thing is, the web output result also has padding. I am noting this to ask in the editor chat, curious if this is a long term approach.
OK I think this is about the current architecture of global styles. I find it a bit confusing to use the universal Background color palette for button color as well. Imho it should be represented by a different color section in the settings. Because the button color is simply not a background color, and one should be able to set the Button colors on a global level as well. But since the GSS is still work in progress it is early to make a judgement. I think what we have is enough for now. |
|
||
return ( | ||
( style && style.color && style.color.background ) || | ||
wrapperProps?.style?.backgroundColor || | ||
backgroundColor.color || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need backgroundColor.color
? Is it for backward compatibility ? If so, it could be good to drop an inline comment to explain why we still need that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need that for supporting colors that are not custom ones and are set from the color palette. Let me check if i could merge them in the block.native.js
and we could remove it from here. Additional pros of this is that will be applied for all blocks (like media-text etc)
Edit: I think we should leave it as it is because i would need to refactor with-colors to make it work.
I added an inline comment
Unfortunately, I'm not sure if there is an easy way to achieve that.
It looks the same.
Yeah, i observed the same and was wondering if we should follow that rule but i remember that at some point, we decided to remove that indentation.
🙏 |
OK, I'll open a separate issue to track this, we can consider adding some padding as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates, this looks good to me! 🎉
Description
This is a very first thing from wordpress-mobile/gutenberg-mobile#2147
This PR introduces a global style - block-level support mechanism to the mobile.
Terms:
wrapperStyles
- styles that are applied on the block levelglobalStyles
- styles that are passed down through editor and are overridden by block-level onesRecently a lot of changes have been made in terms of
custom colors
and style in general.The color and the background color is added to the wrapper on the web. (other styles are added or will be added soon):
In this PR I use
getEditWrapperProps
to get wrapper styles and I pass them to the block component. Thanks to that we can getbackground
orcolor
(and other props like line-height) of the block (if set) fromwrapperProps
like here - https://github.com/WordPress/gutenberg/pull/21637/files#diff-b27dffd07183b62521c86ec1d84cad1dR226In addition, I added
GlobalStylesContext
to pass styles down to the nested blocks and override needed values on the block level. So, we can get correct styles wherever we use theGlobalStylesContext.Consumer
.We should pass flatten Theme (global) > User (edited global styles) > Specific styles per post as the initial value and then the style will be updated on the block level by concatenating global styles and wrapper style. On the web, these values are set as inline styles and are inherited by blocks out of the box so it's enough to set them there.
I'm not sure where it should be done on mobile. In the current implementation, I do that in
block.native.js
https://github.com/WordPress/gutenberg/pull/21637/files#diff-42b230fc8f23c8ce7322e2d6ff6d5df6R63-R66That means the styles are updated on the block level for all blocks with no exceptions and in the edit file of the block we have correct values.
The second place where it could be done is an edit file of each block that has inner blocks. Thanks to that we could decide if that block should override global styles for its inner block. It is a different behavior than the web so I decided to go with the first option. This approach would also require external developers of 3rd party block to think about that if they want to override styles or not.
In both approaches, we have to keep in mind that sometimes we shouldn't apply the global styles as a fallback.
Example:
Let's say we have a group block where we set the background color to red. The red background color shouldn't be applied in a button block that is inside that group. So, in that case, we should set the background only when is set in
wrapperProps
of that button block.How has this been tested?
Screenshots
Web
Mobile
Types of changes
Introduction of the mechanism that allows passing styles to the inner blocks and use
getEditWrapperProps
to get block-level styles. Global > Block > Block > ... (Global > Group > Group > Paragraph)Checklist: