cccicl
cccicl
发布于 1个月前

React Native react-native-webview-plugin插件ios端无法自适应高度

问题:react-native-webview-plugin插件ios端无法自适应高度(Android上没试)

解决方法1:

增加useWebKit={true}

<WebView

webviewRef={(ref) => { this.webviewInject = ref; }}

style={{height: 100}}

autoHeight={true}

isShowSelectButton={false}

mixedContentMode='always'

originWhitelist={['*']}

source={{html: '<body>'+home.configData.sy_recharge_show+'</body>',baseUrl:''}}

useWebKit={true}

/>

解决方法2:

修改webview文件的_onMessage方法(原因是window.postMessage过来的值,在ios端接收是乱码)

/** * html发送过来的交互消息 */

_onMessage = (event) => {

try {

//源代码

// const action = JSON.parse(decodeURIComponent(decodeURIComponent(event.nativeEvent.data)));

const action = '';

if(Platform.OS === 'android'){

action = JSON.parse(event.nativeEvent.data);

}else{

action = JSON.parse(decodeURIComponent(decodeURIComponent(event.nativeEvent.data)));

}

if (action.type === 'setHeight' && action.height > 0) {

this.setState({contentHeight: action.height}); return;

}

if (action.type !== 'setHeight' && this.props.onMessage) {

this.props.onMessage(event);

} }

catch (error) {

if (this.props.onMessage) {

this.props.onMessage(event);

}

}

}

©2020 edoou.com   京ICP备16001874号-3