【问题标题】:React native webview crash when playing youtube embed video播放 youtube 嵌入视频时反应原生 webview 崩溃
【发布时间】:2019-07-14 18:42:36
【问题描述】:

播放视频时,播放音乐应用会崩溃。

提示短信或电话声音也会崩溃

看起来任何系统声音都会导致崩溃

我尝试升级到最新版本的 react native 也遇到了同样的问题。

请帮帮我

import { WebView } from 'react-native';

@observer
export default class MyWebView extends Component<any>
{
    setPlay = (){
         this.setState({play: true})
    }
    render() {
        const uri = 'https://www.youtube.com/embed/71pyOB4TPRE'
        let play = this.state.play
        return (
          <View >
            {!play ? <TouchableOpacity  onPress={this.setPlay}>
                <Image style={{ width: 40, height: 40 }} source={playerIcon} />
            </TouchableOpacity> : null}

            { play? 
            <View style={{width: 450, height:300}} >
                <WebView
                    source={{ uri: uri }}
                />
            </View> :null}
          </View>
        )
    }
}

如果直接显示webview,它不会崩溃

    render() {
        const uri = 'https://www.youtube.com/embed/71pyOB4TPRE'
        let play = this.state.play
        return (
          <View >
            <View style={{width: 450, height:300}} >
                <WebView
                    source={{ uri: uri }}
                />
            </View>
          </View>
        )
    }
}

仅限安卓

【问题讨论】:

  • 我添加了代码。代码非常简单。我使用的是 0.58.5 版
  • 这是什么移动设备?
  • 我找到了错误的原因,但仍然不知道为什么
  • 世博还是被驱逐?
  • 弹出@diogenesgg

标签: react-native webview


【解决方案1】:

最后,我找到了一个非常愚蠢的解决方案。 在输入文件 index.js 中添加此代码

&lt;View style={{ height:0 }}&gt;&lt;WebView source={{ html: `` }} /&gt;&lt;/View&gt;

这样

import TabNavigator from './router'
const AppContainer = createAppContainer(TabNavigator)

export default class App extends React.Component {
    render() {
        if( Platform.OS === 'ios' ){
            return <AppContainer />
        }

        return <React.Fragment>
            <View style={{ height:0 }}><WebView source={{ html: `` }} /></View>
            <AppContainer />
        </React.Fragment>
    }
}

我没有找到具体原因 但这对我有用

很奇怪,只有我有这个问题吗?

【讨论】:

    猜你喜欢
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多