-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] List V2 Support #42702
Merged
Merged
[Mobile] List V2 Support #42702
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e4e7b80
Mobile - BlockList - Only render ListEmptyComponent at root level
a69486c
Mobile - Register ListItem block
c73ca23
ListItem block - Export IdentUI to share it with Mobile
b73c2be
Mobile - Export useRefEffect
589c987
List V2 - Make it compatible with mobile by passing two props to thei…
a8e4e5c
Mobile - ListItem block - Add native variant
9094e3b
List V2 - Add style prop for mobile
ea6067f
Mobile - ListItem block - Add color customization support
281d792
Mobile - ListItem - Pass style instead of specific values to prevent …
b0621f0
Mobile - Add List V2 feature flag
0eeb139
Merge branch 'trunk' into rnmobile/list-v2
21c3d36
[Mobile] - List V2 - List Style Type (#42703)
14edb0c
Mobile - Update CHANGELOG
76b3d02
Mobile - List Block V2 - Unit tests
4e3c015
Mobile - BlockList - Fix appender
9b4b45a
Mobile - RichText - Add container width prop
d694c0e
Mobile - List V2 - Fix issue on Android where the font size / line-he…
8ccdd35
List V2 - Move TagName to its own file with both web and native variant
aa84328
Mobile - Update RichText snapshots
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
RichText, | ||
useBlockProps, | ||
useInnerBlocksProps, | ||
BlockControls, | ||
store as blockEditorStore, | ||
} from '@wordpress/block-editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { useState, useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useSplit, useMerge } from './hooks'; | ||
import { convertToListItems } from './utils'; | ||
import { IndentUI } from './edit.js'; | ||
import styles from './style.scss'; | ||
import ListStyleType from './list-style-type'; | ||
|
||
export default function ListItemEdit( { | ||
attributes, | ||
setAttributes, | ||
onReplace, | ||
clientId, | ||
style, | ||
} ) { | ||
const [ contentWidth, setContentWidth ] = useState(); | ||
const { placeholder, content } = attributes; | ||
const { | ||
blockIndex, | ||
hasInnerBlocks, | ||
indentationLevel, | ||
numberOfListItems, | ||
ordered, | ||
reversed, | ||
start, | ||
} = useSelect( | ||
( select ) => { | ||
const { | ||
getBlockAttributes, | ||
getBlockCount, | ||
getBlockIndex, | ||
getBlockParentsByBlockName, | ||
getBlockRootClientId, | ||
} = select( blockEditorStore ); | ||
const currentIdentationLevel = getBlockParentsByBlockName( | ||
clientId, | ||
'core/list-item', | ||
true | ||
).length; | ||
const currentBlockIndex = getBlockIndex( clientId ); | ||
const blockWithInnerBlocks = getBlockCount( clientId ) > 0; | ||
const rootClientId = getBlockRootClientId( clientId ); | ||
const blockAttributes = getBlockAttributes( rootClientId ); | ||
const totalListItems = getBlockCount( rootClientId ); | ||
const { | ||
ordered: isOrdered, | ||
reversed: isReversed, | ||
start: startValue, | ||
} = blockAttributes || {}; | ||
|
||
return { | ||
blockIndex: currentBlockIndex, | ||
hasInnerBlocks: blockWithInnerBlocks, | ||
indentationLevel: currentIdentationLevel, | ||
numberOfListItems: totalListItems, | ||
ordered: isOrdered, | ||
reversed: isReversed, | ||
start: startValue, | ||
}; | ||
}, | ||
[ clientId ] | ||
); | ||
|
||
const blockProps = useBlockProps( { | ||
...( hasInnerBlocks && styles[ 'wp-block-list-item__nested-blocks' ] ), | ||
} ); | ||
const innerBlocksProps = useInnerBlocksProps( blockProps, { | ||
allowedBlocks: [ 'core/list' ], | ||
renderAppender: false, | ||
} ); | ||
|
||
const onSplit = useSplit( clientId ); | ||
const onMerge = useMerge( clientId ); | ||
const onLayout = useCallback( ( { nativeEvent } ) => { | ||
setContentWidth( ( prevState ) => { | ||
const { width } = nativeEvent.layout; | ||
|
||
if ( ! prevState || prevState.width !== width ) { | ||
return Math.floor( width ); | ||
} | ||
return prevState; | ||
} ); | ||
}, [] ); | ||
|
||
return ( | ||
<View style={ styles[ 'wp-block-list-item__list-item-parent' ] }> | ||
<View style={ styles[ 'wp-block-list-item__list-item' ] }> | ||
<View style={ styles[ 'wp-block-list-item__list-item-icon' ] }> | ||
<ListStyleType | ||
blockIndex={ blockIndex } | ||
indentationLevel={ indentationLevel } | ||
numberOfListItems={ numberOfListItems } | ||
ordered={ ordered } | ||
reversed={ reversed } | ||
start={ start } | ||
style={ style } | ||
/> | ||
</View> | ||
<View | ||
style={ styles[ 'wp-block-list-item__list-item-content' ] } | ||
onLayout={ onLayout } | ||
> | ||
<RichText | ||
identifier="content" | ||
tagName="p" | ||
onChange={ ( nextContent ) => | ||
setAttributes( { content: nextContent } ) | ||
} | ||
value={ content } | ||
placeholder={ placeholder || __( 'List' ) } | ||
onSplit={ onSplit } | ||
onMerge={ onMerge } | ||
onReplace={ ( blocks, ...args ) => { | ||
onReplace( convertToListItems( blocks ), ...args ); | ||
} } | ||
style={ style } | ||
deleteEnter={ true } | ||
containerWidth={ contentWidth } | ||
/> | ||
</View> | ||
</View> | ||
<View { ...innerBlocksProps }></View> | ||
<BlockControls group="block"> | ||
<IndentUI clientId={ clientId } /> | ||
</BlockControls> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SVG, Rect } from '@wordpress/components'; | ||
|
||
export const circle = ( size, color ) => ( | ||
<SVG fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<Rect width={ size } height={ size } rx={ size / 2 } fill={ color } /> | ||
</SVG> | ||
); | ||
|
||
export const circleOutline = ( size, color ) => ( | ||
<SVG | ||
width={ size } | ||
height={ size } | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<Rect | ||
x="0.5" | ||
y="0.5" | ||
width={ size - 1 } | ||
height={ size - 1 } | ||
rx={ size / 2 } | ||
stroke={ color } | ||
/> | ||
</SVG> | ||
); | ||
|
||
export const square = ( size, color ) => ( | ||
<SVG fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<Rect width={ size } height={ size } fill={ color } /> | ||
</SVG> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This export is needed to share it with the mobile variant of the
ListItem
block