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

[Mobile] Improve List block onSplit to avoid hiding the keyboard on enter #62446

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading