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

Refactor heading block to share more code with web version. #20745

Merged
merged 15 commits into from
Mar 25, 2020

Conversation

SergioEstevao
Copy link
Contributor

@SergioEstevao SergioEstevao commented Mar 9, 2020

Description

This PR refactors the heading block to share the edit function with the web version. On the process, it adds the align button to the header block in mobile.
It also reduces the number of headers available on the block toolbar in order to make the align buttons visible without the need for scrolling.

The only issue that I have is the way it shows the extra headers level on the Block setting modal

@iamthomasbishop Should we convert this to another type of setting, that looks better on mobile?

We now have an implementation of the dropdown menu in mobile that uses a bottom sheet to show the options available.

How has this been tested?

This can be tested on GB-mobile using this PR: wordpress-mobile/gutenberg-mobile#1990

Screenshots

Screenshot 2020-03-09 at 21 10 13

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.

@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 9, 2020
@github-actions
Copy link

github-actions bot commented Mar 9, 2020

Size Change: +216 B (0%)

Total Size: 860 kB

Filename Size Change
build/block-editor/index.js 102 kB -17 B (0%)
build/block-editor/style-rtl.css 11 kB +47 B (0%)
build/block-editor/style.css 11 kB +48 B (0%)
build/block-library/index.js 110 kB -20 B (0%)
build/block-library/style-rtl.css 7.44 kB +5 B (0%)
build/block-library/style.css 7.45 kB +5 B (0%)
build/components/index.js 191 kB +148 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 998 B 0 B
build/annotations/index.js 3.43 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-library/editor-rtl.css 7.22 kB 0 B
build/block-library/editor.css 7.23 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/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.6 kB 0 B
build/data-controls/index.js 1.04 kB 0 B
build/data/index.js 8.25 kB 0 B
build/date/index.js 5.37 kB 0 B
build/deprecated/index.js 771 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.06 kB 0 B
build/edit-post/index.js 91.2 kB 0 B
build/edit-post/style-rtl.css 8.47 kB 0 B
build/edit-post/style.css 8.46 kB 0 B
build/edit-site/index.js 6.72 kB 0 B
build/edit-site/style-rtl.css 2.88 kB 0 B
build/edit-site/style.css 2.88 kB 0 B
build/edit-widgets/index.js 4.43 kB 0 B
build/edit-widgets/style-rtl.css 2.58 kB 0 B
build/edit-widgets/style.css 2.58 kB 0 B
build/editor/editor-styles-rtl.css 428 B 0 B
build/editor/editor-styles.css 431 B 0 B
build/editor/index.js 43.8 kB 0 B
build/editor/style-rtl.css 4 kB 0 B
build/editor/style.css 3.98 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 622 B 0 B
build/i18n/index.js 3.49 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.69 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 781 B 0 B
build/redux-routine/index.js 2.84 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.27 kB 0 B
build/url/index.js 4.01 kB 0 B
build/viewport/index.js 1.61 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@@ -54,17 +54,19 @@ function HeadingEdit( {
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
isCollapsed={ Platform.OS === 'web' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do mobile toolbars support isCollapsed prop? Wht happens if we keep it true for mobile too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't show., it looks collapsed is equivalent to hidden in mobile.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should update the toolbar implementation to just ignore that prop instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can update the code for the native ToolbarGroupCollapsed to simple do the same as the non-collapsed version, until we get a proper implementation of a collapsed toolbar for mobile.

@@ -81,7 +83,9 @@ function HeadingEdit( {
<RichText
ref={ ref }
identifier="content"
tagName={ Block[ tagName ] }
tagName={
Platform.OS === 'web' ? Block[ tagName ] : tagName
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Block component should have an equivalent in native. This is going to become a central component to write blocks. Ideally all new blocks use it. cc @ellatrix

Copy link
Member

Choose a reason for hiding this comment

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

Yes, ideally native has a Block component too. I'm not sure what it will take there. I don't know enough about the native side, but happy to collaborate with someone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm working on to have an equivalent ( more a mock at this stage) on this PR: #20772

Will update this PR when the above is merged in.

@iamthomasbishop
Copy link

iamthomasbishop commented Mar 11, 2020

Should we convert this to another type of setting, that looks better on mobile?

@SergioEstevao I know the web extracts the heading levels in their entirety into the inspector, but I’ve always felt this was odd, especially when ported as-is to mobile. I think these should all be inside the block toolbar, and while I understand there is reasonable rationale for not surfacing H1s, I don’t love the idea of losing H5 and H6 in the toolbar.

Maybe this is a good opportunity to consider tackling collapsible groups for things like this (also for alignment controls, etc). I remember having some earlier discussions on this issue, but can’t seem to find that discussion atm. I’ll try to find it tomorrow and lay out a few rough sketches as well to demonstrate what the potential paths are.

@SergioEstevao
Copy link
Contributor Author

I don’t love the idea of losing H5 and H6 in the toolbar.

@iamthomasbishop One advantage of not having those is that it makes the alignment buttons visible on the toolbar, without need to scroll.

I think we have a global problem in the toolbar when we have more commands that are not in the screen, I don't think our users know that they can scroll horizontally on the toolbar to get more commands.

@iamthomasbishop
Copy link

One advantage of not having those is that it makes the alignment buttons visible on the toolbar, without need to scroll.

I think we have a global problem in the toolbar when we have more commands that are not in the screen, I don't think our users know that they can scroll horizontally on the toolbar to get more commands.

Both good points, although I think the scrolling concern is a more complex discussion that we should have separately. For now, implementing collapsible groups would mitigate the bulk of the cases where there is overflow so we should probably start there.

@SergioEstevao
Copy link
Contributor Author

For now, implementing collapsible groups would mitigate the bulk of the cases where there is overflow so we should probably start there.

I think this will be a broader work, and should be in a separate PR of this one. Meanwhile you prefer to have all header level in the toolbar and the block settings removed for mobile?

@iamthomasbishop
Copy link

iamthomasbishop commented Mar 11, 2020

I think this will be a broader work, and should be in a separate PR of this one.

@SergioEstevao Agree if we do further exploration, but before we push that work aside, let me propose what could be a nice temporary solution 😄 If it will require much additional effort, let me know and we will proceed with the solution mentioned below.

What do you think about doing something extremely simple like tap-to-cycle-headings in the toolbar? The heading buttons would be collapsed into a single button, and tapping it would cycle through heading levels. In theory, we could do the same thing with alignment, etc. Here's a quick and dirty prototype for example:


If you think the above would be more effort, for now, let's consider doing one of the following (in no particular order):

  • Keep toolbar as-is, showing H2-H6 (takes up lots of space)
  • Show all heading levels in the toolbar (takes up slightly more space)
  • Only show H2, H3, and H4 in the toolbar like web (takes up less space, but requires us to add a control in the settings sheet — not ideal for the user and additional work right now)
  • If we wanted to go super simple, we could even show an ActionSheet w/ the heading levels

Let me know if you have any preferences or questions @SergioEstevao.

@SergioEstevao
Copy link
Contributor Author

Only show H2, H3, and H4 in the toolbar like web (takes up less space, but requires us to add a control in the settings sheet — not ideal for the user and additional work right now)

@iamthomasbishop at the moment I have the above implemented, so it's exactly like the web.

I can try to give it a go on the rotating buttons idea, but I have a feeling that it will very confusing for our users...

@iamthomasbishop
Copy link

iamthomasbishop commented Mar 16, 2020

I can try to give it a go on the rotating buttons idea, but I have a feeling that it will very confusing for our users...

As a temporary measure (temp. because we will be establishing a more holistic solution at some point), what do you think about relying on a native component like the ActionSheet (on Android, we would use a BottomSheet)? Example:

I think this would be pretty intuitive for a user and allow us to apply the pattern to other groups, such as alignment, etc. in a way that doesn't seem very expensive.

@SergioEstevao
Copy link
Contributor Author

SergioEstevao commented Mar 20, 2020

I gave it a go and implement the dropdown like this:

What do you say @iamthomasbishop ?

We also hide the headings settings in RN because all of them are
available in the block controls.
@SergioEstevao
Copy link
Contributor Author

@iamthomasbishop I followed your feedback and here is the latest version:

I styled the dropdown menu like the block settings and I added the checkmark icon to show current option selected.

Comment on lines 131 to 139
renderContent={ ( { isOpen, onClose, ...props } ) => {
return (
<BottomSheet
hideHeader={ true }
isVisible={ isOpen }
onClose={ onClose }
>
{ isFunction( children ) ? children( props ) : null }
<PanelBody title={ label }>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use the Picker component to reuse functionality? (packages/components/src/mobile/picker/)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Picker is using an ActionSheet in iOS that doesn't translate to the interface we want here.
Or are you saying to refactor the Picker component to be like like this visually?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I thought we wanted the ActionSheet on iOS based on @iamthomasbishop 's comment.

Still, as this layout is already in place somewhere else, maybe we could add a prop to the picker component, something like useNativeActionSheet, and use the code currently from the Android implementation if that prop is false. Anyway, not sure if this is the best way to go or if it will make things unnecessary complicated.

@iamthomasbishop
Copy link

@SergioEstevao I think this is looking pretty solid, and if we do stay this route (BottomSheet), I have some suggestions in terms of design details to shore up. Per @etoledom's question re: actionSheets, I'm not opposed to staying with a more native component like ActionSheet on iOS, but I would assume we're going to need a BottomSheet for Android.

Feedback on BottomSheet as you've shown above:

  • Left margin of table row separators should be inset so that the lines start at the text label, not icon (56 on iOS, 72 on Android, IIRC)
  • Last table row shouldn’t have a separator-bottom
  • What are the margin values on the left/right sides of the sheet contents? It seems slightly more (24px?) than our default 16px
  • Can we make the checkmark icon our primary blue?
  • Can we add a separator on left and right side of the heading level button on the block toolbar?
  • Would you mind adding screenshots of what this looks like on Android after addressing the above notes?

@SergioEstevao
Copy link
Contributor Author

@iamthomasbishop I addressed all the issues you commented above, here is the end result:

Android

Toolbar Dropdown
screen-android-toolbar screen-android-dropdown

iOS light mode

Toolbar Dropdown
screen-ios-light-toolbar screen-ios-light-dropdown

iOS dark mode

Toolbar Dropdown
screen-ios-dark-toolbar screen-ios-dark-dropdown

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.

Nice work @SergioEstevao ! I had a couple thoughts, but otherwise I believe it's good to go 👍

@iamthomasbishop
Copy link

@SergioEstevao Looking good, just a couple minor requests to wrap up, and I've provided a visual example below:

  • Remove separators on Android
  • iOS text labels should sit at the 56px keyline (see example below)
  • The text labels on the rows seem to have an additional inset of ~4-8px. Can we remove this? (example)
  • I think we can make the section title more concise. Let's change Change heading level to Heading level.

Also likely not related to this PR, but if possible on Dark Mode, can we map the heading icons on the sheet and in the toolbar to the neutral gray? // cc @etoledom because I think you did some work on this recently, maybe you have a suggestion.

@SergioEstevao
Copy link
Contributor Author

@iamthomasbishop here is a screenshot with the updated iOS and Android versions:

iOS Android
Simulator Screen Shot - iPhone 11 Pro Max - 2020-03-25 at 17 18 51 screen

@iamthomasbishop
Copy link

Looks solid! Ship it! 🚀

@SergioEstevao SergioEstevao merged commit 6603642 into master Mar 25, 2020
@SergioEstevao SergioEstevao deleted the rnmobile/add_align_to_heading_block branch March 25, 2020 18:50
@github-actions github-actions bot added this to the Gutenberg 7.9 milestone Mar 25, 2020
@@ -97,6 +99,7 @@ function HeadingEdit( { attributes, setAttributes, mergeBlocks, onReplace } ) {
[ `has-text-align-${ align }` ]: align,
} ) }
placeholder={ placeholder || __( 'Write heading…' ) }
textAlign={ align }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only thing that's bothering me, in this PR. It's redundunt with the style prop in the web and it can easily get removed since it's not used at all in the web version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a recurrent issue we have on the mobile implementations. We don't have access to CSS so we end up recurring to extra props or container classes to do the work that CSS does. I'm all open to suggestions on how can we avoid these issues.
@mtias told me there is some approach being discussed about Global Styling approach using props for the components that could be a way to make the implementation less dependent of CSS styling.

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.

8 participants