Giter Club home page Giter Club logo

react-native-see-more-inline's Introduction

npm npm

react-native-see-more-inline

Show a "read more", "see more", "read less", "see less" inline with your text in React Native

My motivation of building this was that I couldn't find any library/implementation that would place the "see more" link inline with the text. All the other implementations I found would place the link under the text. This package uses text width, and using a simple binary search it (almost) accurately calculates where it should place the "see more" link.

Installing the package

  1. Install react-native-text-size v4.0.0-rc.1
  2. yarn add react-native-see-more-inline or npm install --save react-native-see-more-inline

Note: This package will not work with expo managed projects. The dependency react-native-text-size links natively. Till we have a dependency on this package to measure the text width, this limitation will remain.

Usage

import SeeMore from 'react-native-see-more-inline';

<SeeMore numberOfLines={2}>
  {VERY_LARGE_TEXT}
</SeeMore>

<SeeMore numberOfLines={2} linkStyle={{ fontWeight: '500' }}>
  {VERY_LARGE_TEXT}
</SeeMore>

Props

Prop Default Value Required Type
numberOfLines - yes number
linkColor '#2E75F0' no string
linkPressedColor '#163772' no string
linkStyle undefined no array/object
seeMoreText 'see more' no string
seeLessText 'see less' no string
style { fontFamily: undefined, fontSize: 14, fontWeight: '300' } no array/object

Running the example

  1. cd example
  2. yarn install
  3. Terminal 1 - yarn start
  4. Terminal 2 - yarn run wml
  5. Terminal 3 - yarn run ios / yarn run android

react-native-see-more-inline's People

Contributors

cnilton avatar dependabot[bot] avatar filipemerker avatar kashishgrover avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-see-more-inline's Issues

Doesn't work with last version on React native (0.63.3)

[IOS] After installation and updating pods show this error:

RCTF Fatal Error: Unable to resolve module react-native-text-size from node_modules/react-native-see-more-inline/src/SeeMore/SeeMoreUtil.js: react-native-text-size could not be found within the project.

Version on React Native is [0.63.3]

Calculating truncation index not taking into account default React Native word break mode?

Am I correct that the calculation for truncationIndex doesn't properly account for the default word break mode for React Native's Text? namely, a word will not be cut partially for line wrap - the entire word will be moved to the next line (at least for iOS - I know you can control this behavior with Android).

This severely undercounts the width (really space/pixels) needed to render some given text:
const { width: totalTextWidth } = await reactNativeTextSize.measure({ text, fontSize: scaledFontSize, fontFamily, fontWeight, });

as a line will be filled with empty space if the last word needs to be moved to the next line.

Example of incorrect calculation(s), current v1.3.0 code and behavior I saw using v1.1.0 for a year+:

bad truncation

Expected (and using my fixes):

Screen Shot 2021-07-02 at 1 16 08 PM

I have modified SeeMoreUtils.js to instead calculate how each line would be rendered, thus taking into account word break where the word is not broken partially. I can post it here, but

  1. please let me know if I'm misunderstanding the current behavior and/or am missing some prop/config that will account for this behavior
  2. or if I should just fork, I can do that as well

Just want to help others, if possible

Basically, my code breaks up the text into lines, accounting for word break moving the last word of a line to the next line if it can't fit, so it better mimics the actual rendering when it does the truncationIndex calculation. Then, I re-assemble the text based on numberOfLines and truncate the last line appropriately to fit the seeMoreText

Malformed calls from JS: field sizes are different.

Hello,
I have followed the documentation for implementing your module however I'm unable to get it working correctly and am receiving the below.
image

This is my code for implementation:
image

Could you please advise?

Does not break properly when there is a linebreak in the text

Thanks to @kashishgrover for developing the plug-in exactly what i needed.

In a recent update, I found something different from before:
If there is a line break in the text, it works to break the text right there and display 'see more'.
Previously, there was a case where 'see more' was not displayed when there was a line break, so it seems to be an improvement. However, it seems not intended when there is a line-break in a position less than the max-number of lines, 'see more' is displayed from there.

image

Use only "Show more"

It would be great if we had option to use "See more" only depending on requirement.
Conditionally I hid the "see less" text but the gesture works on complete text which ultimately allows user to collapse text.
Hope to see additional prop asap.

Does not work with expo

Simulator Screen Shot - iPhone 8 Plus - 2020-04-21 at 12 57 55

I tried to use the example project code in my project and not able to see the "See More" and "See Less" option, am I doing something wrong?

Expo eas build failed

i use expo, for development it working fine but when eas build --platform android
i got error because peerDependencies : react-native-text-size

image

Prop Types

Could you extend typings of props with react-native TextProps because using some of text throws error on typescript such as allowFontScaling

see more text not show

I followed the example the text expands and gets smaller in click but the see more text is not rendering all I have is the elipseses

Error in install

It seems the library is not registered on NPM? I keep on getting

npm ERR! 404 '[email protected]' is not in the npm registry.

Can you have a look on this? Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.