Skip to content

Commit

Permalink
Adjust ReadableContentView when parent is full width
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewalczak committed Sep 9, 2020
1 parent 9b8531a commit d248738
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export class BlockListItem extends Component {
shouldShowInsertionPointAfter,
contentResizeMode,
shouldShowInnerBlockAppender,
parentBlockAlignment,
blockName,
...restProps
} = this.props;
const readableContentViewStyle =
Expand All @@ -106,7 +108,9 @@ export class BlockListItem extends Component {
return (
<ReadableContentView
align={ blockAlignment }
parentBlockAlignment={ parentBlockAlignment }
style={ readableContentViewStyle }
blockName={ blockName }
>
<View
style={ this.getContentStyles( readableContentViewStyle ) }
Expand Down Expand Up @@ -170,6 +174,7 @@ export default compose( [

const block = __unstableGetBlockWithoutInnerBlocks( clientId );
const { attributes } = block || {};
const blockName = block.name || '';
const { align } = attributes || {};
const parents = getBlockParents( clientId, true );
const hasParents = !! parents.length;
Expand All @@ -186,6 +191,7 @@ export default compose( [
hasParents,
blockAlignment: align,
parentBlockAlignment,
blockName,
};
}
),
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/column/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
PanelBody,
RangeControl,
FooterMessageControl,
ALIGNMENT_BREAKPOINTS,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
Expand Down Expand Up @@ -119,7 +120,8 @@ function ColumnEdit( {
getContainerWidth( newParentWidth )
);

const finalWidth = hasWidth && { width: newColumnWidth };
const finalWidth = parentWidth > ALIGNMENT_BREAKPOINTS.medium &&
hasWidth && { width: newColumnWidth };

if ( ! isSelected && ! hasChildren ) {
return (
Expand Down
7 changes: 4 additions & 3 deletions packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ function ColumnsEditContainer( {
}, [ width ] );

const contentStyle = useMemo( () => {
const columnBaseWidth = width / columnsInRow;
const minWidth = 2 * 8 + width;
const columnBaseWidth = minWidth / columnsInRow;

let columnWidth = columnBaseWidth;
if ( columnsInRow > 1 ) {
const margins = columnsInRow * 2 * 16;
columnWidth = ( width - margins ) / columnsInRow;
const margins = columnsInRow * 2 * styles.columnMargin.marginLeft;
columnWidth = ( minWidth - margins ) / columnsInRow;
}
return { width: columnWidth };
}, [ width, columnsInRow ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ import styles from './style.scss';

const PIXEL_RATIO = 2;

const ReadableContentView = ( { align, reversed, children, style } ) => {
const ReadableContentView = ( {
align,
reversed,
children,
style,
parentBlockAlignment,
blockName,
} ) => {
const { width, height } = Dimensions.get( 'window' );
const [ windowWidth, setWindowWidth ] = useState( width );
const [ windowRatio, setWindowRatio ] = useState( width / height );

const isColumn = blockName === 'core/column';

function onDimensionsChange( { window } ) {
setWindowWidth( window.width );
setWindowRatio( window.width / window.height );
Expand Down Expand Up @@ -66,6 +75,7 @@ const ReadableContentView = ( { align, reversed, children, style } ) => {
: styles.centeredContent,
style,
styles[ align ],
parentBlockAlignment === 'full' && isColumn && styles.full,
align === WIDE_ALIGNMENTS.alignments.wide &&
getWideStyles(),
] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

.centeredContent {
width: 100%;
// max-width: 580;
max-width: 580;
}

.reversedCenteredContent {
Expand Down

0 comments on commit d248738

Please sign in to comment.