Skip to content

Conversation

@artemiomorales
Copy link
Contributor

What?

This pull request is an exploration of how we might implement the Navigator component in the off-canvas editor experiment in order to improve the user experience by creating animation transitions between block inspector panels.

It addresses issue #45884 and is related to the rough implementation taken in #46342

Why?

This draft PR is meant to help with discussion and discovery related to the implementation, as well as gain insight into how the Navigator component could be revised to fit this use case.

How?

It adds a special inspector for navigation that makes use of the Navigator component.

Testing Instructions

  1. Open the Full Site Editor
  2. Click on items inside a Navigation block
  3. The items are rendered using the Navigator

Testing Instructions for Keyboard

TBD

Screenshots or screencast

TBD

@artemiomorales
Copy link
Contributor Author

artemiomorales commented Dec 16, 2022

@ajlende Here's a walkthrough of the current draft, outlining some of the considerations for this use case.

Namely, we need to consider that the Navigator logic runs contrary to the current Block Inspector logic, so we'd need to introduce a special case for the Navigation blocks.

In addition, whereas navigation through the Global Styles is all contained within the sidebar, when it comes to the Navigation blocks, we need to consider that those blocks can be selected from the Document List view and canvas in addition to the off-canvas editor.

We also need to figure a way to introduce this special case for navigation to the edit buttons in the off-canvas editor and the back button in the Block Card.

Note: I realized there was some extraneous code in the video, which I removed in the commit "Remove useNavigator references to keep code clean for discussion"

navigator-pt1.mp4
navigator-pt2.mp4
navigator-pt3.mp4

@artemiomorales
Copy link
Contributor Author

Update: So I fixed the wonky state updates that were preventing the Block Card from showing up properly. Next step is to make sure the state updates happen properly no matter where the block is selected from, and that the animations only occur when using the off-canvas editor and back button.

I'm thinking to also introduce logic to the Navigator that would allow you to configure the direction of the animation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of expected a loop at this level to render a "screen" per clientId

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 took that approach in an earlier commit, but because of the way the provider works, the state wasn't getting updated properly in the screen components. Separating them like this seems to solve the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

I took that approach in an earlier commit, but because of the way the provider works, the state wasn't getting updated properly in the screen components.

Why do you mean by "the state wasn't getting updated properly"?

Copy link
Contributor Author

@artemiomorales artemiomorales Dec 19, 2022

Choose a reason for hiding this comment

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

Here I have an explanatory video. I'm happy to explain further if you'd like.

navigator-props-edit.mp4

@artemiomorales
Copy link
Contributor Author

artemiomorales commented Dec 20, 2022

@youknowriad @ajlende The latest commit adds the option to customize the animation settings for the Navigator, and I refactored the Navigation Inspector to make use of this:

  1. When the Navigation Inspector is first mounted, there is no animation
  2. When a child navigation block is selected, it animates if the previously selected item was the root Navigation Block
  3. When the root Navigation Block is selected, it animates if the previously selected item was a child navigation block
  4. When switching between child navigation blocks, there is no animation

It does this by keeping track of the depth of the current selection, which allows us to contain logic for the Navigator inside of the BlockInspector file, without needing to introduce anything new to the Document List view, canvas, or Block Card.

Here's a video walking through it; please let me know your thoughts, ideas, and suggestions 🙏

animation-settings.mp4

@ajlende
Copy link
Contributor

ajlende commented Dec 21, 2022

Firefox only plays the audio of the .mov files. Could you run your videos through ffmpeg of something to convert them to mp4s which are supported?

This is the command that I use if I'm recording on MacOS: ffmpeg -i screen-recording.mov -vf scale=iw/2:-2 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -level 3 screen-recording.mp4.

@artemiomorales
Copy link
Contributor Author

@ajlende The videos throughout the thread have been converted; just let me know if you run into any issues.

@scruffian
Copy link
Contributor

When I tested this, I see this in the inspector:

Screenshot 2022-12-21 at 17 12 27

Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be a different file.

Copy link
Contributor

Choose a reason for hiding this comment

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

One of the points in favour of using the navigator component is that we won't have to duplicate the animation logic. If we're doing that here then that makes it a less compelling argument.

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 we can remove this, and the other opacity: 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if exposing the animation settings like this is best option. In reality it's only the direction (x) of the initial animation state that we need to alter, so is it better to expose an option that tells the navigator whether this is an "up" or "down" style animation, rather than making everything customizable?

@ciampo ciampo requested review from ciampo and mirka December 22, 2022 22:09
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

Hey @artemiomorales ! Thank you for putting this draft together.

I personally agree with @scruffian 's comment here — exposing a way to override the whole animation settings feels a bit overkill.

More in general, the idea behind Navigator is that it handles "forwards" and "backwards" navigation, associating a specific animation with those types of navigation. Is your idea here to basically invert the direction of a backwards and forwards animation?

@artemiomorales
Copy link
Contributor Author

I wonder if exposing the animation settings like this is best option. In reality it's only the direction (x) of the initial animation state that we need to alter, so is it better to expose an option that tells the navigator whether this is an "up" or "down" style animation, rather than making everything customizable?

@scruffian Ok I've modified the component. Note: Not only do we need to be able to specify whether the animation should go forward or backward, we also need to be able to disable the animation altogether. I've added parameters to allow for these different cases.

More in general, the idea behind Navigator is that it handles "forwards" and "backwards" navigation, associating a specific animation with those types of navigation. Is your idea here to basically invert the direction of a backwards and forwards animation?

