Skip to content

Commit 4ae461c

Browse files
fluiddotdcalhoun
authored andcommitted
[RNMobile] Gallery block: Re-introduce v1 (#41533)
* 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]>
1 parent 32ab484 commit 4ae461c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/block-library/src/gallery/shared.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
*/
44
import { get, pick } from 'lodash';
55

6+
/**
7+
* WordPress dependencies
8+
*/
9+
import { Platform } from '@wordpress/element';
10+
611
export function defaultColumnsNumber( imageCount ) {
712
return imageCount ? Math.min( 3, imageCount ) : 3;
813
}
@@ -22,25 +27,33 @@ export const pickRelevantMediaFiles = ( image, sizeSlug = 'large' ) => {
2227
return imageProps;
2328
};
2429

30+
function getGalleryBlockV2Enabled() {
31+
// We want to fail early here, at least during beta testing phase, to ensure
32+
// there aren't instances where undefined values cause false negatives.
33+
if ( ! window.wp || typeof window.wp.galleryBlockV2Enabled !== 'boolean' ) {
34+
throw 'window.wp.galleryBlockV2Enabled is not defined';
35+
}
36+
return window.wp.galleryBlockV2Enabled;
37+
}
38+
2539
/**
2640
* The new gallery block format is not compatible with the use_BalanceTags option
2741
* in WP versions <= 5.8 https://core.trac.wordpress.org/ticket/54130. The
2842
* window.wp.galleryBlockV2Enabled flag is set in lib/compat.php. This method
2943
* can be removed when minimum supported WP version >=5.9.
3044
*/
3145
export function isGalleryV2Enabled() {
46+
// The logic for the native version is located in a different if statement
47+
// due to a lint rule that prohibits a single conditional combining
48+
// `process.env.IS_GUTENBERG_PLUGIN` with a native platform check.
49+
if ( Platform.isNative ) {
50+
return getGalleryBlockV2Enabled();
51+
}
52+
3253
// Only run the Gallery version compat check if the plugin is running, otherwise
3354
// assume we are in 5.9 core and enable by default.
3455
if ( process.env.IS_GUTENBERG_PLUGIN ) {
35-
// We want to fail early here, at least during beta testing phase, to ensure
36-
// there aren't instances where undefined values cause false negatives.
37-
if (
38-
! window.wp ||
39-
typeof window.wp.galleryBlockV2Enabled !== 'boolean'
40-
) {
41-
throw 'window.wp.galleryBlockV2Enabled is not defined';
42-
}
43-
return window.wp.galleryBlockV2Enabled;
56+
return getGalleryBlockV2Enabled();
4457
}
4558

4659
return true;

0 commit comments

Comments
 (0)