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

Remove editor experience when using handheld devices #47

Merged
merged 12 commits into from
Sep 13, 2022

Conversation

renintw
Copy link
Contributor

@renintw renintw commented Sep 1, 2022

Fixes #46

The logic can also be placed in the following block to avoid running unnecessary logic, but we have to enqueue the required styles.

add_action(
'wp_enqueue_scripts',
function( $hook ) {
// Gutenberg requires the post-locking functions defined within:
// See `show_post_locked_dialog` and `get_post_metadata` filters below.
include_once ABSPATH . 'wp-admin/includes/post.php';
gutenberg_editor_scripts_and_styles( $hook );
}
);

Screencast

remove.editor.exp.on.mobile.mov

The font-weight of the heading and the border styles of the button are still off,
that's probably because they're no longer in the editor, so the class name editor-styles-wrapper doesn't exist anymore.
And the button style in the sandbox is different from the one in local env (sandbox has squared black border)

Do we want the styles to be exactly the same as the original ones?

@renintw renintw self-assigned this Sep 1, 2022
@StevenDufresne
Copy link
Collaborator

Right, it's missing all the editor-styles-wrapper classes. We need to figure out how to load what is returned from get_block_editor_theme_styles.

@tellyworth
Copy link

The mobile version might need some slight variations in content. That needn't necessarily be fixed in this PR, but it might be worth opening a new issue after fixing this one to decide what content changes are needed. (Perhaps the "Click around to explore" text)

