-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] refactor InspectorControls #17279
[RNMobile] refactor InspectorControls #17279
Conversation
packages/block-editor/src/components/block-list/block.native.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-list/block.native.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/inspector-controls/index.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @jbinda Thanks for the PR 🎉 I tried to address all the main things but let me know if I missed something
packages/block-editor/src/components/block-list/block-mobile-toolbar.native.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-list/block-mobile-toolbar.native.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/block-list/block.native.js
Outdated
Show resolved
Hide resolved
Let me also link this comment here in case you have different opinions @koke @marecar3 please go ahead and respond here: wordpress-mobile/gutenberg-mobile#1300 (comment) |
I agree with your second thought. I don't think we'll need the slot for now, and if/when we do it should probably be called something else. |
SlotComponent.displayName = name + 'Slot'; | ||
|
||
const OptionsContainer = ( { children, showSettings, onSettingsToggle: onClose, ...rest } ) => ( | ||
<BottomSheet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand the need for putting BottomSheet component inside slot-fill. slot-fill is a multi purpose pattern, would it be possible if we don't touch it at all for this particular change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I don't see the need to change slot-fill for this. I'd recommend looking at how this works on the web:
@wordpress/edit-post
has aLayout
component that includes aSidebar.Slot
- I believe that the sidebar visibility is controlled via the
core/edit-post
store with theisEditorSidebarOpened
selector. The button to open the sidebar would dispatch theopenGeneralSidebar
action. - It also includes a
SettingsSidebar
that fills that slot with many things, includingBlockInspector
. - This
BlockInspector
is whereInspectorControls.Slot
is placed
For mobile, we use a modal BottomSheet
instead of the Sidebar
(although I imagine iPads could show a sidebar in the future), and the button to toggle it is in the block toolbar instead of a global editor toolbar.
The UI is a little different but I think the existing web architecture should still fit the native UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@koke, @pinarol thank you for review.
I followed with the remarks you have posted and implement changes as below:
- I have moved
BottomSheet
underLayout
component and provideBottomSheetSettings
component to make it more similar to web (which useslot-fill
logic to renderSidebar
and it's content) - I use logic from web to show/hide the settings
BottomSheet
container - I have created
BlockSettingsButton
and useslot-fill
logic because I need to conditionally show/hide it depending if given block have some settings wrapped inInspectorControls
4 I created native implementation forInspectorControls
which will render the same as for web plusSettingsButton
In current implementation I was able to remove all changes in slot-fill
logic made before (only InspectorControls
for mobile is affected) and also the behaviour is the same as I recorder before. You can noticed that after you delete the children of InspectorControls
in edit.native.js
for image block the settings button disappears.
packages/block-editor/src/components/block-list/block-mobile-toolbar.native.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor here 👍
I like the fact that we removed some of the internal state of the ImageEdit
component showSettings
and moved it to the store as editorSidebarOpened
.
Not sure why we would want a Slot
for BlockSettingsButton
though.
@@ -28,7 +28,7 @@ const BlockMobileToolbar = ( { | |||
|
|||
<View style={ styles.spacer } /> | |||
|
|||
<InspectorControls.Slot /> | |||
<BlockSettingsButton.Slot /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary to make the settings button a SlotFill. I don't expect another button to make sense being displayed alongside it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because we render the settings button Fill
component inside Inspector Controls when it has any children. Using it in that way we can automatically show/hide setting button depending if block has some settings wrappen insideInspectorControl
component inside edit.native.js
file.
At this moment it was my best idea to make the API on mobile usage as much as possible to web.
Another benefit of that is after small refactor we can use the same mechanism to add another buttons in the future
packages/block-editor/src/components/block-settings/container.native.js
Outdated
Show resolved
Hide resolved
There was something bugging me about this and I realized that the behavior is different on the web, as the settings button is always present, because the sidebar contains other things as well. After chatting with @iamthomasbishop, we think it would be interesting to have the block settings button always available on every block. I don't think we need to block this PR on that, but it would be good to consider after merging this. On the web, even if you ignore the document options, block settings always shows the block icon, title, and description, and most blocks have the advanced css field: The blocks currently available on mobile don't implement those |
Agreed w/ @koke – if we add the |
@koke - right! that was the main difference. On web there are others element that has a slot inside Settings Sidebar. On mobile we have less space to show them all at once. Stacked bottom sheets seems to be good solution @iamthomasbishop - as you mentioned in current implementation not every block has a settings button. So the fastest way to show it in every block is to take care about AdvancedInspectorControl mobile implementation right ? (this is the component which renders Additional CSS classes) Summarizing: If it's ok if we merge this PR and then take care of AdvancedInspectorControls to finally refactor settings button show/hide logic ? Or we should wait with merging ? |
I don't think we should block this PR for that, we can handle it separately. |
Ok, so I resolve conflicts and it's ready to merge |
Agreed w/ @pinarol – this isn't a blocker.
Yes, essentially just adding the additional css classes input should in theory take care of the problem, bc every block (afaik) has that field. |
Could you update the branch and resolve the conflicts? @jbinda |
Opened an issue to handle advanced settings separately. |
Sure ! |
@pinarol conflicts are solved and CI passed :) |
packages/block-editor/src/components/inspector-controls/index.native.js
Outdated
Show resolved
Hide resolved
@pinarol already in-progress :) |
Yes, code looks good. I was planning to do some final testing today before merging |
I just wonder if we shouldn't first merge |
It is already done by #17228 |
9fd0913
to
a52c350
Compare
Ok, thanks ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I saw one failing test, so I restarted the build on Travis to see if it was a glitch. Ready to merge when green IMO
And there is also failing test on Android on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
great ! Thanks |
Description
PR is connected with #1300 in gutenberg-mobile.
Please also refer to Related gutenberg-mobile PR
It presents:
View
component)InspectorControls
that allows to use it in pretty same manner as on webedit.native.js
in image and video blockSettingsButton
inBlockMobileToolbar
behaviour to allow show/hide depending if there is any settings available to current blockHow has this been tested?
Currently only manual test was provided to check if feature listed in the #1300 works as expected.
Also still need to fix some failing unit test but I will be cover soon.
Screenshots
Please see below screenshot. It presents how to render InspectorControls inside Image block. On left side there is usage on Web. On the right side is the usage on mobile.
Note here that I temporally left
BottomSheet.Cell
to render buttons insideBottomSheet
- the markup will be also refactor in separate PR to be consistent with web markup.Types of changes
It should not have impact on usage on web but provides changes in usage on mobile (see comments in
changes
section in this PR)Checklist: