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

Not working with Parsed Text #37

Open
fawaz-ahmed opened this issue Aug 16, 2021 · 5 comments
Open

Not working with Parsed Text #37

fawaz-ahmed opened this issue Aug 16, 2021 · 5 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@fawaz-ahmed
Copy link
Owner

Referencing issue from
#36 (comment)

@fawaz-ahmed
Copy link
Owner Author

Sample code:

import React from 'react';
import {SafeAreaView, StyleSheet, View} from 'react-native';
import ReadMore from '@fawazahmed/react-native-read-more';
import ParsedText from 'react-native-parsed-text';

const App = () => {
  return (
    <SafeAreaView style={styles.safe}>
      <View style={styles.root}>
        <ReadMore numberOfLines={3}>
          <ParsedText
            parse={[
              {type: 'url', style: styles.url},
              {type: 'phone', style: styles.phone},
              {type: 'email', style: styles.email},
              {pattern: /Bob|David/, style: styles.name},
              {pattern: /42/, style: styles.magicNumber},
              {pattern: /#(\w+)/, style: styles.hashTag},
            ]}>
            Hello this is an example of the ParsedText, links like
            http://www.google.com or http://www.facebook.com are clickable and
            phone number 444-555-6666 can call too. But you can also do more
            with this package, for example Bob will change style and David too.
            foo@gmail.com And the magic number is 42! #react #react-native
          </ParsedText>
        </ReadMore>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  safe: {
    flex: 1,
  },
  root: {
    flex: 1,
    padding: 16,
  },
  textStyle: {
    fontSize: 14,
  },
  url: {
    color: 'red',
    textDecorationLine: 'underline',
  },
  email: {
    textDecorationLine: 'underline',
  },
  phone: {
    color: 'blue',
    textDecorationLine: 'underline',
  },
  name: {
    color: 'red',
  },
  magicNumber: {
    fontSize: 42,
    color: 'pink',
  },
  hashTag: {
    fontStyle: 'italic',
  },
});

export default App;

@fawaz-ahmed
Copy link
Owner Author

However, formatting goes away while collapsed:
Screen Shot 2022-02-21 at 9 05 11 PM
Screen Shot 2022-02-21 at 9 07 33 PM

@fawaz-ahmed fawaz-ahmed added enhancement New feature or request bug Something isn't working labels May 31, 2022
@Bayramito
Copy link

Bayramito commented Oct 4, 2023

This issue still exists, in my case sometimes show “read more” button even the text is 1 word long

@fawaz-ahmed
Copy link
Owner Author

fawaz-ahmed commented Oct 4, 2023

Hi @Bayramito. Yes, I can explain a bit. Incase you get a chance to fix.
See this method getTextByChildren in file
It re-constructs the paragraph in collapsed state. While doing so it clones the Text element and that's where it loses the component properties and becomes a regular text component.
If the component can be cloned with it's original state somehow, this issue can be resolved.

@carl0shd
Copy link

This issue is persistent :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants