Git Product home page Git Product logo

react-native-view-more-text's Introduction

react-native-view-more-text

A super lightweight plugin to expand/collapse text in React-Native. Truncated text is ended with dotdotdot.

Working on IOS/Android

ios android

Installation

npm install --save react-native-view-more-text || yarn add react-native-view-more-text

Usage

  • numberOfLines(number)(*required): Number of lines to be displayed.

  • renderViewMore(object): Render view-more component

  • renderViewLess(object): Render view-less component

  • afterCollapse(func): Callback after collapsing

  • afterExpand(func): Callback after expanding

  • onTextLayout(func): onTextLayout function is passed to Text inside ViewMoreText (Refer to this PR#56)

  • textStyle([object, array]): Styles is passed to Text inside ViewMoreText (Refer to this PR#8)

  import ViewMoreText from 'react-native-view-more-text';

  const Screen = () => {
    const renderViewMore = (onPress) =>  <Text onPress={onPress}>View more</Text>;
    const renderViewLess = (onPress) =>  <Text onPress={onPress}>View less</Text>;

    return (
       //...  
        <ViewMoreText
          numberOfLines={3}
          renderViewMore={renderViewMore}
          renderViewLess={renderViewLess}
          textStyle={{textAlign: 'center'}}
        >
          <Text>
            Lorem ipsum dolor sit amet, in quo dolorum ponderum, nam veri molestie constituto eu. Eum enim tantas sadipscing ne, ut omnes malorum nostrum cum. Errem populo qui ne, ea ipsum antiopam definitionem eos.
          </Text>
        </ViewMoreText>
        //... 
    );
  }

Support

Discord: lelabrador/react-native-view-more-text

react-native-view-more-text's People

Contributors

amin3mej avatar harrisonjackson avatar jacobmarq avatar mateusandrade avatar nlt2390 avatar sregg 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

react-native-view-more-text's Issues

Missing License

Thanks for publishing this to NPM and github! Can you add a license to the repo?

View more is always shown

When a text is even character and you set numOfLines={3}, the view more component still shows.

This is just feature suggestion, it should hide when the text component is minimal and not up to the numOfLInes

Can't be used with different versions of react-native

Hi!
This seems like a great package but I have an issue getting started.

It keeps complaining that I have two versions of react-native in my node_modules. That is because the package requires a fixed version of react-native (and react, prop-types).

The problem:
https://github.com/nlt2390/react-native-view-more-text/blob/master/package.json#L24

"dependencies": {
    "prop-types": "15.6.0",
    "react": "16.0.0",
    "react-native": "0.50.1"
  }

Maybe we can do something like this?

"dependencies": {
    "prop-types": "*",
    "react": "*",
    "react-native": "*"
  }

Using:
React-native: 49.5
React: 16.0.0
Prop-types: ^15.5.10

Not showing More & Less Button

When Adding a string like
This card came from the 1992 Olympic Hopeful Set. This is one of many Olympic cards we are offering. These are the second best "quality" olympic cards that exist from a color perspective that I've seen. You are looking at the front and back of the card..You be the judge.
Item in mint condition...

Text inside ViewMore component flickers

Hi,
I have a description text that can vary so i have enclosed it inside the ViewMore component, but it tends to flicker when i start typing in the below textfield.
RN version: 0.46.4

ezgif com-video-to-gif
Please find the attached gif of the issue.

How to get in the top of the screen if the ViewMore text is very long

I have big ViewMore text, more than one screen if user clicks on see less text, text is collapsed for 2 lines of text, so after that user see just empty screen, to see collapsed text user need to scroll up to the top of the screen. How to make automatic scroll up to the top of the screen after text was collapsed?

[Android device] entire screen goes blank on

Hi there,
Thanks for the plugin!!

When I tested with scrollView in android device, 'View More' worked fine but when I tapped on 'View Less', entire screen went blank; I had to scroll to see the original view.

It works fine with iOS device.

any idea what might be causing this?
Thanks!!

Footer not updated after changing the children

If I update the children of this component, it doesn't recalculate shouldShowMore, so updating it from little text to a lot of text (that requires a footer) won't actually trigger calculating if the footer needs to appear. The opposite is true for if I have a lot of text then change it to a little: It will show the "View More" footer even if there is only one line of text

Style doesn't work

Hello!

I'm trying use different style into ViewMoreText (i.e textAlign) but It doesn't work. I think ViewMoreText could have a customStyle props to Text component. What do you think?

<ViewMoreText
  numberOfLines={20}
  renderViewMore={this.renderViewMore}
  renderViewLess={this.renderViewLess} >

  <Text style={styles.body}>{item.body}</Text>

</ViewMoreText>

const styles = StyleSheet.create({
  body: {
    fontSize:15,
    color:'#606060',
    lineHeight:24,
    marginRight:18,
    textAlign: 'justify'
  },
}

Text flickers during rerender.

View flickers when view is rendered multiple times.

I believe it is because of those lines in react-native-view-more-text/index.js

  componentWillReceiveProps(nextProps) {
    this.resetData();

    this.setState({
      numberOfLines: null,
      opacity: 0,
    });
  }

flicker

iOS: Works in Debug mode, not in Release mode

Hi,

When using multiple (3) ViewMores in a single component, they operate correctly for an iOS app in Debug mode. However when I change to Release mode, only the first 1 or 2 ViewMores will render. The ones that don't render still truncate the text, they just don't show the Read More button. Any ideas as to why this could be happening? The same problem occurrs when using expo/react-native-read-more library.

Thanks!

dotdotdot not showing

My text is not being truncated with "...", something I am missing? Even defining ellipsizeMode does not do anything.

Collapse issue

@nlt2390
When view more button is visible - After state is changed the ViewMoreText disappears and appears again.

When view less button is visible - After state is changed the ViewMoreText disappears.

Button to view more or less is not showing up

I've implemented it simply as:

<ViewMoreText numberOfLines={5}>
         <Text style={styles.listText}>{categoryArray.toString().split(",").join("\n")}</Text>
</ViewMoreText>

But I'm not able to see the View More/Less button, and if I get rid of the numberOfLines prop the I see the complete list.

Screen Shot 2021-06-07 at 8 52 52 AM

Here is my code :

<ViewMoreText numberOfLines={3} renderViewMore={renderViewMore} renderViewLess={renderViewLess}
textStyle={{textAlign: 'left',paddingTop:6}}>
{ children }

textStyle propType displays warning for arrays

In my example I am passing in an array as prop for textStyle:

const defaultStyle = { color: '#000000' };
const appTheme = { color: '#00ff00' };
const userTheme = { color: '#0000ff' };

// .....
<ViewMoreText
  textStyle={[defaultStyle, appTheme, userTheme]}
>
  // ...
</ViewMoreText>

screen shot 2018-01-05 at 11 18 24 am

React-Native allows to pass styles as an array to give effect similar to css (cascading).

Will create pull request if I'm able what the correct propType for textStyle should be.

The heigh delay during render of list

This issue is related with #11. When you added renderTimeout prop component has began working
more slowly. When I use it on the list(more than 1 view-more component in one row) on collapsible panel I must to set a big delay (about 300, 500, 700) that component will render correctly.
screen shot 2018-01-17 at 11 35 21

In this screen all 3 labels in the row use view-more-text component.

View more is not showing

This is my code:

<ViewMoreText
  numberOfLines={1}
  renderViewMore={this.renderViewMore}
  renderViewLess={this.renderViewLess}
>
<Text style={styles.someStyle}>
{ this.state.textExist? this.state.text:""}
</Text>
</ViewMoreText>

I have to show text on some condition. The text is rendered when the condition becomes true, but View more is not rendered.
But if i make the text content fix, like below then it is working fine.
<Text style={styles.someStyle}> Any long long very long text </Text>

All the other variables and functions are defined.

Allow Font Scaling property not working

Text inside the react-native-view-more-text is not scaling automatically.I tried to add allow font scaling its not working .When i look in code of the package seems that properties of text is not importing

Cannot set Text to selectable when using ViewMoreText

Setting the ability to long press copy from a Text component as such <Text selectable={true}>{content}</Text> does not work when inside of the <ViewMoreText> wrapper. Works as expected outside of this component

Does not work

              <ViewMoreText
                numberOfLines={5}
                renderViewMore={this.renderViewMore}
                renderViewLess={this.renderViewLess}
              >
                <Text selectable={true}>{content}</Text>
              </ViewMoreText>

Does work

              <Text selectable={true}>{content}</Text>

How to selectable text?

I cannot select text in Text component which is already selectable.

Here's my code:

<ViewMoreText numberOfLines={15} renderViewMore={this.renderViewMore} renderViewLess={this.renderViewLess} > <Text selectable={true}>{content}</Text> </ViewMoreText>

I appreciate any help. ^__^
Thank you!

How to hide "read more" when number of lines is under a certain number?

How to hide "read more" when the actual number of lines is under a certain number?

I did something like this:

<ViewMoreText
    numberOfLines={3}
    renderViewMore={this._renderViewMore}
    renderViewLess={this._renderViewLess}
    textStyle={styles.caption}
>
        <Text>{this.props.caption}</Text>
</ViewMoreText>


_renderViewMore(onPress) {
        return (
                <Text
                        style={styles.viewMore}
                        onPress={onPress}
                >
                        View more
                </Text>
        );
}

View Read more is shown when not supposed

Hi,
I have a large number of list and in that I am showing text with ability to show vewMore and viewLess, using this library works fine if I have very few number of list item but fails on anything more than couple of list items. Please have a look on attachment. I am using import { List, ListItem, Button } from 'react-native-elements'. Inside each listItem, i use react-native-view-more library.

simulator screen shot - iphone 6 - 2018-02-20 at 20

It takes several seconds to see initial lines of the text

Hi guys. Thanks for a good package.

Just one note: when I go the screen where I use your package, it takes several seconds to see initial lines of the text. At first, it does not show any text and it seems that text view height is null. Then it increases the height (still text is not visible). And only after this text is going to be visible.

Can you please help to understand what is the problem here

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.