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

Add native support for the MediaText block #16305

Merged
merged 21 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c3fbe4c
First working version of the MediaText component for native mobile
Tug Jun 26, 2019
2f26450
Fix adding a block to an innerblock list
Tug Jun 27, 2019
fe3cb13
Disable mediaText on production
Tug Jul 9, 2019
d4b30d8
MediaText native: improve editor visuals
Tug Jul 16, 2019
a390c7e
Move BlockToolbar from BlockList to Layout
Tug Jul 17, 2019
2bc590b
Remove BlockEditorProvider from BlockList and add native version of E…
Tug Jul 19, 2019
80e4e94
Update BlockMover for native to hide if locked or if it's the only block
Tug Aug 6, 2019
2ef9cff
Make the vertical align button work, add more styling options for too…
Tug Aug 6, 2019
dff6ef7
Make sure registerCoreBlocks does not break in production
Tug Aug 14, 2019
c62606b
Copy docblock comment from the web version for registerCoreBlocks
Tug Aug 14, 2019
201dd3e
Fix focusing on the media placeholder
Tug Aug 14, 2019
7dc86a4
Only support adding image for now
Tug Aug 14, 2019
f6df91a
Update usage of MediaPlaceholder in MediaContainer
Tug Aug 14, 2019
f91fd8a
Enable autoScroll for just the out most block list
pinarol Aug 22, 2019
cba09ec
Merge branch 'rnmobile/master' into rnmobile/add/media-text
etoledom Aug 28, 2019
4173518
Fix JS Unit tests
etoledom Aug 28, 2019
bb550ac
Roll back to IconButton refactor and fix tests
etoledom Aug 28, 2019
7818564
Fix BlockVerticalAlignmentToolbar buttons style on mobile
etoledom Aug 28, 2019
dbe42d3
Fix thing for web and ensure ariaPressed is always passed down
gziolo Aug 29, 2019
f05d666
Use AriaPressed directly to style SVG on mobile
etoledom Aug 29, 2019
7794404
Update snapshots
etoledom Aug 29, 2019
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
30 changes: 30 additions & 0 deletions packages/block-editor/src/components/block-icon/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* External dependencies
*/
import { get } from 'lodash';
import { View } from 'react-native';

/**
* WordPress dependencies
*/
import { Path, Icon, SVG } from '@wordpress/components';

