Skip to content

Commit

Permalink
[RNMobile] update mobile to not use ListEdit
Browse files Browse the repository at this point in the history
This update is in response to changes made on the web side in #15113
that were causing a crash on mobile.
  • Loading branch information
mchowning committed Aug 16, 2019
1 parent 15f5ff4 commit 2c503a6
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 10 deletions.
12 changes: 2 additions & 10 deletions packages/block-editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@ import Autocomplete from '../autocomplete';
import BlockFormatControls from '../block-format-controls';
import FormatToolbar from './format-toolbar';
import { withBlockEditContext } from '../block-edit/context';
import { ListEdit } from './list-edit';

const wrapperClasses = 'editor-rich-text block-editor-rich-text';
const classes = 'editor-rich-text__editable block-editor-rich-text__editable';

function RichTextWraper( {
children,
tagName,
value: originalValue,
onChange: originalOnChange,
selectionStart,
selectionEnd,
onSelectionChange,
multiline,
onTagNameChange,
inlineToolbar,
wrapperClassName,
className,
Expand Down Expand Up @@ -86,14 +85,7 @@ function RichTextWraper( {
>
{ ( { isSelected, value, onChange } ) =>
<View>
{ isSelected && multiline === 'li' && (
<ListEdit
onTagNameChange={ onTagNameChange }
tagName={ tagName }
value={ value }
onChange={ onChange }
/>
) }
{ children && children( { value, onChange } ) }
{ isSelected && ! inlineToolbar && (
<BlockFormatControls>
<FormatToolbar />
Expand Down
139 changes: 139 additions & 0 deletions packages/block-library/src/list/edit.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
import {
RichText,
BlockControls,
RichTextShortcut,
} from '@wordpress/block-editor';
import {
Toolbar,
} from '@wordpress/components';
import {
__unstableIndentListItems as indentListItems,
__unstableOutdentListItems as outdentListItems,
__unstableChangeListType as changeListType,
__unstableIsListRootSelected as isListRootSelected,
__unstableIsActiveListType as isActiveListType,
} from '@wordpress/rich-text';

/**
* Internal dependencies
*/
import { name } from './';

export default function ListEdit( {
attributes,
setAttributes,
mergeBlocks,
onReplace,
className,
} ) {
const { ordered, values } = attributes;
const tagName = ordered ? 'ol' : 'ul';

const controls = ( { value, onChange } ) => {
if ( value.start === undefined ) {
return;
}

return <>
<RichTextShortcut
type="primary"
character="["
onUse={ () => {
onChange( outdentListItems( value ) );
} }
/>
<RichTextShortcut
type="primary"
character="]"
onUse={ () => {
onChange( indentListItems( value, { type: tagName } ) );
} }
/>
<RichTextShortcut
type="primary"
character="m"
onUse={ () => {
onChange( indentListItems( value, { type: tagName } ) );
} }
/>
<RichTextShortcut
type="primaryShift"
character="m"
onUse={ () => {
onChange( outdentListItems( value ) );
} }
/>
<BlockControls>
<Toolbar
controls={ [
{
icon: 'editor-ul',
title: __( 'Convert to unordered list' ),
isActive: isActiveListType( value, 'ul', tagName ),
onClick() {
onChange( changeListType( value, { type: 'ul' } ) );

if ( isListRootSelected( value ) ) {
setAttributes( { ordered: false } );
}
},
},
{
icon: 'editor-ol',
title: __( 'Convert to ordered list' ),
isActive: isActiveListType( value, 'ol', tagName ),
onClick() {
onChange( changeListType( value, { type: 'ol' } ) );

if ( isListRootSelected( value ) ) {
setAttributes( { ordered: true } );
}
},
},
{
icon: 'editor-outdent',
title: __( 'Outdent list item' ),
shortcut: _x( 'Backspace', 'keyboard key' ),
onClick() {
onChange( outdentListItems( value ) );
},
},
{
icon: 'editor-indent',
title: __( 'Indent list item' ),
shortcut: _x( 'Space', 'keyboard key' ),
onClick() {
onChange( indentListItems( value, { type: tagName } ) );
},
},
] }
/>
</BlockControls>
</>;
};

return (
<RichText
identifier="values"
multiline="li"
tagName={ tagName }
onChange={ ( nextValues ) => setAttributes( { values: nextValues } ) }
value={ values }
wrapperClassName="block-library-list"
className={ className }
placeholder={ __( 'Write list…' ) }
onMerge={ mergeBlocks }
onSplit={ ( value ) => createBlock( name, { ordered, values: value } ) }
__unstableOnSplitMiddle={ () => createBlock( 'core/paragraph' ) }
onReplace={ onReplace }
onRemove={ () => onReplace( [] ) }
>
{ controls }
</RichText>
);
}

0 comments on commit 2c503a6

Please sign in to comment.