-
-
Notifications
You must be signed in to change notification settings - Fork 591
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
How to limit content number line? #243
Comments
You can do it by creating this renderer and changing the numberOfLines null attribute to your desired number
|
It applies to each EDIT. I ended up wrapping the whole thing into |
I am closing because this will be resolved by #349. |
I wouldn't consider this one as resolved. Yes this solution works when you have text-only content, but in case there are nested block elements the view is getting corrupted. The reason is that View element cannot be nested into Text element. |
@ao-tigran With the powerful new foundry API (#430) you can do something like this (Typescript): import React from 'react';
import { Text } from 'react-native';
import RenderHtml, {
TBlock,
CustomBlockRenderer,
TNodeChildrenRenderer
} from 'react-native-render-html';
import { SnippetDeclaration } from '../types';
const html = `
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<img width="1200" height="800" src="https://i.imgur.com/XP2BE7q.jpg" />
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
`;
const ParagraphRenderer: CustomBlockRenderer = function ParagraphRenderer({
TDefaultRenderer,
tnode,
type,
...props
}) {
return (
<TDefaultRenderer tnode={tnode} {...props}>
<TNodeChildrenRenderer
tnode={tnode}
parentMarkers={props.markers}
renderChild={({ childTnode, childElement }) =>
type === "block" ? (
childElement
) : (
<Text numberOfLines={3}>{childElement}</Text>
)
}
/>
</TDefaultRenderer>
);
};
const renderHtmlProps = {
source: { html },
renderers: {
p: ParagraphRenderer
}
};
// ...
<RenderHtml {...renderHtmlProps} /> Note that the |
@castalonirenz If will only work for direct children of PS: Your problem is yet a bit ill-defined, but I am available for counseling if you or your company is willing to hire me. |
Closing now since the stable beta which fixes this issue has just been released. |
Hi @jsamr would you be able to give an example of line limiting? Is there a specific property? Not sure I understood |
Hi @jsamr, thank you! Will you be able to give an example? Not quite sure based on the example |
I need the same thing, trying to figure it out rn |
Hello,
How to limit html content number line like react component Text props numberofLine?
Thank you!
The text was updated successfully, but these errors were encountered: