Adding support to youtube videos.

This commit is contained in:
Adolfo Reyna
2022-12-25 21:46:54 -05:00
parent 6f3b8f81a9
commit ee231ae3af
3 changed files with 40 additions and 13 deletions
+17 -3
View File
@@ -8,13 +8,20 @@ import { WebView } from 'react-native-webview';
const videoIdF = (content) => {
let vimeoTag = content.match(/@vimeo:[0-9]+/);
let youtubeTag = content.match(/@youtube:[0-z]+/);
if (!vimeoTag && !youtubeTag) return [];
let tag = youtubeTag || vimeoTag || hslTag;
if (!vimeoTag) return [];
let tag = vimeoTag;
tag = tag[0].substring(1);
return tag.split(':');
};
const youtubeIdF = (content) => {
let youtubeTag = content.match(/@youtube:[0-z]+/);
if (!youtubeTag) return '';
let tag = youtubeTag;
tag = tag[0].substring(1);
return tag.split(':')[1];
};
const hlsIdF = (content) => {
let hslTag = content.match(/@hls:.+\w/);
if (!hslTag) return '';
@@ -51,6 +58,7 @@ let Media = (props) => {
const videosId = videoIdF(props.content);
const hlsUrl = hlsIdF(props.content);
const iframeSrc = iframeTagF(props.content) || [];
const youtubeId = youtubeIdF(props.content);
const [videosFiles, setVideosFiles] = useState([]);
const [poster, setPoster] = useState('');
const [loaded, setLoaded] = useState(false);
@@ -97,6 +105,11 @@ let Media = (props) => {
style={styles.iframe}
source={{ uri: iframeSrc[1] }}
/> : <></>;
const youtubeEmb = youtubeId.length ?
<WebView
style={styles.iframe}
source={{ uri: "https://www.youtube.com/embed/" + youtubeId + "?fs=0" }}
/> : <></>;
const renderImages = (({ item }) => {
return (<Image source={{ uri: item[1] }} style={styles.flatlistImages} />);
});
@@ -125,6 +138,7 @@ let Media = (props) => {
{video}
{video2}
{iframe}
{youtubeEmb}
</View>
);
}
+1 -1
View File
@@ -59,7 +59,7 @@ let Post = (props) => {
return (
<Card style={styles.card}>
<Card.Content>
<Hyperlink linkDefault={ true } linkStyle={{}}>
<Hyperlink linkDefault={ true } linkStyle={ { color: '#2980b9'} }>
{!post.nonOrganicType ?
<View>
<Text style={styles.userName}>