Reputation: 93
I'm using expo for the simulator as I created my react native app with CRNA. And I want to show a youtube video on WebView inside a Card elements but it couldn't do as I supposed.
Here is my code:
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>
);
}
}
I don't know if it is because of the Card or not because when I remove the Card and only showing the WebView, it worked. But since I want to put the video along with another items (text, picture, etc) I need to use Card to display it.
Please help me....
Thank you in advance.
Upvotes: 2
Views: 1433
Reputation: 1
WebView has been removed from React Native. It can now be installed and imported from 'react-native-webview' instead of 'react-native'
import React, { Component } from 'react';
import { WebView } from 'react-native-webview';
import { Card, CardItem } from 'native-base';
export default class App extends Component {
render() {
return (
<Card>
<CardItem style={{height:200}}>
<WebView
source={{uri: 'https://www.youtube.com/embed/OCMs-YhSp2o'}}
style={{marginTop: 20}}
/></CardItem>
</Card>
);
}
}
And if you are using Expo you will face this problem
Some of your project's dependencies are not compatible with currently installed expo package version:
Upvotes: 0
Reputation: 93
As I defined the height of the CardItem, the code is working perfectly now. Thanks to Nima for the comment!
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>
);
}
}
Upvotes: 2