export default function BlockIcon( { icon, showColors = false } ) {
if ( get( icon, [ 'src' ] ) === 'block-default' ) {
icon = {
src: <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M19 7h-1V5h-4v2h-4V5H6v2H5c-1.1 0-2 .9-2 2v10h18V9c0-1.1-.9-2-2-2zm0 10H5V9h14v8z" /></SVG>,
};
}

const renderedIcon = <Icon icon={ icon && icon.src ? icon.src : icon } />;
const style = showColors ? {
backgroundColor: icon && icon.background,
color: icon && icon.foreground,
} : {};

return (
<View style={ style }>
{ renderedIcon }
</View>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import DefaultBlockAppender from '../default-block-appender';
import styles from './style.scss';

function BlockListAppender( {
blockClientIds,
rootClientId,
canInsertDefaultBlock,
isLocked,
} ) {
if ( isLocked ) {
return null;
}

if ( canInsertDefaultBlock ) {
return (
<DefaultBlockAppender
rootClientId={ rootClientId }
lastBlockClientId={ last( blockClientIds ) }
containerStyle={ styles.blockListAppender }
placeholder={ blockClientIds.length > 0 ? '' : null }
/>
);
}

return null;
}

export default withSelect( ( select, { rootClientId } ) => {
const {
getBlockOrder,
canInsertBlockType,
getTemplateLock,
} = select( 'core/block-editor' );

return {
isLocked: !! getTemplateLock( rootClientId ),
blockClientIds: getBlockOrder( rootClientId ),
canInsertDefaultBlock: canInsertBlockType( getDefaultBlockName(), rootClientId ),
};
} )( BlockListAppender );
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

.blockListAppender {
background-color: $white;
padding-left: 16;
padding-right: 16;
padding-top: 12;
padding-bottom: 0; // will be flushed into inline toolbar height
border-color: transparent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class BlockList extends Component {
<KeyboardAwareFlatList
{ ...( Platform.OS === 'android' ? { removeClippedSubviews: false } : {} ) } // Disable clipping on Android to fix focus losing. See https://github.com/wordpress-mobile/gutenberg-mobile/pull/741#issuecomment-472746541
accessibilityLabel="block-list"
autoScroll={ this.props.autoScroll }
innerRef={ this.scrollViewInnerRef }
extraScrollHeight={ innerToolbarHeight + 10 }
keyboardShouldPersistTaps="always"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import { Text, View } from 'react-native';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import styles from './style.scss';

const BlockInsertionPoint = ( { showInsertionPoint } ) => {
if ( ! showInsertionPoint ) {
return null;
}

return (
<View style={ styles.containerStyleAddHere } >
<View style={ styles.lineStyleAddHere }></View>
<Text style={ styles.labelStyleAddHere } >{ __( 'ADD BLOCK HERE' ) }</Text>
<View style={ styles.lineStyleAddHere }></View>
</View>
);
};

export default withSelect( ( select, { clientId, rootClientId } ) => {
const {
getBlockIndex,
getBlockInsertionPoint,
isBlockInsertionPointVisible,
} = select( 'core/block-editor' );
const blockIndex = getBlockIndex( clientId, rootClientId );
const insertionPoint = getBlockInsertionPoint();
const showInsertionPoint = (
isBlockInsertionPointVisible() &&
insertionPoint.index === blockIndex &&
insertionPoint.rootClientId === rootClientId
);

return { showInsertionPoint };
} )( BlockInsertionPoint );
82 changes: 46 additions & 36 deletions packages/block-editor/src/components/block-mover/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,59 @@ import { withInstanceId, compose } from '@wordpress/compose';
const BlockMover = ( {
isFirst,
isLast,
isLocked,
onMoveDown,
onMoveUp,
firstIndex,
} ) => (
<>
<ToolbarButton
title={ ! isFirst ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block up from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex
) :
__( 'Move block up' )
}
isDisabled={ isFirst }
onClick={ onMoveUp }
icon="arrow-up-alt"
extraProps={ { hint: __( 'Double tap to move the block up' ) } }
/>
rootClientId,
} ) => {
if ( isLocked || ( isFirst && isLast && ! rootClientId ) ) {
return null;
}

<ToolbarButton
title={ ! isLast ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block down from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex + 2
) :
__( 'Move block down' )
}
isDisabled={ isLast }
onClick={ onMoveDown }
icon="arrow-down-alt"
extraProps={ { hint: __( 'Double tap to move the block down' ) } }
/>
</>
);
return (
<>
<ToolbarButton
title={ ! isFirst ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block up from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex
) :
__( 'Move block up' )
}
isDisabled={ isFirst }
onClick={ onMoveUp }
icon="arrow-up-alt"
extraProps={ { hint: __( 'Double tap to move the block up' ) } }
/>

<ToolbarButton
title={ ! isLast ?
sprintf(
/* translators: accessibility text. %1: current block position (number). %2: next block position (number) */
__( 'Move block down from row %1$s to row %2$s' ),
firstIndex + 1,
firstIndex + 2
) :
__( 'Move block down' )
}
isDisabled={ isLast }
onClick={ onMoveDown }
icon="arrow-down-alt"
extraProps={ { hint: __( 'Double tap to move the block down' ) } }
/>
</>
);
};

export default compose(
withSelect( ( select, { clientIds } ) => {
const { getBlockIndex, getBlockRootClientId, getBlockOrder } = select( 'core/block-editor' );
const { getBlockIndex, getTemplateLock, getBlockRootClientId, getBlockOrder } = select( 'core/block-editor' );
const normalizedClientIds = castArray( clientIds );
const firstClientId = first( normalizedClientIds );
const rootClientId = getBlockRootClientId( first( normalizedClientIds ) );
const rootClientId = getBlockRootClientId( firstClientId );
const blockOrder = getBlockOrder( rootClientId );
const firstIndex = getBlockIndex( firstClientId, rootClientId );
const lastIndex = getBlockIndex( last( normalizedClientIds ), rootClientId );
Expand All @@ -67,6 +75,8 @@ export default compose(
firstIndex,
isFirst: firstIndex === 0,
isLast: lastIndex === blockOrder.length - 1,
isLocked: getTemplateLock( rootClientId ) === 'all',
rootClientId,
};
} ),
withDispatch( ( dispatch, { clientIds, rootClientId } ) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/components/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
export { default as BlockControls } from './block-controls';
export { default as BlockEdit } from './block-edit';
export { default as BlockFormatControls } from './block-format-controls';
export { default as BlockIcon } from './block-icon';
export { default as BlockVerticalAlignmentToolbar } from './block-vertical-alignment-toolbar';
export * from './colors';
export * from './font-sizes';
export { default as AlignmentToolbar } from './alignment-toolbar';
export { default as InnerBlocks } from './inner-blocks';
export { default as InspectorControls } from './inspector-controls';
export { default as PlainText } from './plain-text';
export {
Expand Down
Loading