Skip to content

Commit

Permalink
Adjust margin for containers
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Sep 25, 2020
1 parent 451dc09 commit 73b2181
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import BlockListBlock from './block';
import BlockInsertionPoint from './insertion-point';
import styles from './block-list-item.native.scss';

export const INNER_CONTAINERS = [ 'core/columns', 'core/column', 'core/group' ];

const stretchStyle = {
flex: 1,
};
Expand Down Expand Up @@ -53,22 +55,22 @@ export class BlockListItem extends Component {
parentBlockAlignment,
hasParents,
blockName,
isColumnsDescendantSelected,
isContainerDescendantSelected,
} = this.props;
const { blockWidth } = this.state;
const isFullWidth = blockAlignment === WIDE_ALIGNMENTS.alignments.full;
const isWideWidth = blockAlignment === WIDE_ALIGNMENTS.alignments.wide;
const isParentFullWidth =
parentBlockAlignment === WIDE_ALIGNMENTS.alignments.full;
const isColumnsRelated = blockName.includes( 'core/column' );
const isContainerRelated = INNER_CONTAINERS.includes( blockName );

if ( isFullWidth ) {
if ( ! hasParents ) {
if (
isColumnsRelated &&
isContainerRelated &&
blockWidth < ALIGNMENT_BREAKPOINTS.mobile
) {
if ( isColumnsDescendantSelected ) {
if ( isContainerDescendantSelected ) {
return 0;
}
return marginHorizontal;
Expand All @@ -86,7 +88,7 @@ export class BlockListItem extends Component {
if (
isParentFullWidth &&
blockWidth <= ALIGNMENT_BREAKPOINTS.medium &&
! isColumnsRelated
! isContainerRelated
) {
return marginHorizontal * 2;
}
Expand Down Expand Up @@ -207,21 +209,22 @@ export default compose( [
parentBlock?.attributes || {};

const selectedBlockId = getSelectedBlockClientId();
const selectedBlockParents = getBlockParents(
const selectedBlockParentId = getBlockParents(
selectedBlockId
)[ 0 ];
const { name: selectedBlockParentsName } =
__unstableGetBlockWithoutInnerBlocks( selectedBlockParents ) ||
__unstableGetBlockWithoutInnerBlocks( selectedBlockParentId ) ||
{};

const isRootInnerBlockSelected = hasSelectedInnerBlock(
rootClientId
const isInnerBlockSelected =
hasParents && hasSelectedInnerBlock( clientId );

const isContainerBlock = INNER_CONTAINERS.includes(
selectedBlockParentsName
);

const isColumnsDescendantSelected = selectedBlockParentsName?.includes(
'core/column'
)
? isRootInnerBlockSelected
const isContainerDescendantSelected = isContainerBlock
? isInnerBlockSelected
: true;

return {
Expand All @@ -232,7 +235,7 @@ export default compose( [
blockAlignment: align,
parentBlockAlignment,
blockName: name,
isColumnsDescendantSelected,
isContainerDescendantSelected,
};
}
),
Expand Down
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/block-list/block.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { View, Text, TouchableWithoutFeedback, Dimensions } from 'react-native';
* WordPress dependencies
*/
import { Component, createRef } from '@wordpress/element';
import { GlobalStylesContext, WIDE_ALIGNMENTS } from '@wordpress/components';
import {
GlobalStylesContext,
WIDE_ALIGNMENTS,
ALIGNMENT_BREAKPOINTS,
} from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose, withPreferredColorScheme } from '@wordpress/compose';
import {
Expand Down Expand Up @@ -153,7 +157,10 @@ class BlockListBlock extends Component {
const isColumnsRelated = name.includes( 'core/column' );
const shouldBeFullWidth =
isFullWidth &&
( ! isColumnsRelated || ! hasParents || hasParentBlockAlignment );
( ! isColumnsRelated ||
! hasParents ||
( hasParentBlockAlignment &&
blockWidth > ALIGNMENT_BREAKPOINTS.mobile ) );

return (
<TouchableWithoutFeedback
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function ColumnsEditContainer( {
onDeleteBlock,
innerColumns,
updateInnerColumnWidth,
hasParents,
} ) {
const [ resizeListener, sizes ] = useResizeObserver();
const [ columnsInRow, setColumnsInRow ] = useState( MIN_COLUMNS_NUM );
Expand Down Expand Up @@ -250,7 +249,7 @@ function ColumnsEditContainer( {
const renderAppender = () => {
const isFullWidth = align === WIDE_ALIGNMENTS.alignments.full;
const isFullWidthAppender =
isFullWidth && ! hasParents && width > ALIGNMENT_BREAKPOINTS.mobile;
isFullWidth && width > ALIGNMENT_BREAKPOINTS.mobile;

if ( isSelected ) {
return (
Expand Down

0 comments on commit 73b2181

Please sign in to comment.