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] fix group appender behaviour #18564

Merged
merged 11 commits into from
Dec 20, 2019
Merged

[RNMobile] fix group appender behaviour #18564

merged 11 commits into from
Dec 20, 2019

Conversation

jbinda
Copy link
Contributor

@jbinda jbinda commented Nov 18, 2019

Description

Refactor renderDefautBlockAppender() to unlock show InserterMenu in Group block (noticed issue after merge this one.

Please also refer to:
Related gutenberg-mobile PR

How has this been tested?

  1. Add empty group block in initial-html
<!-- wp:group -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"></div></div>
<!-- /wp:group -->
  1. Try to add block using appender
  2. Select Group block and try to use group appender
  3. Do the same on default initial-html content

I have also test it according to steps here

Test 1:

Test 2:

Test WPAndroid

Screenshots

Before:

After:

Types of changes

Small refactor to fix group appender behaviour

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. .

@jbinda jbinda requested a review from hypest November 18, 2019 09:18
@jbinda jbinda requested a review from pinarol November 18, 2019 09:24
@jbinda jbinda self-assigned this Nov 18, 2019
@jbinda jbinda 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 Nov 18, 2019
@jbinda
Copy link
Contributor Author

jbinda commented Nov 19, 2019

@hypest I have provide the GIFs according to test you mentioned from original PR on demo app iOS/Android as well as in WPAndroid app

Appender seems to work as described there

@jbinda jbinda changed the title [RNMobile] fix show appender in group block [RNMobile] fix group appender behaviour Nov 19, 2019
@jbinda
Copy link
Contributor Author

jbinda commented Nov 19, 2019

@iamthomasbishop

I talked with @hypest on Slack about this PR and we decided to ask you about the design. The issue was that I was unable to open InserterMenu after changes mentioned in PR description.

I provide simple solution that brings back ability to open InserterMenu with group appender but also will cause that user see the ADD BLOCK HERE separator above the appender. Is it something that breaks the current design ?

Our conclusion with @hypest was:

  1. in my code we have the InserterMenu visible with Separator inside Group block
  2. in @hypest version we do not have Separator in Group but also do not allow to open InserterMenu after press it
  3. outside the Group block both version works the same
  4. rendering BlockListAppender apparently plays a role here, which is still unclear which role it is or if it should play it.

@iamthomasbishop
Copy link

@jbinda It's a little hard to follow, but based on the "After" gif above, I think that's pretty close to what I'd expect. One change I'd make is to hide the inline appender (inside the group) while the block library bottom sheet is open, so just the "Add block here" indicator is shown in place of that.

Maybe I'm missing something, but that's my initial reaction.

@jbinda
Copy link
Contributor Author

jbinda commented Nov 20, 2019

So I assume that is expected behaviour for Group block appender?

Now the technical aspects:
I have manage to allow see Inserter and hide the appender button after click to follow @thomasbishop guideline by adding check for isOpen in this renderToggle render prop inside ButtonBlickAppender like this:

Like me and @hypest conclude on Slack convo it seems to be "hacky" solution and it treated rather as "hotfix" if we do not found the root cause of described behaviour

According to that I have also investigate the flow behind BlockListAppender which is as below:

  1. Inserter component is render in ButtonBlockAppender which passed render prop called renderToggle in which it renders the button with “+” icon and call onToggle which show and hide the InserterMenu with block options
  2. in BlockListAppender we render CustomAppender or DefaultAppender. CustomAppender is render when we pass renderAppender to BlockListAppender. If this prop is not passed it render the default
  3. in renderDefaultBlockAppender() method in BlockList we pass renderAppender from this.props. Tracking down the way from it comes I see that in Group block edit.native.js file we call InnerBlock component and pass there renderAppender in that way renderAppender={ isSelected && InnerBlocks.ButtonBlockAppender }. The flow of InnerBlock is that it renders BlockList with some props including renderAppender it receives (edited)

The next thing to be checked is value of willShowInsertionPoint under renderDefaultBlockAppender() which comes from shouldShowInsertionPointBefore()in BlockList component because it seems it also have impact of described behaviour.

@hypest
Copy link
Contributor

hypest commented Nov 20, 2019

Like me and @hypest conclude on Slack convo it seems to be "hacky" solution and it treated rather as "hotfix" if we do not found the root cause of described behaviour

Thanks for investigating deeper @jbinda ! Yeah, using isOpen couples the "+" button with the Inserter bottomsheet, which feels wrong. Let's continue working on this to find a better flag to depend the Group "+" button rendering on. Perhaps that flag could be something like the willShowInsertionPoint.

@iamthomasbishop
Copy link

So I assume that is expected behaviour for Group block appender?

@jbinda I think yes, it seems like the expected behavior.

@jbinda
Copy link
Contributor Author

jbinda commented Nov 29, 2019

@hypest

I played again with the behaviour of this issue once again.

I came up with the idea to pass renderSeparator to BlockListAppender and conditionally render it under ButtonBlockAppender but I'm not sure we would like to go that way. Maybe we would like to change the structure where Inserter is rendered by Appender button ?

Anyway at this moment I have strong opinion that the solution this PR provide is currently the best option to allow show inserter when the group block do not have any children added.

The reason behind that is the current structure described in previous comment.

Do you have any thought on that since our previous discussion ?

@hypest
Copy link
Contributor

hypest commented Dec 10, 2019

Here's how I look at this: Looking at the ButtonBlockAppender component, I find it weird that it renders an Inserter component. I'd expect to render a "+" button. Maybe it makes sense for the web since the inserter is popped up right there by the button so the two are linked. On mobile it's not, rather, the inserter is rendered as a bottomsheet. Let's ignore that for a bit.

So as it happens, the Inserter renders the actual "+" button via the renderToggle() prop.

With the changes in this PR, the ButtonBlockAppender renders an Inserter, the Inserter renders a button via renderToggle and then renderToggle itself doesn't even render the button if the isOpen is true. I think this logic is quite complex to follow 🤔.

Instead, how about:

  1. renderToggle always renders the button
  2. Inserter decides to call renderToggle when closed and a renderAddBlockSeparator() function when open

Thoughts?

@dratwas
Copy link
Contributor

dratwas commented Dec 10, 2019

  1. renderToggle always renders the button
  2. Inserter decides to call renderToggle when closed and a renderAddBlockSeparator() function when open

I totally agree with that flow :)

*/
import styles from './style.scss';

const AddBlockSeparator = ( { getStylesFromColorScheme } ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't realized that there is such a component. However, it seems like insertion-point.native.js is not used at all. I will move the AddBlockSeparator into it to be consistent with web names.

Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

This looks good to me!

I've only left one comment about whether we can consolidate the older BlockInsertionPoint component with the newer AddBlockSeparator, but I think that could be done in a separate PR if needed.

@dratwas dratwas requested a review from hypest December 16, 2019 13:47
Copy link
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for the work here @jbinda and @dratwas !

Feel free to merge, update the gutenberg-mobile PR with the merged commit and merge that one too.

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.

6 participants