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] Set and reference heading anchors #27935

Merged

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Dec 30, 2020

Description

Address wordpress-mobile/gutenberg-mobile#1816 by adding the ability to set and reference Heading block anchors

How has this been tested?

  1. Edit a post and add Heading block.
  2. Tap block settings button (i.e. settings cog icon).
  3. Set value for "HTML Anchor" control.
  4. Dismiss block settings.
  5. Add Paragraph block with text including a link to the HTML Anchor from
    earlier step.
  6. Publish post.
  7. Visit published post in a web browser.
  8. Tap link.

Outcome: Browser should scroll to Heading anchor.

Screenshots

UI Examples
iOS Android
ios-heading-selected android-heading-selected
ios-without-heading-anchor android-without-heading-anchor
ios-with-heading-anchor android-with-heading-anchor

Types of changes

New feature (non-breaking change which adds functionality)

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.

@hypest
Copy link
Contributor

hypest commented Jan 8, 2021

👋 David! May I suggest changing the "prefix" in the PR title to [RNMobile] instead of just [Mobile]? "RNMobile" is not a hugely better prefix but, it's rather unique at that and disambiguating between mobile-web and native-mobile. Thanks!

@dcalhoun dcalhoun changed the title [Mobile] Set and reference heading anchors [RNMobile] Set and reference heading anchors Jan 8, 2021
@dcalhoun
Copy link
Member Author

dcalhoun commented Jan 13, 2021

@hypest I do not have permissions to manage the reviewers list. After consideration, including four members is likely unnecessary. Would you please update the reviewers to list to be @ceyhun and @talldan please?

@ceyhun would you please review that my implementation works as expected and is a sound approach?

@talldan would you be willing to review my work to ensure my implementation does not disrupt any web experiences or violate any general project coding practices?

@dcalhoun dcalhoun force-pushed the rnmobile/set-and-reference-heading-anchors branch from 455a9ca to 2d4c648 Compare January 13, 2021 22:47
@talldan
Copy link
Contributor

talldan commented Jan 14, 2021

@dcalhoun Thanks for the ping.

I tested this and on the web I'm seeing two way to set an anchor on the heading block now:
Screenshot 2021-01-14 at 10 25 38 am

The UI for the anchor in the advanced section is added to some blocks by the supports setting:

And the code that picks up that setting and adds the UI is here (added using filters):

export const withInspectorControl = createHigherOrderComponent(
( BlockEdit ) => {
return ( props ) => {
const hasAnchor = hasBlockSupport( props.name, 'anchor' );
if ( hasAnchor && props.isSelected ) {
return (
<>
<BlockEdit { ...props } />
<InspectorAdvancedControls>
<TextControl
className="html-anchor-control"
label={ __( 'HTML anchor' ) }
help={
<>
{ __(
'Enter a word or two — without spaces — to make a unique web address just for this heading, called an “anchor.” Then, you’ll be able to link directly to this section of your page.'
) }
<ExternalLink
href={
'https://wordpress.org/support/article/page-jumps/'
}
>
{ __( 'Learn more about anchors' ) }
</ExternalLink>
</>
}
value={ props.attributes.anchor || '' }
onChange={ ( nextValue ) => {
nextValue = nextValue.replace(
ANCHOR_REGEX,
'-'
);
props.setAttributes( {
anchor: nextValue,
} );
} }
autoComplete="off"
/>
</InspectorAdvancedControls>
</>
);
}
return <BlockEdit { ...props } />;
};
},
'withInspectorControl'
);

I think if you're looking to add anchor support on mobile, you'd probably want to use the same system to ensure it automatically works across all blocks that support the anchor setting.

Copy link
Member

@ceyhun ceyhun left a comment

Choose a reason for hiding this comment

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

Just saw the comment from Daniel. I guess the mobile implementation will be different from the web one, so I think it makes sense to review and test after that change. Feel free to ping me again 🙇

@hypest
Copy link
Contributor

hypest commented Jan 15, 2021

I tested this and on the web I'm seeing two way to set an anchor on the heading block now:

Aha, nice find there Daniel!

I think if you're looking to add anchor support on mobile, you'd probably want to use the same system to ensure it automatically works across all blocks that support the anchor setting.

👋 @dcalhoun , just wanted to add that in terms of scope, it'd be cool if we can limit to the heading block for now, but still have an implementation that lends itself to expanding to other blocks. That said, I'm not sure if that'd be more practical or quicker than just go for all blocks as Daniel mentions, but if we can break up the scope in such a way that we land things in separate PRs it can help with moving forward in a nice pace. Thanks!

@dcalhoun
Copy link
Member Author

I tested this and on the web I'm seeing two way to set an anchor on the heading block now:

Aha, nice find there Daniel!

Indeed. Thank you for reviewing, Daniel. You have opened my eyes to a much wider view of the code base and it's incredibly helpful.

it'd be cool if we can limit to the heading block for now, but still have an implementation that lends itself to expanding to other blocks. That said, I'm not sure if that'd be more practical or quicker than just go for all blocks as Daniel mentions, but if we can break up the scope in such a way that we land things in separate PRs it can help with moving forward in a nice pace.

@hypest whether it is more or less work to scope enabling anchors for headings will likely depend upon the response to my questions for Thomas. If we is OK with using a generic heading for the bottom sheet, then enabling anchor hook for all blocks will likely "just work out of the box."

That said, I can go ahead and execute enabling anchors for Heading blocks only to sustain project momentum.

@dcalhoun dcalhoun requested a review from ellatrix as a code owner January 15, 2021 15:44
@dcalhoun
Copy link
Member Author

