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] Enable child block caption field to be hidden by parent blocks #36618

Merged
merged 3 commits into from
Nov 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/block-editor/src/components/block-caption/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,16 +45,33 @@ 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;

// 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 );

const hideCaption = hasBlockSupport(
guarani marked this conversation as resolved.
Show resolved Hide resolved
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 =
! RichText.isEmpty( caption ) > 0 || isBlockSelected;
! hideCaption &&
( ! RichText.isEmpty( caption ) > 0 || isBlockSelected );

return {
shouldDisplay,
Expand Down