Skip to content
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

Adding support for HTML text #55

Closed
PopJoestar opened this issue Feb 12, 2022 · 10 comments
Closed

Adding support for HTML text #55

PopJoestar opened this issue Feb 12, 2022 · 10 comments

Comments

@PopJoestar
Copy link

Hi, thanks for this great package, I think it will be good if we add support for HTML text, currently I'm using text-clipper in my project.

@fawaz-ahmed
Copy link
Owner

Hi @PopJoestar, thanks for those kind words.

The idea seems nice. I will think around it and explore a bit. The problem arises with edge cases, like if a user clicks on a link, since its html then what should happen ? If images are there inside then how to handle those ? Or shall we have another lib with webview for react native ?
If you have some more input on dealing with these please feel free to comment.

@PopJoestar
Copy link
Author

PopJoestar commented Feb 12, 2022

I thought we could improve the current renderer to support HTML by passing HTML renderers like https://github.com/meliorence/react-native-render-html through the customTextComponent props.

@fawaz-ahmed
Copy link
Owner

Hi @PopJoestar, with text-clipper it's possible to render html inside ReadMore component:

import { Dimensions } from 'react-native';
import clip from 'text-clipper';

const htmlString = `
<p style='text-align:left;padding:0;margin:0'>
  Hello World!
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>`;

// inside your component

<ReadMore numberOfLines={3}>
  {clip(htmlString, screenWidth, {html: true, stripTags: true})}
</ReadMore

Thanks for pointing out to this great lib: https://github.com/arendjr/text-clipper

@PopJoestar
Copy link
Author

Hi @fawaz-ahmed , thanks for the tips! I'm already using it in my project with react-native-render-HTML but I haven't tested it yet with your library

@fawaz-ahmed
Copy link
Owner

fawaz-ahmed commented Feb 22, 2022 via email

@saad9624-tribalScale
Copy link

ITs not showing complete HTML just showing 9 lines without picking html classes

@fawaz-ahmed
Copy link
Owner

@saad9624-tribalScale can you share the response you are getting from the clip method.
I need to know if my lib is showing less lines or is clip method returning lesser text.

@fawaz-ahmed fawaz-ahmed reopened this Apr 14, 2022
@saad9624-tribalScale
Copy link

Yeah, its working after adding width to undefined.

@mohil-nft
Copy link

@fawaz-ahmed I am using the library with expo, works great on mobile devices, for web I am not able to make this work.

@fawaz-ahmed
Copy link
Owner

@mohil-nft this package doesn't supports web. It depends on Text component from react-native package for applying logical updates and calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants