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
- 下一篇: 函数调用的预编译