如何使用带有 Expo 的 webview 应用程序不使用手指调整网页大小
How to make not to adjust web size with finger using webview app with Expo
我在 React native 和 Expo 中使用 webview。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native';
export default function App() {
return <WebView source={{ uri: 'http://192.0.0.1:8080' }} />;
}
这是我的webview代码。
但是我想修复webview而不用手指调整大小。我该如何设置这个选项?太感谢了。
请检查下面的示例,让我知道你是否可以做到。
const INJECTEDJAVASCRIPT = `const meta = document.createElement('meta'); meta.setAttribute('content', 'width='100%', initial-scale=1.0, maximum-scale=1.0, user-scalable=0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta); `
<WebView
ref={(reff) => {
this.webView = reff;
}}
bounces={false}
automaticallyAdjustContentInsets={false}
injectedJavaScript={INJECTEDJAVASCRIPT}
startInLoadingState
javaScriptEnabled ={true}
/>
我在 React native 和 Expo 中使用 webview。
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native';
export default function App() {
return <WebView source={{ uri: 'http://192.0.0.1:8080' }} />;
}
这是我的webview代码。
但是我想修复webview而不用手指调整大小。我该如何设置这个选项?太感谢了。
请检查下面的示例,让我知道你是否可以做到。
const INJECTEDJAVASCRIPT = `const meta = document.createElement('meta'); meta.setAttribute('content', 'width='100%', initial-scale=1.0, maximum-scale=1.0, user-scalable=0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta); `
<WebView
ref={(reff) => {
this.webView = reff;
}}
bounces={false}
automaticallyAdjustContentInsets={false}
injectedJavaScript={INJECTEDJAVASCRIPT}
startInLoadingState
javaScriptEnabled ={true}
/>