import React from 'react';
import {
CustomBlockRenderer,
RenderHTMLProps,
TChildrenRenderer
} from 'react-native-render-html';
import { View, Text } from 'react-native';
import { UIRenderHtmlCardProps } from '../../toolkit/toolkit-types';
function AdComponent() {
return (
😈🤑😈🤑😈🤑
);
}
const adComponentSrc = `function AdComponent() {
return (
😈🤑😈🤑😈🤑
);
}`;
const Renderer: CustomBlockRenderer = function ArticleWithAds({
TDefaultRenderer,
tnode,
...defaultRendererProps
}) {
const firstChildrenChunk = tnode.children.slice(0, 2);
const secondChildrenChunk = tnode.children.slice(2, 4);
const thirdChildrenChunk = tnode.children.slice(4);
return (
{firstChildrenChunk.length === 2 ? : null}
{secondChildrenChunk.length === 2 ? : null}
);
};
const articleWithAdsSource = `function ArticleWithAds({
TDefaultRenderer,
tnode,
...defaultRendererProps
}) {
const firstChildrenChunk = tnode.children.slice(0, 2);
const secondChildrenChunk = tnode.children.slice(2, 4);
const thirdChildrenChunk = tnode.children.slice(4);
return (
{firstChildrenChunk.length === 2 ? : null}
{secondChildrenChunk.length === 2 ? : null}
);
}`;
const props: RenderHTMLProps = {
source: {
html: `
Paragraph 1
Paragraph 2
Paragraph 3
Paragraph 4
Paragraph 5
`
},
tagsStyles: {
article: {
marginHorizontal: 10
}
},
renderers: {
article: Renderer
}
};
const adsRenderersConfig: UIRenderHtmlCardProps = {
title: 'Inserting Elements at Render Time',
caption:
'A custom renderer taking advantage of "TChildrenRenderer" component. When "TDefaultRenderer" is given children, those will replace the default children rendering logic, allowing great customizability.',
props,
config: {
importStatements: [
{ package: 'react-native', named: ['View', 'Text'] },
{ package: 'react-native-render-html', named: ['TChildrenRenderer'] }
],
fnSrcMap: {
AdComponent: adComponentSrc,
ArticleWithAds: articleWithAdsSource
}
}
};
export default adsRenderersConfig;