加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – React Native WebView Android:阿拉伯语文本显

发布时间:2020-12-15 20:17:19 所属栏目:百科 来源:网络整理
导读:我正在使用React Native WebView来显示文件中的html内容.我使用iOS模拟器测试过,它工作正常.但不知何故,当我在 Android模拟器上测试它时,阿拉伯语文本显示不正确,而不是像?,?,ü出现的奇怪字符. 这是我的代码: render() { const { content } = this.state r
我正在使用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)
        })
}

我的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"
  }
}

输出:

enter image description here

Browser Console日志:

enter image description here

我该怎么做才能解决这个问题?提前致谢.

解决方法

这是适合我的解决方案.将baseUrl:”添加到WebView的source属性中. UTF-8然后正确显示!

<WebView
    source={{baseUrl: '',html: "Your HTML content here"}}
    style={}
    bounces={true}
/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读