-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Enable child block settings to be hidden via parent block (#…
…36371) With this PR, a "__experimentalHideChildBlockControls" block support is introduced. If a parent block declares "__experimentalHideChildBlockControls" to be true with this PR applied, then the settings control for its child blocks won't be displayed. It is set to false by default.
- Loading branch information
Showing
2 changed files
with
42 additions
and
3 deletions.
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
38 changes: 38 additions & 0 deletions
38
packages/block-editor/src/components/use-display-block-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,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { hasBlockSupport } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useBlockEditContext } from '../block-edit/context'; | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
export default function useDisplayBlockControls() { | ||
const { isSelected, clientId, name } = useBlockEditContext(); | ||
return useSelect( | ||
( select ) => { | ||
const { getBlockName, getBlockRootClientId } = select( | ||
blockEditorStore | ||
); | ||
|
||
const parentId = getBlockRootClientId( clientId ); | ||
const parentBlockName = getBlockName( parentId ); | ||
|
||
const hideControls = hasBlockSupport( | ||
parentBlockName, | ||
'__experimentalHideChildBlockControls', | ||
false | ||
); | ||
|
||
if ( ! hideControls && isSelected ) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
[ clientId, isSelected, name ] | ||
); | ||
} |