@talldan @ceyhun I have addressed the initial feedback. I believe this PR is now ready for review again. Thank you!

@dcalhoun dcalhoun requested a review from ceyhun January 15, 2021 17:21
@dcalhoun dcalhoun force-pushed the rnmobile/set-and-reference-heading-anchors branch from f653167 to 61a2168 Compare January 19, 2021 21:45
Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

Things look good from a web point of view. Happy for someone more familiar with mobile to do a test there and give the final thumbs up 👍.

</InspectorAdvancedControls>
) }
{ ! isWeb && props.name === 'core/heading' && (
<InspectorControls>
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point it would be cool to look at supporting InspectorAdvancedControls on mobile (guess it's not rendered anywhere at the moment though).

There are a few other things that tend to be rendered in this panel/slot on the web, the main other item is the Custom Class Name field (https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/hooks/custom-class-name.js):
Screenshot 2021-01-20 at 2 56 34 pm

Those things could always be prevented from rendering on mobile in the same way you have here if you want a more gradual roll-out.

Copy link
Member Author

@dcalhoun dcalhoun Jan 20, 2021

Choose a reason for hiding this comment

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

I agree. Ideally we reuse InspectorAdvancedControls for mobile once we have a design for displaying its entirety. Thomas and I had a discussion about the "Advanced" section, but opted to target only the anchor input for the initial implementation.

) }
{ ! isWeb && props.name === 'core/heading' && (
<InspectorControls>
<PanelBody title={ __( 'Heading settings' ) }>
Copy link
Contributor

Choose a reason for hiding this comment

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

'Heading settings' might not be very scalable for the future, as other features that get added to the block inspector for Heading can't be put inside this panel. There's no way to access it from the Block's edit function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, we'll need a more scalable heading in the future. Thomas requested that we use the "Heading settings" title for the time being.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thomas requested

My comment below is actually covering the process here too, thanks!

{ textControl }
</InspectorAdvancedControls>
) }
{ ! isWeb && props.name === 'core/heading' && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a plan to remove the restriction to just the one block?

I'd hope that as long as TextControl works well on mobile, it should be fairly straightforward to support this on all blocks that declare support for an HTML Anchor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I believe the plan is to implement other blocks in the future. For the time being, Thomas and Stefanos requested that we scope the work to Heading blocks.

From my testing, you are correct that wider anchor support is straightforward.

Copy link
Contributor

@hypest hypest Jan 21, 2021

Choose a reason for hiding this comment

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

requested

Just a quick note on the process, as "requested" doesn't represent it very well: The way we work, at least on the native mobile apps, we make sure people collaborate by sharing information and context to design/implement solutions, including carving out the plan to get there.

We try to keep PR scope to the minimum so we can move and land land them in small but predictable steps (even if, say, landing means merging to a feature branch). We re-evaluate our plans as we go, when new info arises, like for example when we understand scope is actually too big for a single PR.

In our case here with the anchor feature, limiting to just the "Heading" block helps us pin down the implementation on mobile, add value by shipping the feature to the users, all while we making plans for the next steps.

Hope this helps, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

@hypest thank you for the feedback and context.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a comment here linking the issue where we plan to implement InspectorAdvancedControls and/or enable anchors for all the other blocks?

@@ -394,7 +394,7 @@ Undocumented declaration.

_Related_

- <https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inspector-controls-advanced/README.md>
- <https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/inspector-advanced-controls/README.md>
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

@talldan talldan added [Block] Heading Affects the Headings Block [Type] Enhancement A suggestion for improvement. Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) labels Jan 20, 2021
@dcalhoun
Copy link
Member Author

@talldan thank you again for the solid review. You shared great thoughts and questions. I have created #28363 to allow us to continue a discussion on when/how we might add wider support anchors on mobile.

Copy link
Member

@ceyhun ceyhun left a comment

Choose a reason for hiding this comment

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

Sorry for the late review @dcalhoun, it LGTM 👍 Tested on iOS and Android and everything is working as expected. Thanks!

{ textControl }
</InspectorAdvancedControls>
) }
{ ! isWeb && props.name === 'core/heading' && (
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a comment here linking the issue where we plan to implement InspectorAdvancedControls and/or enable anchors for all the other blocks?

packages/react-native-editor/CHANGELOG.md Outdated Show resolved Hide resolved
Address design feedback.
Previous approach ignored web implementation and resulted in double
anchor controls for web editor. This leverages the existing anchor hook
to fix the issue and share more code.
Address code review feedback.
@dcalhoun dcalhoun force-pushed the rnmobile/set-and-reference-heading-anchors branch from 61a2168 to 3be82b7 Compare January 26, 2021 16:41
@dcalhoun
Copy link
Member Author

@ceyhun thank you for the review. I pushed a new commit to address your feedback. I believe this PR is ready to merge. I do not have the privileges required to rerun the failing CI tests or merge the PR. Would you be willing to help me do that please?

@ceyhun
Copy link
Member

ceyhun commented Jan 26, 2021

I restarted the End-to-End Tests / Admin jobs, but they are already failing on master, so I think it'll be OK to merge this PR even if they don't pass.

@ceyhun ceyhun merged commit 946d54b into WordPress:master Jan 26, 2021
@github-actions github-actions bot added this to the Gutenberg 9.9 milestone Jan 26, 2021
@dcalhoun dcalhoun deleted the rnmobile/set-and-reference-heading-anchors branch January 31, 2021 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Heading Affects the Headings Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository Mobile App - i.e. Android or iOS Native mobile impl of the block editor. (Note: used in scripts, ping mobile folks to change) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants