11import React , { useEffect , useRef , useState } from 'react' ;
22import { LiveProvider , LiveEditor , LiveError } from 'react-live' ;
33import { themes } from 'prism-react-renderer' ;
4+ // import {Button} from 'react-native-ui-lib/core';
45import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
56import BrowserOnly from '@docusaurus/BrowserOnly' ;
67import CodeBlock from '@theme/CodeBlock' ;
7- import { Button } from 'react-native-ui-lib/core' ;
88import ReactLiveScope from '../theme/ReactLiveScope' ;
99import { isComponentSupported } from '../utils/componentUtils' ;
1010import useFormattedCode from '../hooks/useFormattedCode' ;
@@ -16,8 +16,14 @@ export default function UILivePreview({code: initialCode, componentName = undefi
1616 const [ iframeLoaded , setIframeLoaded ] = useState ( false ) ;
1717 const { siteConfig} = useDocusaurusContext ( ) ;
1818 const iframeRef = useRef ( null ) ;
19- const [ code , setCode ] = useState ( initialCode ) ;
20- const { code : formattedCode } = useFormattedCode ( code , { printWidth : 100 } ) ;
19+ const { code : formattedCode } = useFormattedCode ( initialCode , { printWidth : 100 } ) ;
20+ const [ code , setCode ] = useState ( formattedCode ) ;
21+ // const [code, setCode] = useState(initialCode);
22+ // const {code: formattedCode} = useFormattedCode(code, {printWidth: 100});
23+
24+ useEffect ( ( ) => {
25+ setCode ( formattedCode ) ;
26+ } , [ formattedCode ] ) ;
2127
2228 useEffect ( ( ) => {
2329 if ( iframeLoaded ) {
@@ -30,9 +36,9 @@ export default function UILivePreview({code: initialCode, componentName = undefi
3036 iframeRef . current ?. contentWindow . postMessage ( message , '*' ) ;
3137 } ;
3238
33- const handleFormat = ( ) => {
34- setCode ( formattedCode ) ;
35- } ;
39+ // const handleFormat = () => {
40+ // setCode(formattedCode);
41+ // };
3642
3743 if ( ! liveScopeSupport && ! isComponentSupported ( componentName ) ) {
3844 return < CodeBlock language = "jsx" > { code } </ CodeBlock > ;
@@ -47,28 +53,30 @@ export default function UILivePreview({code: initialCode, componentName = undefi
4753 < LiveProvider code = { code } scope = { ReactLiveScope } theme = { themes . oceanicNext } >
4854 < div className = { styles . container } >
4955 < div className = { styles . codeContainer } >
50- < div className = { styles . codeHeader } >
56+ { /* <div className={styles.codeHeader}>
5157 <Button
5258 label="Prettify"
5359 size={Button.sizes.small}
5460 onPress={handleFormat}
5561 backgroundColor="#2d2d2d"
5662 borderRadius={4}
5763 />
58- </ div >
64+ </div> */ }
5965 < LiveEditor onChange = { setCode } className = { styles . liveEditor } />
6066 < div className = { styles . errorContainer } >
6167 < LiveError />
6268 </ div >
6369 </ div >
64- < div className = { styles . preview } >
65- < iframe
66- ref = { iframeRef }
67- className = { styles . iframe }
68- src = { iframeSource }
69- title = "Simulator"
70- onLoad = { ( ) => setIframeLoaded ( true ) }
71- />
70+ < div className = { styles . previewContainer } >
71+ < div className = { styles . preview } >
72+ < iframe
73+ ref = { iframeRef }
74+ className = { styles . iframe }
75+ src = { iframeSource }
76+ title = "Simulator"
77+ onLoad = { ( ) => setIframeLoaded ( true ) }
78+ />
79+ </ div >
7280 </ div >
7381 </ div >
7482 </ LiveProvider >
0 commit comments