Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static html or react support #61

Closed
qalqi opened this issue Jul 22, 2024 · 4 comments
Closed

Static html or react support #61

qalqi opened this issue Jul 22, 2024 · 4 comments
Labels
question Further information is requested

Comments

@qalqi
Copy link

qalqi commented Jul 22, 2024

All the shared examples require us to host the website.
Is it possible to use webview-bridge using static html or react thats packed along with react native app?

@qalqi qalqi changed the title Static html example Static html or react support Jul 22, 2024
@gronxb
Copy link
Owner

gronxb commented Jul 22, 2024

what do you mean by using it in static HTML? Do you mean a case like this?

<WebView 
    source={{ html: `
        <script>
            const bridge = linkBridge();
            bridge.openInAppBrowser("https://www.google.com/");
         </script>
         <h1>This is a static HTML source!</h1>
`}}
/>

And what do you mean by using it in React? The webview-bridge is currently usable in React. Are you referring to using React via CDN a here

<WebView 
    source={{ html: `
      
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Standalone React Example</title>
    <!-- Include React and ReactDOM from a CDN -->
    <script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
    <div id="root"></div>

    <script type="text/babel">
        // Your React code here
        function App() {
            return (
                <div>
                    <h1>Hello, React!</h1>
                    <p>This is a standalone React example.</p>
                </div>
            );
        }

        ReactDOM.createRoot(document.getElementById('root')).render(<App />);
    </script>
</body>
</html>
`}}
/>

Do you want to use webview-bridge for both static HTML and react without npm support ?

@qalqi
Copy link
Author

qalqi commented Jul 23, 2024

yes! thanks for shared example for react! But, Can this react code be extended with webpack, html-webpack-plugin, transpiled locally, inserted as html automatically while also generating the required types as suggested? https://javascript.plainenglish.io/how-to-integrate-react-native-web-existing-react-native-apps-8e4964ad2f0b

In my case, I have p5js, p5js audio, react and need webview two way bridge to react native

@gronxb
Copy link
Owner

gronxb commented Jul 24, 2024

This example was recorded in a non-deployed web environment.

Simulator.Screen.Recording.-.iPhone.15.-.2024-07-24.at.23.05.21.mp4

Please check the link below:
Example
Web Code (web/index.ts)
React Native Code (App.tsx)
Webpack Config

In this React Native project, I created a simple web page and bundled it using webpack.

Bundling was done with HtmlInlineScriptPlugin, which inserts all code into the HTML.

dist/index.html:
image

In this project, running

> pnpm webpack

will generate dist/index.html from the code in web/src/index.ts.

The WebView can be used as follows:

<WebView
  // 1. pnpm webpack (output: dist/index.html)
  source={require("./dist/index.html")}
  style={{ height: "100%", flex: 1, width: "100%" }}
/>

Although I did not use react-native-web and react as you provided, the structure I used is sufficiently expandable with React.
Bundling React with webpack seems to be outside my scope.

Let me know if you need assistance!

@gronxb
Copy link
Owner

gronxb commented Jul 29, 2024

I'll mark this issue as resolved and close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants