introduced videoThumb to handle img and non img based video preview

This commit is contained in:
noumantahir 2021-09-16 23:39:46 +05:00
parent 7fe8a28a6e
commit c65f1a42ec
3 changed files with 55 additions and 21 deletions

View File

@ -1,10 +1,8 @@
import React, { memo } from "react"; import React, { memo } from "react";
import { View, ImageBackground } from "react-native";
import EStyleSheet from "react-native-extended-stylesheet";
import RenderHTML, { CustomRendererProps, Element, TNode } from "react-native-render-html"; import RenderHTML, { CustomRendererProps, Element, TNode } from "react-native-render-html";
import styles from "./postHtmlRendererStyles"; import styles from "./postHtmlRendererStyles";
import { LinkData, parseLinkData } from "./linkDataParser"; import { LinkData, parseLinkData } from "./linkDataParser";
import { IconButton } from ".."; import VideoThumb from "./videoThumb";
interface PostHtmlRendererProps { interface PostHtmlRendererProps {
@ -36,6 +34,8 @@ export const PostHtmlRenderer = memo(({
//new renderer functions //new renderer functions
body = body.replace('<center>', '<div class="text-center">').replace('</center>','</div>'); body = body.replace('<center>', '<div class="text-center">').replace('</center>','</div>');
console.log("Comment body:", body);
const _handleOnLinkPress = (data:LinkData) => { const _handleOnLinkPress = (data:LinkData) => {
if(!data){ if(!data){
@ -106,6 +106,7 @@ export const PostHtmlRenderer = memo(({
} }
}; };
const _anchorRenderer = ({ const _anchorRenderer = ({
InternalRenderer, InternalRenderer,
tnode, tnode,
@ -116,9 +117,20 @@ export const PostHtmlRenderer = memo(({
console.log("Link Pressed:", tnode) console.log("Link Pressed:", tnode)
const data = parseLinkData(tnode); const data = parseLinkData(tnode);
_handleOnLinkPress(data); _handleOnLinkPress(data);
}; };
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} />
)
}
}
return ( return (
<InternalRenderer <InternalRenderer
tnode={tnode} tnode={tnode}
@ -135,8 +147,8 @@ export const PostHtmlRenderer = memo(({
...props ...props
}:CustomRendererProps<TNode>) => { }:CustomRendererProps<TNode>) => {
const imgUrl = tnode.attributes.src;
const _onPress = () => { const _onPress = () => {
const imgUrl = tnode.attributes.src;
console.log("Image Pressed:", imgUrl) console.log("Image Pressed:", imgUrl)
setSelectedImage(imgUrl); setSelectedImage(imgUrl);
}; };
@ -145,23 +157,9 @@ export const PostHtmlRenderer = memo(({
const isAnchored = !(tnode.parent?.classes?.indexOf('markdown-external-link') >= 0) const isAnchored = !(tnode.parent?.classes?.indexOf('markdown-external-link') >= 0)
if(isVideoThumb){ if(isVideoThumb){
return ( return <VideoThumb contentWidth={contentWidth} uri={imgUrl}/>;
<View pointerEvents={'none'}>
<ImageBackground
source={{uri:tnode.attributes.src}}
style={{...styles.videoThumb, height:contentWidth * 9/16 }}
resizeMode={'cover'}>
<IconButton
style={styles.playButton}
size={44}
name='play-arrow'
color={EStyleSheet.value('$white')}
iconType='MaterialIcons'
/>
</ImageBackground>
</View>
)
} }
else { else {
return ( return (
<InternalRenderer <InternalRenderer

View File

@ -88,6 +88,7 @@ export default EStyleSheet.create({
width:'100%', width:'100%',
alignItems:'center', alignItems:'center',
justifyContent:'center', justifyContent:'center',
backgroundColor:'$darkIconColor'
}, },
playButton:{ playButton:{
alignItems:'center', alignItems:'center',

View File

@ -0,0 +1,35 @@
import React from 'react'
import { View, Text, ImageBackground } from 'react-native'
import EStyleSheet from 'react-native-extended-stylesheet';
import { TouchableHighlight, TouchableOpacity } from 'react-native-gesture-handler';
import { IconButton } from '..';
import styles from "./postHtmlRendererStyles";
interface Props {
contentWidth:number,
uri?:string;
onPress?:()=>void;
}
const VideoThumb = ({contentWidth, uri, onPress}: Props) => {
return (
<TouchableHighlight onPress={onPress} disabled={!onPress}>
<View pointerEvents={'none'}>
<ImageBackground
source={{uri}}
style={{...styles.videoThumb, height:contentWidth * 9/16 }}
resizeMode={'cover'}>
<IconButton
style={styles.playButton}
size={44}
name='play-arrow'
color={EStyleSheet.value('$white')}
iconType='MaterialIcons'
/>
</ImageBackground>
</View>
</TouchableHighlight>
)
}
export default VideoThumb