Skip to content

Commit

Permalink
[RNMobile] Media & Text alignment options (#18300)
Browse files Browse the repository at this point in the history
* Correct media text alignments

* Unblock alignment options in Media & Text component

* Fix images layout in media text

* Set center alignment by default, revert shouldStack changes
  • Loading branch information
lukewalczak authored Nov 8, 2019
1 parent eba7de4 commit 2c3310f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export class BlockList extends Component {
}

render() {
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender, isFirstBlock, selectedBlockParentId } = this.props;
const { clearSelectedBlock, blockClientIds, isFullyBordered, title, header, withFooter = true, renderAppender, isFirstBlock, selectedBlockParentId, isRootList } = this.props;

const showFloatingToolbar = isFirstBlock && selectedBlockParentId !== '';
return (
<View
style={ { flex: 1 } }
style={ { flex: isRootList ? 1 : 0 } }
onAccessibilityEscape={ clearSelectedBlock }
>
{ showFloatingToolbar && <FloatingToolbar.Slot fillProps={ { innerFloatingToolbar: showFloatingToolbar } } /> }
Expand All @@ -91,7 +91,7 @@ export class BlockList extends Component {
innerRef={ this.scrollViewInnerRef }
extraScrollHeight={ innerToolbarHeight + 10 }
keyboardShouldPersistTaps="always"
style={ styles.list }
scrollViewStyle={ { flex: isRootList ? 1 : 0 } }
data={ blockClientIds }
extraData={ [ isFullyBordered ] }
keyExtractor={ identity }
Expand Down Expand Up @@ -236,6 +236,7 @@ export default compose( [
selectedBlockClientId,
isFirstBlock,
selectedBlockParentId,
isRootList: rootClientId === undefined,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
background-color: #fff;
}

.list {
flex: 1;
}

.switch {
flex-direction: row;
justify-content: flex-start;
Expand Down
15 changes: 7 additions & 8 deletions packages/block-library/src/media-text/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { View } from 'react-native';
import { __ } from '@wordpress/i18n';
import {
BlockControls,
// BlockVerticalAlignmentToolbar,
BlockVerticalAlignmentToolbar,
InnerBlocks,
withColors,
} from '@wordpress/block-editor';
Expand Down Expand Up @@ -131,10 +131,10 @@ class MediaTextEdit extends Component {
attributes,
backgroundColor,
setAttributes,
// isMobile,
// isMobile,
} = this.props;
const {
// isStackedOnMobile,
// isStackedOnMobile,
mediaPosition,
mediaWidth,
verticalAlignment,
Expand All @@ -145,7 +145,7 @@ class MediaTextEdit extends Component {
const widthString = `${ temporaryMediaWidth }%`;
const containerStyles = {
...styles[ 'wp-block-media-text' ],
...styles[ `is-vertically-aligned-${ verticalAlignment }` ],
...styles[ `is-vertically-aligned-${ verticalAlignment || 'center' }` ],
...( mediaPosition === 'right' ? styles[ 'has-media-on-the-right' ] : {} ),
...( shouldStack ? styles[ 'is-stacked-on-mobile' ] : {} ),
...( shouldStack && mediaPosition === 'right' ? styles[ 'is-stacked-on-mobile.has-media-on-the-right' ] : {} ),
Expand All @@ -166,22 +166,21 @@ class MediaTextEdit extends Component {
onClick: () => setAttributes( { mediaPosition: 'right' } ),
} ];

/* const onVerticalAlignmentChange = ( alignment ) => {
const onVerticalAlignmentChange = ( alignment ) => {
setAttributes( { verticalAlignment: alignment } );
}; */
};

return (
<>
<BlockControls>
<Toolbar
controls={ toolbarControls }
/>
{ /* // Temporarily commenting out until alignment functionality is fixed
<BlockVerticalAlignmentToolbar
onChange={ onVerticalAlignmentChange }
value={ verticalAlignment }
isCollapsed={ false }
/> */ }
/>
</BlockControls>
<View style={ containerStyles }>
<View style={ { width: widthString } }>
Expand Down
44 changes: 23 additions & 21 deletions packages/block-library/src/media-text/media-container.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,34 @@ class MediaContainer extends Component {

if ( mediaUrl ) {
return (
<View style={ { flex: 1 } }>
<View>
<MediaUpload
onSelect={ this.onSelectMediaUploadOption }
allowedTypes={ ALLOWED_MEDIA_TYPES }
value={ mediaId }
render={ ( { open, getMediaOptions } ) => {
return <>
{ getMediaOptions() }
{ this.renderToolbarEditButton( open ) }

<MediaUploadProgress
coverUrl={ coverUrl }
mediaId={ mediaId }
onUpdateMediaProgress={ this.updateMediaProgress }
onFinishMediaUploadWithSuccess={ this.finishMediaUploadWithSuccess }
onFinishMediaUploadWithFailure={ this.finishMediaUploadWithFailure }
onMediaUploadStateReset={ this.mediaUploadStateReset }
renderContent={ ( params ) => {
return (
<View style={ styles.content }>
{ this.renderContent( params, open ) }
</View>
);
} }
/>
</>;
return (
<View style={ { flex: 1 } }>
{ getMediaOptions() }
{ this.renderToolbarEditButton( open ) }

<MediaUploadProgress
coverUrl={ coverUrl }
mediaId={ mediaId }
onUpdateMediaProgress={ this.updateMediaProgress }
onFinishMediaUploadWithSuccess={ this.finishMediaUploadWithSuccess }
onFinishMediaUploadWithFailure={ this.finishMediaUploadWithFailure }
onMediaUploadStateReset={ this.mediaUploadStateReset }
renderContent={ ( params ) => {
return (
<View style={ styles.content }>
{ this.renderContent( params, open ) }
</View>
);
} }
/>
</View>
);
} }
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export const KeyboardAwareFlatList = ( {
shouldPreventAutomaticScroll,
innerRef,
autoScroll,
scrollViewStyle,
...listProps
} ) => (
<KeyboardAwareScrollView
style={ { flex: 1 } }
style={ [ { flex: 1 }, scrollViewStyle ] }
keyboardDismissMode="none"
enableResetScrollToCoords={ false }
keyboardShouldPersistTaps="handled"
Expand Down

0 comments on commit 2c3310f

Please sign in to comment.