diff --git a/packages/react-native-web-examples/pages/app-registry/index.js b/packages/react-native-web-examples/pages/app-registry/index.js index 53d8f55743..168ea5efe9 100644 --- a/packages/react-native-web-examples/pages/app-registry/index.js +++ b/packages/react-native-web-examples/pages/app-registry/index.js @@ -1,51 +1,137 @@ -import React from 'react'; -import { AppRegistry, Text, StyleSheet } from 'react-native'; +import React, { useRef, useEffect, useState } from 'react'; +import { Pressable, Text, StyleSheet, View, render } from 'react-native'; import Example from '../../shared/example'; +function IframeWrapper({ children }) { + const iframeHost = useRef(); + const reactRoot = useRef(); + + useEffect(() => { + if (iframeHost.current) { + if (!reactRoot.current) { + const iframeElement = iframeHost.current; + const iframeAppContainer = document.createElement('div'); + iframeElement.contentWindow.document.body.appendChild( + iframeAppContainer + ); + reactRoot.current = render(children, iframeAppContainer); + } + reactRoot.current.render(children); + } + }); + + return