From 68a94dd2c13541ab5c11b77430c98f66fc35f9d5 Mon Sep 17 00:00:00 2001 From: Sadaqat Ali Date: Fri, 21 Jan 2022 16:09:30 +0500 Subject: [PATCH] added custom iframe renderer --- .../postHtmlRenderer/postHtmlRenderer.tsx | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/components/postHtmlRenderer/postHtmlRenderer.tsx b/src/components/postHtmlRenderer/postHtmlRenderer.tsx index b51853058..ef8ee54b2 100644 --- a/src/components/postHtmlRenderer/postHtmlRenderer.tsx +++ b/src/components/postHtmlRenderer/postHtmlRenderer.tsx @@ -4,7 +4,7 @@ import styles from "./postHtmlRendererStyles"; import { LinkData, parseLinkData } from "./linkDataParser"; import VideoThumb from "./videoThumb"; import { AutoHeightImage } from "../autoHeightImage/autoHeightImage"; -import IframeRenderer, { iframeModel } from '@native-html/iframe-plugin'; +import { useHtmlIframeProps,iframeModel } from '@native-html/iframe-plugin'; import WebView from "react-native-webview"; interface PostHtmlRendererProps { @@ -38,15 +38,6 @@ export const PostHtmlRenderer = memo(({ //new renderer functions body = body.replace(/
/g, '
').replace(/<\/center>/g,'
'); -// body = `

-//

-//

-//
-//

Demo Text

-//
-// -//

` - console.log("Comment body:", body); const _handleOnLinkPress = (data:LinkData) => { @@ -266,6 +257,47 @@ export const PostHtmlRenderer = memo(({ ) } + // iframe renderer for rendering iframes in body + const _iframeRenderer = function IframeRenderer(props) { + const iframeProps = useHtmlIframeProps(props); + // console.log('iframeProps : ', iframeProps); + const checkSrcRegex = /(.*?)\.(mp4|webm|ogg)$/gi; + const isVideoType = iframeProps.source.uri.match(checkSrcRegex); + + // check if source contain video source then wrap it with video tag + // else pass the source directly to webview + const src = isVideoType + ? { + html: ` + + `, + } + : { + uri: iframeProps.source.uri, + }; + return ( + { + console.log('load end'); + }} + onLoadStart={() => { + console.log('load start'); + }} + source={src} + style={{ width: contentWidth, height: (contentWidth * 9) / 16 }} + startInLoadingState={true} + onShouldStartLoadWithRequest={() => true} + mediaPlaybackRequiresUserAction={true} + allowsInlineMediaPlayback={true} + /> + ); + }; return ( true , - mediaPlaybackRequiresUserAction: true, - allowsFullscreenVideo: false, /* Any prop you want to pass to iframe WebViews */ } }