From 350a916df98c947bfee28ef2704a4f80a5f78fb4 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Wed, 31 May 2023 09:35:11 +1000 Subject: [PATCH] Styles Screen: Ensure variations previews will render in mobile viewports (#51080) --- .../index.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index a7b8add9dd54f..9fd8752180619 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -7,6 +7,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; +import { BlockEditorProvider } from '@wordpress/block-editor'; /** * Internal dependencies @@ -19,6 +20,8 @@ import SidebarButton from '../sidebar-button'; import SidebarNavigationItem from '../sidebar-navigation-item'; import StyleBook from '../style-book'; +const noop = () => {}; + export function SidebarNavigationItemGlobalStyles( props ) { const { openGeneralSidebar } = useDispatch( editSiteStore ); const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); @@ -51,6 +54,33 @@ export function SidebarNavigationItemGlobalStyles( props ) { ); } +function SidebarNavigationScreenGlobalStylesContent() { + const { storedSettings } = useSelect( ( select ) => { + const { getSettings } = unlock( select( editSiteStore ) ); + + return { + storedSettings: getSettings( false ), + }; + }, [] ); + + // Wrap in a BlockEditorProvider to ensure that the Iframe's dependencies are + // loaded. This is necessary because the Iframe component waits until + // the block editor store's `__internalIsInitialized` is true before + // rendering the iframe. Without this, the iframe previews will not render + // in mobile viewport sizes, where the editor canvas is hidden. + return ( + +
+ +
+
+ ); +} + export default function SidebarNavigationScreenGlobalStyles() { const { openGeneralSidebar } = useDispatch( editSiteStore ); const isMobileViewport = useViewportMatch( 'medium', '<' ); @@ -86,7 +116,7 @@ export default function SidebarNavigationScreenGlobalStyles() { description={ __( 'Choose a different style combination for the theme styles.' ) } - content={ } + content={ } actions={
{ ! isMobileViewport && (