-
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
Merged
pinarol
merged 1 commit into
WordPress:master
from
callstack:rnmobile/inspector-controls
Sep 30, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/block-editor/src/components/block-settings/button.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill, ToolbarButton } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { withDispatch } from '@wordpress/data'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'SettingsToolbarButton' ); | ||
|
||
const SettingsButton = ( { openGeneralSidebar } ) => | ||
<ToolbarButton | ||
title={ __( 'Open Settings' ) } | ||
icon="admin-generic" | ||
onClick={ openGeneralSidebar } | ||
/>; | ||
|
||
const SettingsButtonFill = ( props ) => ( | ||
<Fill> | ||
<SettingsButton { ...props } /> | ||
</Fill> | ||
); | ||
|
||
const SettingsToolbarButton = withDispatch( ( dispatch ) => { | ||
const { openGeneralSidebar } = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
openGeneralSidebar: () => openGeneralSidebar( 'edit-post/block' ), | ||
}; | ||
} )( SettingsButtonFill ); | ||
|
||
SettingsToolbarButton.Slot = Slot; | ||
|
||
export default SettingsToolbarButton; |
40 changes: 40 additions & 0 deletions
40
packages/block-editor/src/components/block-settings/container.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BottomSheet } from '@wordpress/components'; | ||
import { withSelect, withDispatch } from '@wordpress/data'; | ||
import { compose } from '@wordpress/compose'; | ||
import { InspectorControls } from '@wordpress/block-editor'; | ||
|
||
function BottomSheetSettings( { editorSidebarOpened, closeGeneralSidebar, ...props } ) { | ||
return ( | ||
<BottomSheet | ||
isVisible={ editorSidebarOpened } | ||
onClose={ closeGeneralSidebar } | ||
hideHeader | ||
{ ...props } | ||
> | ||
<InspectorControls.Slot /> | ||
</BottomSheet> | ||
); | ||
} | ||
|
||
export default compose( [ | ||
withSelect( ( select ) => { | ||
const { | ||
isEditorSidebarOpened, | ||
} = select( 'core/edit-post' ); | ||
|
||
return { | ||
editorSidebarOpened: isEditorSidebarOpened(), | ||
}; | ||
} ), | ||
withDispatch( ( dispatch ) => { | ||
const { closeGeneralSidebar } = dispatch( 'core/edit-post' ); | ||
|
||
return { | ||
closeGeneralSidebar, | ||
}; | ||
} ), | ||
] | ||
)( BottomSheetSettings ); |
2 changes: 2 additions & 0 deletions
2
packages/block-editor/src/components/block-settings/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as BlockSettingsButton } from './button'; | ||
export { default as BottomSheetSettings } from './container'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/block-editor/src/components/inspector-controls/index.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createSlotFill } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ifBlockEditSelected } from '../block-edit/context'; | ||
import { BlockSettingsButton } from '../block-settings'; | ||
|
||
const { Fill, Slot } = createSlotFill( 'InspectorControls' ); | ||
|
||
const FillWithSettingsButton = ( { children, ...props } ) => { | ||
return ( | ||
<> | ||
<Fill { ...props }>{ children }</Fill> | ||
{ React.Children.count( children ) > 0 && ( <BlockSettingsButton /> ) } | ||
</> | ||
); | ||
}; | ||
|
||
const InspectorControls = ifBlockEditSelected( FillWithSettingsButton ); | ||
|
||
InspectorControls.Slot = Slot; | ||
|
||
/** | ||
* @see https://github.com/WordPress/gutenberg/blob/master/packages/block-editor/src/components/inspector-controls/README.md | ||
*/ | ||
export default InspectorControls; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
|
||
export class PanelBody extends Component { | ||
constructor( ) { | ||
super( ...arguments ); | ||
this.state = {}; | ||
} | ||
|
||
render() { | ||
const { children } = this.props; | ||
return ( | ||
<View > | ||
{ children } | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default PanelBody; | ||
jbinda marked this conversation as resolved.
Show resolved
Hide resolved
jbinda marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 insideedit.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