@@ -30,10 +30,12 @@ import {
30
30
UserGuideLocationState ,
31
31
} from "pages/tutorials/tutorialsConstant" ;
32
32
import React , {
33
+ ReactNode ,
33
34
Suspense ,
34
35
lazy ,
35
36
useCallback ,
36
37
useContext ,
38
+ useEffect ,
37
39
useLayoutEffect ,
38
40
useMemo ,
39
41
useState ,
@@ -58,6 +60,7 @@ import EditorSkeletonView from "./editorSkeletonView";
58
60
import { getCommonSettings } from "@lowcoder-ee/redux/selectors/commonSettingSelectors" ;
59
61
import { isEqual , noop } from "lodash" ;
60
62
import { AppSettingContext , AppSettingType } from "@lowcoder-ee/comps/utils/appSettingContext" ;
63
+ import Flex from "antd/es/flex" ;
61
64
// import { BottomSkeleton } from "./bottom/BottomContent";
62
65
63
66
const Header = lazy (
@@ -251,6 +254,13 @@ export const EditorWrapper = styled.div`
251
254
flex: 1 1 0;
252
255
` ;
253
256
257
+ const DeviceWrapperInner = styled ( Flex ) `
258
+ margin: 20px 0 0;
259
+ .screen {
260
+ overflow: auto;
261
+ }
262
+ ` ;
263
+
254
264
interface EditorViewProps {
255
265
uiComp : InstanceType < typeof UIComp > ;
256
266
preloadComp : InstanceType < typeof PreloadComp > ;
@@ -298,6 +308,64 @@ const aggregationSiderItems = [
298
308
}
299
309
] ;
300
310
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
+
301
369
function EditorView ( props : EditorViewProps ) {
302
370
const { uiComp } = props ;
303
371
const params = useParams < AppPathParams > ( ) ;
@@ -416,6 +484,24 @@ function EditorView(props: EditorViewProps) {
416
484
uiComp ,
417
485
] ) ;
418
486
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
+
419
505
// we check if we are on the public cloud
420
506
const isLowCoderDomain = window . location . hostname === 'app.lowcoder.cloud' ;
421
507
const isLocalhost = window . location . hostname === 'localhost' ;
@@ -455,7 +541,7 @@ function EditorView(props: EditorViewProps) {
455
541
{ ! hideBodyHeader && < PreviewHeader /> }
456
542
< EditorContainerWithViewMode >
457
543
< ViewBody $hideBodyHeader = { hideBodyHeader } $height = { height } >
458
- { uiComp . getView ( ) }
544
+ { uiCompViewWrapper }
459
545
</ ViewBody >
460
546
< div style = { { zIndex : Layers . hooksCompContainer } } >
461
547
{ hookCompViews }
0 commit comments