Skip to content

Commit

Permalink
[Mobile] Improve List block onSplit to avoid hiding the keyboard on e…
Browse files Browse the repository at this point in the history
…nter (WordPress#62446)

* Native RichText - Add __unstableUseSplitSelection prop

* Native List block - Use __unstableUseSplitSelection prop and remove custom onSplit and onReplace functionality

* Update changelog

* Fix changelog after fixing conflict

Co-authored-by: geriux <geriux@git.wordpress.org>
Co-authored-by: twstokes <twstokes@git.wordpress.org>
Co-authored-by: fluiddot <carlosgprim@git.wordpress.org>
  • Loading branch information
4 people authored and patil-vipul committed Jun 17, 2024
1 parent 113334f commit 00c1b83
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function RichTextWrapper(
unstableOnFocus,
__unstableAllowPrefixTransformations,
// Native props.
__unstableUseSplitSelection,
__unstableMobileNoFocusOnMount,
deleteEnter,
placeholderTextColor,
Expand Down Expand Up @@ -178,6 +179,7 @@ export function RichTextWrapper(
exitFormattedText,
selectionChange,
__unstableMarkAutomaticChange,
__unstableSplitSelection,
clearSelectedBlock,
} = useDispatch( blockEditorStore );
const adjustedAllowedFormats = getAllowedFormats( {
Expand Down Expand Up @@ -345,6 +347,8 @@ export function RichTextWrapper(
}
} else if ( canSplit ) {
splitValue( value );
} else if ( __unstableUseSplitSelection ) {
__unstableSplitSelection();
} else if ( canSplitAtEnd ) {
onSplitAtEnd();
} else if (
Expand Down
24 changes: 2 additions & 22 deletions packages/block-library/src/list-item/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { useState, useCallback, useRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useSplit, useMerge, useEnter } from './hooks';
import { convertToListItems } from './utils';
import { useMerge, useEnter } from './hooks';
import { IndentUI } from './edit.js';
import styles from './style.scss';
import ListStyleType from './list-style-type';
Expand All @@ -32,7 +31,6 @@ const OPACITY = '9e';
export default function ListItemEdit( {
attributes,
setAttributes,
onReplace,
clientId,
style,
mergeBlocks,
Expand Down Expand Up @@ -118,24 +116,7 @@ export default function ListItemEdit( {

const preventDefault = useRef( false );
const { onEnter } = useEnter( { content, clientId }, preventDefault );
const onSplit = useSplit( clientId );
const onMerge = useMerge( clientId, mergeBlocks );
const onSplitList = useCallback(
( value ) => {
if ( ! preventDefault.current ) {
return onSplit( value );
}
},
[ clientId, onSplit ]
);
const onReplaceList = useCallback(
( blocks, ...args ) => {
if ( ! preventDefault.current ) {
onReplace( convertToListItems( blocks ), ...args );
}
},
[ clientId, onReplace, convertToListItems ]
);
const onLayout = useCallback( ( { nativeEvent } ) => {
setContentWidth( ( prevState ) => {
const { width } = nativeEvent.layout;
Expand Down Expand Up @@ -166,6 +147,7 @@ export default function ListItemEdit( {
onLayout={ onLayout }
>
<RichText
__unstableUseSplitSelection
identifier="content"
tagName="p"
onChange={ ( nextContent ) =>
Expand All @@ -176,9 +158,7 @@ export default function ListItemEdit( {
placeholderTextColor={
defaultPlaceholderTextColorWithOpacity
}
onSplit={ onSplitList }
onMerge={ onMerge }
onReplace={ onReplaceList }
onEnter={ onEnter }
style={ styleWithPlaceholderOpacity }
deleteEnter
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For each user feature we should also add a importance categorization label to i

## Unreleased
- [internal] Fix Inserter items list filtering [#62334]
- [*] Prevent hiding the keyboard when creating new list items [#62446]

## 1.120.0
- [*] Prevent deleting content when backspacing in the first Paragraph block [#62069]
Expand Down

0 comments on commit 00c1b83

Please sign in to comment.