Skip to content

Commit

Permalink
[RNMobile] Gallery block: Re-introduce v1 (#41533)
Browse files Browse the repository at this point in the history
* Fix isGalleryV2Enabled calculation for the native version

* Update comment in isGalleryV2Enabled function

Co-authored-by: David Calhoun <[email protected]>

Co-authored-by: David Calhoun <[email protected]>
  • Loading branch information
fluiddot and dcalhoun authored Jun 14, 2022
1 parent 3c619fd commit 70e0cdc
Showing 1 changed file with 22 additions and 9 deletions.
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

0 comments on commit 70e0cdc

Please sign in to comment.