react-native - 在卡片中显示 webview( react native )

标签 react-native webview expo

当我使用 CRNA 创建 React Native 应用程序时,我正在使用 expo 作为模拟器。我想在 Card 元素内的 WebView 上显示 YouTube 视频,但它无法按照我的预期进行。

这是我的代码:

import React, { Component } from 'react';
import { WebView } from 'react-native';
import { Card, CardItem } from 'native-base';

export default class MyWeb extends Component {
  render() {
    return (
      <Card>
      <CardItem>
        <WebView
          source={{uri: 'https://www.youtube.com/embed/OCMs-YhSp2o'}}
          style={{marginTop: 20}}
      /></CardItem>
      </Card>
    );
  }
}

我不知道这是否是因为卡的原因,因为当我删除卡并只显示 WebView 时,它起作用了。但由于我想将视频与其他项目(文本、图片等)一起放置,我需要使用 Card 来显示它。

请帮助我......

提前谢谢您。

最佳答案

当我定义了 CardItem 的高度时,代码现在可以完美运行。感谢尼玛的评论!

import React, { Component } from 'react';
import { WebView } from 'react-native';
import { Card, CardItem } from 'native-base';

export default class MyWeb extends Component {
  render() {
    return (
      <Card>
      <CardItem style={{height:200}}>
        <WebView
          source={{uri: 'https://www.youtube.com/embed/OCMs-YhSp2o'}}
          style={{marginTop: 20}}
      /></CardItem>
      </Card>
    );
  }
}

关于react-native - 在卡片中显示 webview( react native ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52601831/

相关文章:

reactjs - 在 react native 中单击一次后禁用 TouchableOpacity 按钮?

javascript - 如何将 mapStateToProps/redux 添加到 react-navigation TabNavigator?

Android webview地理定位数据库打开失败

react-native - AdMobBanner 的 `testDeviceID` Prop 已弃用。测试设备 ID 现在是全局设置的。改用 AdMob.setTestDeviceIDAsync

android - Expo 应用程序可以在 ios 和模拟器上运行,但不能在 Android 设备上运行

javascript - react-native fetch 返回奇怪的响应

android - 键盘打开时 React Native ScrollView 不滚动

java - 使用 Webview.findAll()

用于 Facebook 点赞按钮的 Android WebView

android - 为什么 StatusBar.translucent 在 expo 应用程序中不起作用