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

JSON value 'inherit' of type NSString cannot be converted to NSNumber #66

Closed
hshaukatali opened this issue Dec 12, 2017 · 3 comments
Closed

Comments

@hshaukatali
Copy link

import React, {Component} from 'react';
import {View} from 'react-native';
import HTML from 'react-native-render-html';

const htmlContent = `<h3 style="margin: 0px 0px 1.25rem; padding: 0px; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; font-size: 1.25rem; line-height: 1.3; font-family: 'Open Sans', Helvetica, Arial, sans-serif; vertical-align: baseline; text-align: center;"><strong style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline;">TEAM</strong><br />T- Together<br />E- Everyone<br />A- Achieves<br />M- More</h3>`

export default class MessageView extends Component {
    render(){
       return(
          <View>
                <HTML html={htmlContent}/>
            </View>
       )
    }
}

Following error was shown:

image

@Exilz
Copy link
Contributor

Exilz commented Dec 13, 2017

Hi,
all your CSS properties like line-height: inherit are transformed like so : { lineHeight: 'inherit' }.
Obviously, <Text> expects a number for this prop, hence the bug.

I don't have a solution that would prevent this crash for all cases yet. If you have control over the HTML you're displaying, just remove those inherit in your CSS.

If you don't, you can various props such as ignoredStyles, alterNode, alterChildren to make sure that won't happen again.

@techrah
Copy link

techrah commented Aug 14, 2018

I'm getting a similar error and wondering why the various renderers are used. That is, if you're using a WebView why do you need to render some content with Text?

I have some fairly complicated HTML that was created by Word and it's going to be a challenge trying to figure out what to fix or ignore. This HTML may also be updated in the future; I have no control over that process.

@nadav2051
Copy link

Not sure why this issue has been closed - there is an issue on iOS where it crashes while trying to render html pasted from a Word editor or similar other editor, I get the same issue.

font-variant: normal on a div produces that error:
Error setting property 'fontVariant' of RCTText with tag #1483: JSON value 'normal' of type NSString cannot be converted to NSArray

letter-spacing: normal on a div produces that error:
Error setting property 'letterSpacing' of RCTText with tag #1483: JSON value 'normal' of type NSString cannot be converted to NSNumber

This only applies to iOS, I don't get the same experience in Android.

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