-
-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
One br tag before blockquote tag is collapsed when using enableExperimentalBRCollapsing in Android #678
Comments
8 tasks
Can anyone please tell me why the custom renderer for import React from 'react';
import { Platform, Text } from 'react-native';
import type { CustomRendererProps, TBlock, TNode, TPhrasing, TText } from 'react-native-render-html';
import { View } from 'react-native';
type BrRendererProps = CustomRendererProps<TText> & {
key?: string;
};
function renderEmptyLineBreak(tnode: TNode) {
const lineHeight =
tnode.styles.nativeTextFlow.lineheight ||
tnode.styles.nativeTextFlow.fontSize! * 1.4;
return <View style={{ height: lineHeight }} />;
}
const emptyProps = {
testID: 'br'
};
function BrRenderer({ TDefaultRenderer, key, renderIndex, renderLength, tnode, sharedProps, ...defaultRendererProps }: BrRendererProps) {
const isWeb = Platform.OS === 'web';
const isFirst = renderIndex === 0;
const isLast = renderIndex === renderLength - 1;
const parentChildren = tnode.parent?.children;
const nextNode = parentChildren?.[renderIndex + 1];
const isFollowedByBr = nextNode?.tagName === "br";
const isLonelyBreak = isFirst && isLast;
const shouldCollapse = sharedProps.enableExperimentalBRCollapsing && (isFirst ? isLast && !isWeb : isLast);
console.log("isFirst ---------------> ", isFirst)
console.log("isLast ---------------> ", isLast)
console.log("isLonelyBreak ---------------> ", isLonelyBreak)
console.log("shouldCollapse -------------> ", shouldCollapse)
console.log("RenderLength ------------------> ", renderLength)
console.log("RenderIndex ------------------> ", renderIndex)
console.log("Parent of node ---------------> ", tnode.parent?.tagName)
// Remove single <br> (when not followed by another <br>)
// if (!isFollowedByBr) {
// return null;
// }
return isLonelyBreak && shouldCollapse
? renderEmptyLineBreak(tnode)
: (
<View style={{ height: shouldCollapse ? 0 : tnode.styles.nativeTextFlow.lineHeight || 14 }} />
);
}
BrRenderer.displayName = 'BrRenderer'; However, it do work when I set the contentModel to block: br: defaultHTMLElementModels.br.extend({
contentModel: HTMLContentModel.block,
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am working on a RN project where I am rendering HTML
Hello<br><br><blockquote>World</blockquote>
like below:But, one
<br>
tag is collapsed. I can say this,Hello<br><blockquote>World</blockquote>
andHello<blockquote>World</blockquote>
have the same output. I don't think that the<br>
tag should collapse when we have another element after the tag.I can't fill the bug issue template as I don't know if this is a bug. Is there any workaround to solve this issue? I am just learning RN and don't know how to use custom renderers. Please help me :)
The text was updated successfully, but these errors were encountered: