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

[RNMobile] Gallery block: Re-introduce v1 #41533

Merged
merged 2 commits into from
Jun 14, 2022
Merged
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
31 changes: 22 additions & 9 deletions packages/block-library/src/gallery/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { get, pick } from 'lodash';

/**
* WordPress dependencies
*/
import { Platform } from '@wordpress/element';

export function defaultColumnsNumber( imageCount ) {
return imageCount ? Math.min( 3, imageCount ) : 3;
}
Expand All @@ -23,25 +28,33 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
return imageProps;
};

function getGalleryBlockV2Enabled() {
// We want to fail early here, at least during beta testing phase, to ensure
// there aren't instances where undefined values cause false negatives.
if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) {
throw 'window.wp.galleryBlockV2Enabled is not defined';
}
return window.wp.galleryBlockV2Enabled;
}

/**
* The new gallery block format is not compatible with the use_BalanceTags option
* in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
* window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
* can be removed when minimum supported WP version >=5.9.
*/
export function isGalleryV2Enabled() {
// The logic for the native version is located in a different if statement
// due to a lint rule that prohibits a single conditional combining
// `process.env.IS_GUTENBERG_PLUGIN` with a native platform check.
if ( Platform.isNative ) {
return getGalleryBlockV2Enabled();
}

// Only run the Gallery version compat check if the plugin is running, otherwise
// assume we are in 5.9 core and enable by default.
if ( process.env.IS_GUTENBERG_PLUGIN ) {
// We want to fail early here, at least during beta testing phase, to ensure
// there aren't instances where undefined values cause false negatives.
if (
! window.wp ||
typeof window.wp.galleryBlockV2Enabled !== 'boolean'
) {
throw 'window.wp.galleryBlockV2Enabled is not defined';
}
return window.wp.galleryBlockV2Enabled;
return getGalleryBlockV2Enabled();
}

return true;
Expand Down