fawaz-ahmed / react-native-read-more

React native library to show text in a condensed way and expand when needed. Drop in replacement for Text component and highly customizable. Can be used with expo or native cli for react native.
https://www.npmjs.com/package/@fawazahmed/react-native-read-more
MIT License
274 stars 37 forks source link

how to add icon beside see more/less text #39

Open iamhaaamed opened 3 years ago

iamhaaamed commented 3 years ago

how can I add icon beside see more/less text? I have used customTextComponent like this:

<ReadMore seeMoreStyle={styles.button} seeLessStyle={styles.button} numberOfLines={3} customTextComponent={props => ( <> <Text {...props} /> <MaterialCommunityIcon name="chevron-down" size={Spacing.large} color={Colors.blueViolet} /> </> )}> {userInfo.about_me} </ReadMore>

but it's not working properly: https://i.imgur.com/CktRJtN.png https://i.imgur.com/HFHGHrq.png

fawaz-ahmed commented 3 years ago

@iamhaamed To pass any custom text component, you pass like this customTextComponent={Text} It means it will use this component to display the underlying text. Same component is then used to render the main text itself, see more text and see less text.

You can try this, though I haven't tested myself:

<ReadMore
  seeMoreStyle={styles.button}
  seeLessStyle={styles.button}
  numberOfLines={3}
  seeMoreText={(
    <>
      {'see more'}
      <MaterialCommunityIcon name="chevron-down" size={Spacing.large} color={Colors.blueViolet} />
    </>
  )}
  >
  {userInfo.about_me}
</ReadMore>
iamhaaamed commented 3 years ago

Thank you it is working now, but it seems we have alignment issue for See more because marginTop and paddingTop is not working properly:

` <ReadMore seeMoreStyle={styles.button} seeLessStyle={styles.button} numberOfLines={3} seeMoreText={ <>

See more

</> } seeLessText={ <View style={{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', }}>

See less

<MaterialCommunityIcon name="chevron-down" size={Spacing.large} color={Colors.blueViolet} /> }> {userInfo.about_me} `

https://imgur.com/XfXUJUf