-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge mobile refactor of gallery to nested image blocks into desktop …
…refactor PR(#31306) * Move native v1 Gallery components to v1 directory * Use v1 defaultColumnsNumber in native v1 gallery * Make onFocus optional in MediaPlaceholder * Add useInnerBlocksProps hook * Enable __experimentalGalleryRefactor flag under __DEV__ * Add numColumns to block-list flat list * Fix spacing * Adjust styles to avoid appender overlap * Add gallery caption * Fix lint Some of these "fixes" are simply disabling lint for the offending lines. These currently unused variables may be used in a later PR, so I'm leaving them in, for now, to help simplify reconciling the changes from the former refactor PR. * Fix sass lint * [Mobile] - Refactor gallery - cherry pick image edit native (#31826) * Remove duplicate / conflicting methods from performance refactor * Use context for imageCrop and isGrouped instead of isGallery * Remove non-existent inheritedAttributes attribute * Remove dead code from non-existent context attributes * Remove unused attributes prop from link settings * Cherry-pick BlockListItem changes Note: Since render was changed to renderContent, we should return early from render too, when blockWidth is falsey. * Return early from render instead of renderContent * Cherry-pick plumb blockProps through BlockListBlock I'm not sure yet whether it still makes sense to use blockProps in this way. I'm going to cherry-pick the commits by file, and sort out the need for this mechanism afterwards. * Cherry-pick add GridItem Since this is duplicated from the original mobile gallery code (Tiles component), it might make sense to export it for re-use. Previously, it was only moved, but now that we will maintain both versions, it has become a duplicate implementation. I will defer this to a later commit. * Cherry-pick BlockList Similar to blockProps mentioned earlier, gridProperties will be evaluated after cherry-picking the relevant changes, to see if there is another mechanism that may be more appropriate. * Cherry-pick StylePreview key change * Cherry-pick blockProps and gridProperties in InnerBlocks * Use sass var for galleryAppender padding Note: This also re-adds fullWidth style, which is still being used in both v1 and v2 mobile implementations. If this is superceded by a recent refactor of the block width styles, it may be worth revisiting this and removing / changing the implementation. * Cherry-pick remaining gallery changes Note: as before, blockProps and gridProperties should be re-evaluated in subsequent commits, if necessary. E.g. `imageCrop` is already recieved via context, and `isGroup` may be sufficient, eliminating the need for `isGallery`. * Remove numColumns Going back over the older commits, it seems there were a two strategies used to render the gallery images as a grid. One used the numColumns (same as used in the Columns block), and the other using the Grid component. This commit cleans up the unused parts of the former approach. * Remove blockProps This is no longer necessary, since we are using context to pass gallery-level attributes to the image blocks' rendering. * Fix gallery block.json (delete extra comma) * Remove unused imageCrop * Add back blockWidth contentContainerStyles in block list * Use boolean flags for variants in Platform module These flags allow for a slightly more flexible, performant, and terse way of branching by platform. For more details, see: #18058 (comment) * Use boolean Platform flags * Only render imageSizeOptions loading spinner on web * Add default for destructured context in image edit This is necessary for unit tests, because they instantiate the block's edit component directly, and so the default context is not provided. * Temporarily hard-code experimenal gallery refactor flag to true This will be reverted once the block settings are fetched from the REST API. This is enabled for now for testing purposes. * Update experiments page with warning about the mobile app version * Changes new gallery flag name * Updates mobile warning * Removes the imageCount attribute * Remove the isGrouped context * Fixes lint issue Co-authored-by: Antonis Lilis <[email protected]>
- Loading branch information
Showing
25 changed files
with
458 additions
and
142 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,7 @@ | |
.fullAlignmentPadding { | ||
padding: $block-edge-to-content; | ||
} | ||
|
||
.gridItem { | ||
overflow: visible; | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/block-editor/src/components/block-list/grid-item.native.js
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,58 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './block-list-item.scss'; | ||
|
||
function Grid( props ) { | ||
/** | ||
* Since we don't have `calc()`, we must calculate our spacings here in | ||
* order to preserve even spacing between tiles and equal width for tiles | ||
* in a given row. | ||
* | ||
* In order to ensure equal sizing of tile contents, we distribute the | ||
* spacing such that each tile has an equal "share" of the fixed spacing. To | ||
* keep the tiles properly aligned within their rows, we calculate the left | ||
* and right paddings based on the tile's relative position within the row. | ||
* | ||
* Note: we use padding instead of margins so that the fixed spacing is | ||
* included within the relative spacing (i.e. width percentage), and | ||
* wrapping behavior is preserved. | ||
* | ||
* - The left most tile in a row must have left padding of zero. | ||
* - The right most tile in a row must have a right padding of zero. | ||
* | ||
* The values of these left and right paddings are interpolated for tiles in | ||
* between. The right padding is complementary with the left padding of the | ||
* next tile (i.e. the right padding of [tile n] + the left padding of | ||
* [tile n + 1] will be equal for all tiles except the last one in a given | ||
* row). | ||
* | ||
*/ | ||
const { numOfColumns, children, tileCount, index, maxWidth } = props; | ||
const lastTile = tileCount - 1; | ||
const lastRow = Math.floor( lastTile / numOfColumns ); | ||
|
||
const row = Math.floor( index / numOfColumns ); | ||
const rowLength = | ||
row === lastRow ? ( lastTile % numOfColumns ) + 1 : numOfColumns; | ||
|
||
return ( | ||
<View | ||
style={ [ | ||
{ | ||
width: maxWidth / rowLength, | ||
}, | ||
styles.gridItem, | ||
] } | ||
> | ||
{ children } | ||
</View> | ||
); | ||
} | ||
|
||
export default Grid; |
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
6 changes: 4 additions & 2 deletions
6
packages/block-library/src/gallery/gallery-styles.native.scss
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
Oops, something went wrong.