From 95b9986c6295bf54addab62b2e64f24669db78db Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 18 Nov 2021 13:14:11 +0000 Subject: [PATCH 1/3] Detect if a parent block is hiding child block controls If a parent block is hiding child block controls, we can reasonable deduce that that would include the option to edit the child block's caption. This commit builds on the work done in https://github.com/WordPress/gutenberg/pull/36371 to detect if a parent block is hiding child block controls via the '__experimentalHideChildBlockControls' block supports. --- .../components/block-caption/index.native.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-caption/index.native.js b/packages/block-editor/src/components/block-caption/index.native.js index bcc2074f02e2e..6bb3419b13342 100644 --- a/packages/block-editor/src/components/block-caption/index.native.js +++ b/packages/block-editor/src/components/block-caption/index.native.js @@ -9,6 +9,7 @@ import { View } from 'react-native'; import { Caption, RichText } from '@wordpress/block-editor'; import { compose } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; +import { hasBlockSupport } from '@wordpress/blocks'; /** * Internal dependencies @@ -44,12 +45,24 @@ const BlockCaption = ( { export default compose( [ withSelect( ( select, { clientId } ) => { - const { getBlockAttributes, getSelectedBlockClientId } = select( - blockEditorStore - ); + const { + getBlockAttributes, + getSelectedBlockClientId, + getBlockName, + getBlockRootClientId, + } = select( blockEditorStore ); const { caption } = getBlockAttributes( clientId ) || {}; const isBlockSelected = getSelectedBlockClientId() === clientId; + const parentId = getBlockRootClientId( clientId ); + const parentBlockName = getBlockName( parentId ); + + hasBlockSupport( + parentBlockName, + '__experimentalHideChildBlockControls', + false + ); + // We'll render the caption so that the soft keyboard is not forced to close on Android // but still hide it by setting its display style to none. See wordpress-mobile/gutenberg-mobile#1221 const shouldDisplay = From 3a1d958d0ca48c400a6d848bf49fdd34e394b225 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 18 Nov 2021 13:17:03 +0000 Subject: [PATCH 2/3] Hide caption based on parent block supports The 'hideCaption' variable introduced with this commit will hide the block caption in cases where parent block's set the '__experimentalHideChildBlockControls' block support to true. --- .../src/components/block-caption/index.native.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/components/block-caption/index.native.js b/packages/block-editor/src/components/block-caption/index.native.js index 6bb3419b13342..a352cf3c825c2 100644 --- a/packages/block-editor/src/components/block-caption/index.native.js +++ b/packages/block-editor/src/components/block-caption/index.native.js @@ -57,7 +57,7 @@ export default compose( [ const parentId = getBlockRootClientId( clientId ); const parentBlockName = getBlockName( parentId ); - hasBlockSupport( + const hideCaption = hasBlockSupport( parentBlockName, '__experimentalHideChildBlockControls', false @@ -66,7 +66,8 @@ export default compose( [ // We'll render the caption so that the soft keyboard is not forced to close on Android // but still hide it by setting its display style to none. See wordpress-mobile/gutenberg-mobile#1221 const shouldDisplay = - ! RichText.isEmpty( caption ) > 0 || isBlockSelected; + ! hideCaption && + ( ! RichText.isEmpty( caption ) > 0 || isBlockSelected ); return { shouldDisplay, From 06bfad93f5f9f173fc42dfa8f7af57aeef98ec99 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Thu, 18 Nov 2021 22:13:17 +0000 Subject: [PATCH 3/3] Add clarifying comment As the purpose of this code may not be immediately clear, given it assumes knowledge of inner blocks, I've added a clarifying comment. --- .../block-editor/src/components/block-caption/index.native.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-editor/src/components/block-caption/index.native.js b/packages/block-editor/src/components/block-caption/index.native.js index a352cf3c825c2..f4a2e22bba904 100644 --- a/packages/block-editor/src/components/block-caption/index.native.js +++ b/packages/block-editor/src/components/block-caption/index.native.js @@ -54,6 +54,10 @@ export default compose( [ const { caption } = getBlockAttributes( clientId ) || {}; const isBlockSelected = getSelectedBlockClientId() === clientId; + // Detect whether the block is an inner block by checking if it has a parent block. + // getBlockRootClientId() will return an empty string for all top-level blocks. + // If the block is an inner block, its parent may explicitly hide child block controls. + // See: https://github.com/wordpress-mobile/gutenberg-mobile/pull/4256 const parentId = getBlockRootClientId( clientId ); const parentBlockName = getBlockName( parentId );