From b36f9296c078923d20f1222f987d4f841c171ba7 Mon Sep 17 00:00:00 2001 From: guyuli2002 <64501116+guyuli2002@users.noreply.github.com> Date: Mon, 20 Mar 2023 22:20:51 -0400 Subject: [PATCH] Create webview.md --- Topics/Tech_Stacks/webview.md | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Topics/Tech_Stacks/webview.md diff --git a/Topics/Tech_Stacks/webview.md b/Topics/Tech_Stacks/webview.md new file mode 100644 index 000000000..7fff5c5e1 --- /dev/null +++ b/Topics/Tech_Stacks/webview.md @@ -0,0 +1,68 @@ +# Open website in IOS or Android using Webview. + + +## Introduction + +As the use of mobile devices continues to grow, many websites are now being accessed through mobile apps instead of traditional web browsers. To provide a seamless user experience, developers often use a WebView component in their iOS or Android app to open a website within the app. A WebView is a user interface component that displays web content within an application. By using a WebView, developers can embed web content, such as web pages or online services, directly into their mobile app, without the need to switch between the app and a separate web browser. In this way, users can stay within the app and seamlessly interact with web content. This approach has become increasingly popular in the development of mobile apps, especially for those that need to integrate web-based content into their user interface. +## Emulator + +https://snack.expo.dev/ +This link provide an emulator for mobile, you don't have to download anything. Remember to save your changes and bookmark the webpage. On the right side, you can see iOS and Android. Click them and click tap to play, it will install the app you created in an emulator and open that app for you. + +## package.json + +Include all the package you need in package.json +```cpp +{ + "dependencies": { + "expo-constants": "~13.2.4", + "@expo/vector-icons": "^13.0.0", + "react-native-paper": "4.9.2", + "react-native-webview": "11.23.0" + } +} +``` + +## App.js + +This is where you put your code in. +```cpp +import React, { useState, useRef } from 'react'; +import { WebView } from 'react-native-webview'; +import { Button } from 'react-native'; +import { View } from 'react-native'; + +export default function App() { + const [showWebView, setShowWebView] = useState(false); + const webViewRef = useRef(null); + + const openWebView = () => { + setShowWebView(true); + }; + + const closeWebView = () => { + setShowWebView(false); + }; + + return ( + + {showWebView ? ( + <> + +