@ciampo My idea is to be able to configure the animation to go forward, backward, or not at all based on certain conditions. As for whether we should continue to associate a specific animation for a particular type of navigation, I'm not sure that's a great fit for this use case.

Before this pull request, activating the backward animation required using the goBack method, but "going back" doesn't have any real meaning here. If a user goes from one submenu item to the next, then clicks on the parent Navigation block, that's not really "going back," and the component as written doesn't give one the ability to specify a particular screen to go back to.

We could make more extensive changes to the Navigator for this use case, locking forward animation to the goTo method and backward animation to the goBack method, but we'd then need to start looking into modifying the location history too. Having a simpler approach by just overriding the default animation in goTo seems like the better move, though I'd be happy to hear what you think.

When I tested this, I see this in the inspector:

Screenshot 2022-12-21 at 17 12 27

@scruffian can you elaborate on the point you're trying to make here? This is what I see. Do you mean that the justification, layout, and "Allow to wrap to multiple lines" options are not visible?

Screen Shot 2023-01-02 at 12 06 40 PM

@scruffian
Copy link
Contributor

@scruffian can you elaborate on the point you're trying to make here? This is what I see. Do you mean that the justification, layout, and "Allow to wrap to multiple lines" options are not visible?

Sorry, no I mean that the "skip to selected block" banner is over the top of the block inserter. This is not the case in trunk.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this the third argument, so we don't have to modify the existing calls to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this has been revised.

Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

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

This is looking good to me. I'd appreciate a review from someone who knows more about this code. We also need to address the "skip to the selected block" overlay before merging.

@ciampo
Copy link
Contributor

ciampo commented Jan 3, 2023

I'd appreciate a review from someone who knows more about this code. We also need to address the "skip to the selected block" overlay before merging.

Absolutely, I'd like to give this PR a deeper look before it gets merged. @artemiomorales, I'm going to give this a review soon (still catching up after a 4-week AFK).

I added the option to override the default animation settings
in the Navigator to allow for customization of the user experience.

In the BlockInspector, we now calculate the depth of the
selected block and, based on that information, configure
the animation settings to give the illusion of a user
drilling down into the hierarchy.

Importantly, we do NOT execute an animation when the
NavigationInspector is first loaded or when we select
new blocka at the same depth.

Currently, we only animate when selecting any descendant
of the root Navigation block, or when we select the Navigation
block after previously having selected a descendant.
@artemiomorales artemiomorales force-pushed the try/implement-navigator-for-off-canvas-editor branch from fe49694 to 1117f8c Compare January 3, 2023 15:14
@artemiomorales
Copy link
Contributor Author

Sorry, no I mean that the "skip to selected block" banner is over the top of the block inserter. This is not the case in trunk.

@scruffian I'm unable to replicate this. Can you provide any additional details as to how this happens?

Does anyone else see this? Perhaps @ciampo?

Absolutely, I'd like to give this PR a deeper look before it gets merged. @artemiomorales, I'm going to give this a review soon (still catching up after a 4-week AFK).

Ok perfect, thank you. We may also want to get someone from design to weigh in on the transitions from the different selection points.

@scruffian
Copy link
Contributor

@scruffian I'm unable to replicate this. Can you provide any additional details as to how this happens?

It happens when the block is initially selected.

@artemiomorales
Copy link
Contributor Author

It happens when the block is initially selected.

@scruffian Hmm I tried that in a few different local environments and encountered no issues. I'll wait to see what other folks encounter and we can go from there.

SelectBlockDemonstration.mov

@ciampo
Copy link
Contributor

ciampo commented Jan 12, 2023

Hey @artemiomorales , sorry for the delay on my end!

My idea is to be able to configure the animation to go forward, backward, or not at all based on certain conditions. As for whether we should continue to associate a specific animation for a particular type of navigation, I'm not sure that's a great fit for this use case.

As you also wrote, the use case that you describe doesn't really fit Navigator. The main "incompatibility" is around the meaning of "backward" and "forward":

  • In your use-case, it seems like "backward" and "forward" relate to the hierarchy of the nav block
  • For Navigator, "backward" and "forward" refer to the location history stack (a simplification of the browser's history, where "going back" means popping the stack)

This is also well explained by what you wrote:

Before this pull request, activating the backward animation required using the goBack method, but "going back" doesn't have any real meaning here. If a user goes from one submenu item to the next, then clicks on the parent Navigation block, that's not really "going back," and the component as written doesn't give one the ability to specify a particular screen to go back to.

You definitely have a point about the meaning of "going back" or "forward". If we had to keep the browser history analogy going, switching from one submenu to a sibling submenu sounds more like a replace than a push (something that Navigator currently doesn't offer, but could potentially do).

I'm simply not sure if Navigator is a good fit here. The way it's being used in this PR and the changes that have been applied to enable the usage feel a bit hacky to me and against the nature of the component (for example, by never using goBack, the location history could theoretically just grow infinitely, and the focus restoration feature is never used).


One potential idea that came to mind (and that I partially already highlighted in #45884, could be to:

  • translate the menu hierarchy to a location history — basically, each layer of submenu from the root menu to the current menu would represent a location entry in Navigator history
  • therefore:
    • "drilling down" from a menu to its submenu would be done via goTo (ie. forward)
    • going from a submenu to its parent menu would be done via goBack (ie. backward)
    • switching between two submenus could be done via replace (which we'd need to implement, but I imagine it could be implemented in a way that doesn't trigger an animation)
  • we could also expose a way to pass an initial array of locations in case the initial menu that needs to be shown is not the root menu

Although it's just an idea for now, and we'd need to look more into it to prove its feasibility.

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.

5 participants