1
1
import React , { useEffect , useRef , useState } from 'react' ;
2
2
import { LiveProvider , LiveEditor , LiveError } from 'react-live' ;
3
3
import { themes } from 'prism-react-renderer' ;
4
+ // import {Button} from 'react-native-ui-lib/core';
4
5
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
5
6
import BrowserOnly from '@docusaurus/BrowserOnly' ;
6
7
import CodeBlock from '@theme/CodeBlock' ;
7
- import { Button } from 'react-native-ui-lib/core' ;
8
8
import ReactLiveScope from '../theme/ReactLiveScope' ;
9
9
import { isComponentSupported } from '../utils/componentUtils' ;
10
10
import useFormattedCode from '../hooks/useFormattedCode' ;
@@ -16,8 +16,14 @@ export default function UILivePreview({code: initialCode, componentName = undefi
16
16
const [ iframeLoaded , setIframeLoaded ] = useState ( false ) ;
17
17
const { siteConfig} = useDocusaurusContext ( ) ;
18
18
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 ] ) ;
21
27
22
28
useEffect ( ( ) => {
23
29
if ( iframeLoaded ) {
@@ -30,9 +36,9 @@ export default function UILivePreview({code: initialCode, componentName = undefi
30
36
iframeRef . current ?. contentWindow . postMessage ( message , '*' ) ;
31
37
} ;
32
38
33
- const handleFormat = ( ) => {
34
- setCode ( formattedCode ) ;
35
- } ;
39
+ // const handleFormat = () => {
40
+ // setCode(formattedCode);
41
+ // };
36
42
37
43
if ( ! liveScopeSupport && ! isComponentSupported ( componentName ) ) {
38
44
return < CodeBlock language = "jsx" > { code } </ CodeBlock > ;
@@ -47,28 +53,30 @@ export default function UILivePreview({code: initialCode, componentName = undefi
47
53
< LiveProvider code = { code } scope = { ReactLiveScope } theme = { themes . oceanicNext } >
48
54
< div className = { styles . container } >
49
55
< div className = { styles . codeContainer } >
50
- < div className = { styles . codeHeader } >
56
+ { /* <div className={styles.codeHeader}>
51
57
<Button
52
58
label="Prettify"
53
59
size={Button.sizes.small}
54
60
onPress={handleFormat}
55
61
backgroundColor="#2d2d2d"
56
62
borderRadius={4}
57
63
/>
58
- </ div >
64
+ </div> */ }
59
65
< LiveEditor onChange = { setCode } className = { styles . liveEditor } />
60
66
< div className = { styles . errorContainer } >
61
67
< LiveError />
62
68
</ div >
63
69
</ 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 >
72
80
</ div >
73
81
</ div >
74
82
</ LiveProvider >
0 commit comments