nov*_*ung 4 android-webview react-native react-native-android
我正在使用React Native WebView来显示文件中的html内容.我使用iOS模拟器测试过,它工作正常.但不知何故,当我测试它在Android模拟器,阿拉伯语的文字没有显示,而不是奇怪的字符,如正确,: ,,ä 正在出现.öü
这是我的代码:
render() {
const { content } = this.state
return (
<View style={style.container}>
...
<WebView
source={{ html: content }}
onMessage={(event) => this.playAudio.call(this, event.nativeEvent.data)}
/>
</View>
)
}
componentDidMount() {
const { state } = this.props.navigation
RNFS.readFileAssets(`content/${state.params.item.id}`, 'utf8')
.then((content) => {
console.log('content', content)
this.setState({ ...this.state, content })
})
.catch((err) => {
console.log('error', err.message, err.code)
})
}
Run Code Online (Sandbox Code Playgroud)
我的package.json:
{
"name": "doadzikirandroid",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"moment": "^2.20.1",
"react": "16.0.0",
"react-native": "0.51.0",
"react-native-admob": "^2.0.0-beta.4",
"react-native-fs": "^2.9.6",
"react-native-gesture-handler": "^1.0.0-alpha.35",
"react-native-search-box": "^0.0.13",
"react-native-sound": "^0.10.4",
"react-native-tab-view": "^0.0.73",
"react-native-vector-icons": "^4.4.3",
"react-navigation": "^1.0.0-beta.22"
},
"devDependencies": {
"babel-jest": "22.0.4",
"babel-preset-react-native": "4.0.0",
"jest": "22.0.4",
"react-test-renderer": "16.0.0"
},
"jest": {
"preset": "react-native"
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Browser Console日志:
我该怎么做才能解决这个问题?提前致谢.
Vir*_*t18 14
这是适合我的解决方案.添加baseUrl: ''到WebView的源属性.UTF-8然后正确显示!
<WebView
source={{baseUrl: '', html: "Your HTML content here"}}
style={}
bounces={true}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1697 次 |
| 最近记录: |