cleaned up video link processor in anchorRenderer, using sheet based players for comments

This commit is contained in:
noumantahir 2022-01-23 01:12:11 +05:00
parent 3a99cb1034
commit aa963f5f8b
2 changed files with 33 additions and 25 deletions

View File

@ -335,6 +335,7 @@ const CommentBody = ({
<PostHtmlRenderer
contentWidth={_contentWidth}
body={body}
isComment={true}
onElementIsImage={_onElementIsImage}
setSelectedImage={_handleSetSelectedImage}
setSelectedLink={_handleSetSelectedLink}

View File

@ -6,13 +6,12 @@ import VideoThumb from './videoThumb';
import { AutoHeightImage } from '../autoHeightImage/autoHeightImage';
import { useHtmlIframeProps, iframeModel } from '@native-html/iframe-plugin';
import WebView from 'react-native-webview';
import { View } from 'react-native';
import YoutubeIframe from 'react-native-youtube-iframe';
import { VideoPlayer } from '..';
interface PostHtmlRendererProps {
contentWidth: number;
body: string;
isComment?: boolean;
onLoaded?: () => void;
setSelectedImage: (imgUrl: string) => void;
setSelectedLink: (url: string) => void;
@ -28,6 +27,7 @@ export const PostHtmlRenderer = memo(
({
contentWidth,
body,
isComment,
onLoaded,
setSelectedImage,
setSelectedLink,
@ -133,35 +133,42 @@ export const PostHtmlRenderer = memo(
_handleOnLinkPress(data);
};
if (tnode.classes?.indexOf('markdown-video-link-youtube') >= 0) {
return (
<VideoPlayer
contentWidth={contentWidth}
youtubeVideoId={parsedTnode.youtubeId}
startTime={parsedTnode.startTime}
/>
);
}
if (tnode.classes?.indexOf('markdown-video-link') >= 0) {
return (
<VideoPlayer
contentWidth={contentWidth}
videoUrl={parsedTnode.videoHref}
/>
);
}
if (tnode.classes?.indexOf('markdown-video-link') >= 0) {
const imgElement = tnode.children.find((child) => {
return child.classes.indexOf('video-thumbnail') > 0 ? true : false;
});
if (!imgElement) {
return <VideoThumb contentWidth={contentWidth} onPress={_onPress} />;
//process video link
if(tnode.classes?.indexOf('markdown-video-link') >= 0){
if(isComment){
const imgElement = tnode.children.find((child) => {
return child.classes.indexOf('video-thumbnail') > 0 ? true : false;
});
if (!imgElement) {
return <VideoThumb contentWidth={contentWidth} onPress={_onPress} />;
}
}
else if(tnode.classes?.indexOf('markdown-video-link-youtube') >= 0){
return (
<VideoPlayer
mode='youtube'
contentWidth={contentWidth}
youtubeVideoId={parsedTnode.youtubeId}
startTime={parsedTnode.startTime}
/>
);
} else {
return (
<VideoPlayer
mode='url'
contentWidth={contentWidth}
videoUrl={parsedTnode.videoHref}
/>
);
}
}
return <InternalRenderer tnode={tnode} onPress={_onPress} {...props} />;
};
//this method checks if image is a child of table column
//and calculates img width accordingly,
//returns full width if img is not part of table