@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 4690151 to 22a225b Compare September 5, 2022 19:16
'rest_preload_api_request',
array()
);
if ( wp_is_mobile() ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make this condition inside gutenberg_editor_scripts_and_styles since

  1. We're still rendering Gutenberg editor but in mobile version.
  2. Styles can be shared without duplicating them.

if ( wp_is_mobile() ) {
$block_editor_css = get_block_editor_theme_styles()[0]['css'];
wp_add_inline_style( 'wp-edit-post', $block_editor_css );
}
Copy link
Contributor Author

@renintw renintw Sep 5, 2022

Choose a reason for hiding this comment

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

It turns out this worked in the first place, except that it only worked on the sandbox,
locally the newly added styles would somehow be overridden and never show the expected layout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this have to be here? Can it be moved in theif ( wp_is_mobile() ) statement above.

Copy link
Contributor Author

@renintw renintw Sep 7, 2022

Choose a reason for hiding this comment

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

My idea was to put the styles together, but it's also ok to move into the if ( wp_is_mobile() ) statement above.
Done in Fix several issues when loading page.

@renintw
Copy link
Contributor Author

renintw commented Sep 5, 2022

Updated screencast (Styles fixed)

handheld.version.g.mp4

TODO

  1. Fix the shaking when loading the page.
  2. Adjust content to make it conform to the mobile context.

yarn.lock Outdated
@@ -2,524 +2,6114 @@
# yarn lockfile v1


"@kwsites/file-exists@^1.1.1":

Choose a reason for hiding this comment

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

I don't see any changes to package.json, should this have changed?

Copy link
Contributor Author

@renintw renintw Sep 5, 2022

Choose a reason for hiding this comment

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

It turns out that it has the same content as the one in the workspace. I took a further look and found that if we removed the "workspaces": [ "source/wp-content/themes/wporg-gutenberg" ] in source/wp-content/themes/wporg-gutenberg/package.json as well as its corresponding yarn.lock in the same folder and then yarn in source/wp-content/themes/wporg-gutenberg, the yarn.lock would only be generated in the root folder (the one we're looking at), and I'm thinking that this is the way workspace saves space from duplicating packages (by hoisting packages to workspace root). So perhaps we only need one yarn.lock here. Didn't have much experience with the workspace, please let me know if I understand it incorrectly.

Choose a reason for hiding this comment

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

Hmm the workspace setup confuses me a bit too, @StevenDufresne do we have a workspace setup for the theme in case one day we need a workspace for a plugin too? I've seen that in other repos

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, it needs some cleanup. The workspace declaration should be removed from the theme and the packages added from the root. We should probably open a new ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'll reset the commit and open a new ticket for it. Other than that, do you think this PR is good to go?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't appear like all the styles are loading properly, a few things I see:

  • Buttons have different border-radius
  • The footer has a huge space below it.

Copy link
Contributor Author

@renintw renintw Sep 6, 2022

Choose a reason for hiding this comment

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

Buttons have different border-radius

Which one you're referring to? I saw buttons on the sandbox having 2px border-radius, which is the same as production.

Sandbox
Screen Shot 2022-09-07 at 3 42 49 AM
Production
Screen Shot 2022-09-07 at 3 43 15 AM

The footer has a huge space below it.

Fixed.

It doesn't appear like all the styles are loading properly

The difference I spot is that the font-weight of h1 and h2 is 600 but not 400 (prod)
and the font-size of some p is smaller than prod.
I've found that the styles have already been imported but were overridden by styles that I can't really tell where they are from. But it can be fixed in a tricky way, I've tested it and it worked, but before really committing it, I'd like to know if there are other ideas for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

wp_is_mobile() = false wp_is_mobile() = true
Screen Shot 2022-09-07 at 12 14 17 PM Screen Shot 2022-09-07 at 12 11 39 PM
Screen Shot 2022-09-07 at 12 14 07 PM Screen Shot 2022-09-07 at 12 10 57 PM

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the best we can do is to enqueue a mobile style sheet that fixes the differences.

Additionally, the <body> tag needs a white background.

Copy link
Contributor Author

@renintw renintw Sep 7, 2022

Choose a reason for hiding this comment

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

I don't see the grey background or the space between the line and the button. (Not sure what makes the differences between our layouts, but could you try again with new commits and see if they are still there, thanks.)
And for the different border-radius of the button, I only saw it locally, not on the sandbox.
Here's the fix for it, now the local would also show the same border-radius as the sandbox and prod.

wp_is_mobile() = true

Sandbox Local Prod
Screen Shot 2022-09-08 at 3 39 26 AM Screen Shot 2022-09-08 at 4 21 08 AM Screen Shot 2022-09-08 at 3 39 52 AM Screen Shot 2022-09-08 at 4 21 15 AM Screen Shot 2022-09-08 at 3 41 06 AM Screen Shot 2022-09-08 at 4 21 52 AM

wp_is_mobile() = false

Sandbox Local Prod
Screen Shot 2022-09-08 at 4 15 18 AM Screen Shot 2022-09-08 at 4 15 51 AM Screen Shot 2022-09-08 at 4 16 44 AM

@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 22a225b to 6f79569 Compare September 6, 2022 17:14
@StevenDufresne
Copy link
Collaborator

Apart from the styles, how do you think we can deal with this copy that appears on the desktop view:

"This page was built with blocks — pieces of content that you can move around. Click around to explore them."

if ( wp_is_mobile() ) {
$block_editor_css = get_block_editor_theme_styles()[0]['css'];
wp_add_inline_style( 'wp-edit-post', $block_editor_css );
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this have to be here? Can it be moved in theif ( wp_is_mobile() ) statement above.

resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) );
$init_script = <<<JS
( function() {
window._wpLoadBlockEditor = new Promise( function( resolve ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be loaded on mobile?.. along with the $script block below...

Copy link
Contributor Author

@renintw renintw Sep 7, 2022

Choose a reason for hiding this comment

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

I don't think they are loaded on mobile. (or you're saying that they should be loaded?)

I think it's the format making it hard to read, and the JS part is the one making it unclear (You can see that originally it is aligned to the left side without the indent, and I was thinking that it might be made that way on purpose at first so I didn't add one more indent when including else into the logic). I'll add one first to make the format clearer, and please let me know if I shouldn't do so.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, yeah my code collapse function got confused. Thanks. No changes needed.

Copy link
Contributor Author

@renintw renintw Sep 7, 2022

Choose a reason for hiding this comment

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

Would the extra indent affect anything? da207bb If not, I'm tempted to keep it as is as the format looks more readable.

@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 8ff9f50 to 1c6f594 Compare September 7, 2022 20:06
'wp-edit-post',
$block_editor_css . 'body,p{font-size:inherit;} h1,h2,h3,h4,h5,h6{font-weight:inherit;} .wp-block-button__link{border-radius: var(--wp--custom--button--border--radius);}'
);
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing changed to logic starting from here to the end of the else block.

@renintw
Copy link
Contributor Author

renintw commented Sep 7, 2022

Apart from the styles, how do you think we can deal with this copy that appears on the desktop view:
"This page was built with blocks — pieces of content that you can move around. Click around to explore them."

I'm thinking of only changing Click around to explore them.
Maybe append something like (only available on Desktop) to it?
Or Explore the whole features on Desktop.

@StevenDufresne
Copy link
Collaborator

Apart from the styles, how do you think we can deal with this copy that appears on the desktop view:
"This page was built with blocks — pieces of content that you can move around. Click around to explore them."

I'm thinking of only changing Click around to explore them. Maybe append something like (only available on Desktop) to it? Or Explore the whole features on Desktop.

I think just removing Click around to explore them. is good enough for now. We can ask for feedback later.

@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 23f9881 to e9da89f Compare September 7, 2022 23:31
@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 845ab46 to 3ddcb55 Compare September 12, 2022 11:30
The styles added in this commit primarily make the layout in the local env consistent with the sandbox and the prod.
(i.e., the styles on the sandbox and the prod are already aligned)
@renintw renintw force-pushed the fix/remove-editor-experience-when-using-mobile branch from 3ddcb55 to 37fb88c Compare September 12, 2022 11:52
@@ -24,7 +24,18 @@ h3 {

.wp-block-button__link {
border-radius: var(--wp--custom--button--border--radius);
background-color: #32373c;
background-color: var(--wp--custom--button--color--background);
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 styles added here (L27 - L38) are just for making the layout in the local env consistent with the sandbox and the prod. (i.e., the styles on the sandbox and the prod are already aligned)

Copy link
Collaborator

@StevenDufresne StevenDufresne left a comment

Choose a reason for hiding this comment

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

I think this is close enough for now. I'm not certain how well wp_is_mobile will work in production, but it should be false more than true so its fine.

- Body background-color is set to white.
- Link color is set to --wp--custom--color--primary.
@renintw renintw merged commit bc3ec7e into trunk Sep 13, 2022
@renintw renintw deleted the fix/remove-editor-experience-when-using-mobile branch September 13, 2022 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove Editor Experience when viewing page on "mobile" device.
4 participants