@@ -2,6 +2,7 @@ import React, {useEffect, useRef, useState, useMemo} from 'react';
2
2
import { StyleSheet } from 'react-native' ;
3
3
import { LiveProvider , LiveEditor } from 'react-live' ;
4
4
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
5
+ import BrowserOnly from '@docusaurus/BrowserOnly' ;
5
6
import { View , Colors } from 'react-native-ui-lib/core' ;
6
7
import ReactLiveScope from '../theme/ReactLiveScope' ;
7
8
@@ -12,7 +13,6 @@ export default function UILivePreview({code: codeProp}) {
12
13
const [ iframeLoaded , setIframeLoaded ] = useState ( false ) ;
13
14
const { siteConfig} = useDocusaurusContext ( ) ;
14
15
const iframeRef = useRef ( null ) ;
15
- const iframeSource = `${ window . location . origin } ${ siteConfig ?. baseUrl } livePreview` ;
16
16
17
17
useEffect ( ( ) => {
18
18
if ( iframeLoaded ) {
@@ -30,27 +30,35 @@ export default function UILivePreview({code: codeProp}) {
30
30
} , [ ] ) ;
31
31
32
32
return (
33
- < View row gap-s2 style = { styles . liveCodeWrapper } >
34
- < LiveProvider code = { code } scope = { ReactLiveScope } >
35
- < View flex style = { styles . editorWrapper } >
36
- < LiveEditor
37
- className = "font-mono"
38
- onChange = { setCode }
39
- //@ts -ignore
40
- style = { liveEditorStyle }
41
- />
42
- </ View >
43
- < View bg-$backgroundDefault margin-s2 style = { styles . iframeWrapper } >
44
- < iframe
45
- ref = { iframeRef }
46
- style = { styles . iframe }
47
- src = { iframeSource }
48
- title = "Simulator"
49
- onLoad = { ( ) => setIframeLoaded ( true ) }
50
- />
51
- </ View >
52
- </ LiveProvider >
53
- </ View >
33
+ < BrowserOnly >
34
+ { ( ) => {
35
+ const iframeSource = `${ window . location . origin } ${ siteConfig ?. baseUrl } livePreview` ;
36
+
37
+ return (
38
+ < View row gap-s2 style = { styles . liveCodeWrapper } >
39
+ < LiveProvider code = { code } scope = { ReactLiveScope } >
40
+ < View flex style = { styles . editorWrapper } >
41
+ < LiveEditor
42
+ className = "font-mono"
43
+ onChange = { setCode }
44
+ //@ts -ignore
45
+ style = { liveEditorStyle }
46
+ />
47
+ </ View >
48
+ < View bg-$backgroundDefault margin-s2 style = { styles . iframeWrapper } >
49
+ < iframe
50
+ ref = { iframeRef }
51
+ style = { styles . iframe }
52
+ src = { iframeSource }
53
+ title = "Simulator"
54
+ onLoad = { ( ) => setIframeLoaded ( true ) }
55
+ />
56
+ </ View >
57
+ </ LiveProvider >
58
+ </ View >
59
+ ) ;
60
+ } }
61
+ </ BrowserOnly >
54
62
) ;
55
63
}
56
64
0 commit comments