react-native-webview禁止缩放
生活随笔
收集整理的這篇文章主要介紹了
react-native-webview禁止缩放
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、需求
RN-webview禁止縮放,即固定屏幕大小,但同時要能夠監聽到其他手勢識別
二、實現
僅僅設置webview的大小自適應是不夠的,因為webview所引入的h5頁面有可能是能夠縮放的。
因此先向h5頁面注入代碼:
const INJECTEDJAVASCRIPT = `const meta = document.createElement('meta'); meta.setAttribute('content', 'initial-scale=0.5, maximum-scale=0.5, user-scalable=0'); meta.setAttribute('name', 'viewport'); document.getElementsByTagName('head')[0].appendChild(meta); `而后設置webview:
<WebViewref={ref => (this.webview = ref)}javaScriptEnabled={true}scalesPageToFit={false}injectedJavaScript={ INJECTEDJAVASCRIPT }source={{ uri: this.state.source }} />即可固定頁面。
轉載于:https://www.cnblogs.com/bbcfive/p/10989367.html
總結
以上是生活随笔為你收集整理的react-native-webview禁止缩放的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: REPAIR修复mysql报错is ma
- 下一篇: 函数调用的预编译