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

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

解决方法1:

增加useWebKit={true}

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

style={{height: 100}}

autoHeight={true}

isShowSelectButton={false}

mixedContentMode='always'

originWhitelist={['*']}

source={{html: ''+home.configData.sy_recharge_show+'',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);

}

}

}

你可能感兴趣的:(React Native react-native-webview-plugin插件ios端无法自适应高度)