@@ -30,10 +30,12 @@ import {
3030 UserGuideLocationState ,
3131} from "pages/tutorials/tutorialsConstant" ;
3232import React , {
33+ ReactNode ,
3334 Suspense ,
3435 lazy ,
3536 useCallback ,
3637 useContext ,
38+ useEffect ,
3739 useLayoutEffect ,
3840 useMemo ,
3941 useState ,
@@ -58,6 +60,7 @@ import EditorSkeletonView from "./editorSkeletonView";
5860import { getCommonSettings } from "@lowcoder-ee/redux/selectors/commonSettingSelectors" ;
5961import { isEqual , noop } from "lodash" ;
6062import { AppSettingContext , AppSettingType } from "@lowcoder-ee/comps/utils/appSettingContext" ;
63+ import Flex from "antd/es/flex" ;
6164// import { BottomSkeleton } from "./bottom/BottomContent";
6265
6366const Header = lazy (
@@ -251,6 +254,13 @@ export const EditorWrapper = styled.div`
251254 flex: 1 1 0;
252255` ;
253256
257+ const DeviceWrapperInner = styled ( Flex ) `
258+ margin: 20px 0 0;
259+ .screen {
260+ overflow: auto;
261+ }
262+ ` ;
263+
254264interface EditorViewProps {
255265 uiComp : InstanceType < typeof UIComp > ;
256266 preloadComp : InstanceType < typeof PreloadComp > ;
@@ -298,6 +308,64 @@ const aggregationSiderItems = [
298308 }
299309] ;
300310
311+ const DeviceWrapper = ( {
312+ deviceType,
313+ deviceOrientation,
314+ children,
315+ } : {
316+ deviceType : string ,
317+ deviceOrientation : string ,
318+ children : ReactNode ,
319+ } ) => {
320+ const [ Wrapper , setWrapper ] = useState < React . ElementType | null > ( null ) ;
321+
322+ useEffect ( ( ) => {
323+ const loadWrapper = async ( ) => {
324+ if ( deviceType === "tablet" ) {
325+ await import ( 'html5-device-mockups/dist/device-mockups.min.css' ) ;
326+ const { IPad } = await import ( "react-device-mockups" ) ;
327+ setWrapper ( ( ) => IPad ) ;
328+ } else if ( deviceType === "mobile" ) {
329+ await import ( 'html5-device-mockups/dist/device-mockups.min.css' ) ;
330+ const { IPhone7 } = await import ( "react-device-mockups" ) ;
331+ setWrapper ( ( ) => IPhone7 ) ;
332+ } else {
333+ setWrapper ( ( ) => null ) ;
334+ }
335+ } ;
336+
337+ loadWrapper ( ) ;
338+ } , [ deviceType ] ) ;
339+
340+ const deviceWidth = useMemo ( ( ) => {
341+ if ( deviceType === 'tablet' && deviceOrientation === 'portrait' ) {
342+ return 700 ;
343+ }
344+ if ( deviceType === 'tablet' && deviceOrientation === 'landscape' ) {
345+ return 1000 ;
346+ }
347+ if ( deviceType === 'mobile' && deviceOrientation === 'portrait' ) {
348+ return 400 ;
349+ }
350+ if ( deviceType === 'mobile' && deviceOrientation === 'landscape' ) {
351+ return 800 ;
352+ }
353+ } , [ deviceType , deviceOrientation ] ) ;
354+
355+ if ( ! Wrapper ) return < > { children } </ > ;
356+
357+ return (
358+ < DeviceWrapperInner justify = "center" >
359+ < Wrapper
360+ orientation = { deviceOrientation }
361+ width = { deviceWidth }
362+ >
363+ { children }
364+ </ Wrapper >
365+ </ DeviceWrapperInner >
366+ ) ;
367+ }
368+
301369function EditorView ( props : EditorViewProps ) {
302370 const { uiComp } = props ;
303371 const params = useParams < AppPathParams > ( ) ;
@@ -416,6 +484,24 @@ function EditorView(props: EditorViewProps) {
416484 uiComp ,
417485 ] ) ;
418486
487+ const uiCompViewWrapper = useMemo ( ( ) => {
488+ if ( isViewMode ) return uiComp . getView ( ) ;
489+
490+ return (
491+ < DeviceWrapper
492+ deviceType = { editorState . deviceType }
493+ deviceOrientation = { editorState . deviceOrientation }
494+ >
495+ { uiComp . getView ( ) }
496+ </ DeviceWrapper >
497+ )
498+ } , [
499+ uiComp ,
500+ isViewMode ,
501+ editorState . deviceType ,
502+ editorState . deviceOrientation ,
503+ ] ) ;
504+
419505 // we check if we are on the public cloud
420506 const isLowCoderDomain = window . location . hostname === 'app.lowcoder.cloud' ;
421507 const isLocalhost = window . location . hostname === 'localhost' ;
@@ -455,7 +541,7 @@ function EditorView(props: EditorViewProps) {
455541 { ! hideBodyHeader && < PreviewHeader /> }
456542 < EditorContainerWithViewMode >
457543 < ViewBody $hideBodyHeader = { hideBodyHeader } $height = { height } >
458- { uiComp . getView ( ) }
544+ { uiCompViewWrapper }
459545 </ ViewBody >
460546 < div style = { { zIndex : Layers . hooksCompContainer } } >
461547 { hookCompViews }
0 commit comments