1

I have been trying to understand the feasibility of rendering a HTML with CSS styling in Android/iOS. To give some background, we have web presence where based on some user actions, the HTML is generated and rendered. The HTML contains CSS styles (reference W3), attributes, tags (div/span/a), anchor with url and mailto protocol, custom classes, so on and so forth.
The goal is to have good visual fidelity, great performance, code reuse and less maintenance.

Choices we have so far:

  1. Render the HTML in WebView: Hosting in WebView doesn't look like a great option as it would kill user experience. Plus I've heard WebView doesn't great performance (please correct me of my research is incorrect)
  2. ReactNative: Parse HTML and map it to ReactNative controls
  3. Go pure Native

It looks like Android/iOS doesn't directly support CSS. Before I write about the research I have done so far, I need help in couple of questions:

  1. Does ReactNative cover all CSS styles well? As RN components map to Android/iOS native views, how does the mapping of CSS styles to Android Style props look like?
  2. Is there a way to use CSS in Android/iOS native directly?

react-native-htmlview takes HTML as input and converts it to RN components. But it doesn't seem to support HTML tags with styles. Is there something (a 3rd party library, or a custom solution) that can be used here?

1 Answer 1

1

I suggest you use the native web view tag handler( Html.TagHandler). it can handle the custom tag so that some tag webView does not support can also use. you should override the handleTag method.

@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
    if (opening) {
        if (tag.equalsIgnoreCase("code")) {
            start(output, new Code());
        } else if (tag.equalsIgnoreCase("center")) {
            start(output, new Center());
        } else if (tag.equalsIgnoreCase("table")) {
            start(output, new Table());
            if (tabLevel == 0) {
                tabHtmlBuild = new StringBuilder();
                output.append("table placeHolder");
            }
            tabLevel++;

        } else if (tag.equalsIgnoreCase("th")) {
            start(output, new Th());
        } else if (tag.equalsIgnoreCase("td")) {
            start(output, new Td());
        } else if (tag.equalsIgnoreCase("tr")) {
            start(output, new Tr());
        }

    }

.... }

the solution you can get from source code.

On the other hand, react native is a new platform supports both android and ios, it uses js bridge, and translate view to native UI. It only supports limited CSS style. the detail CSS that supported is listed here, you can look up it. At the same time, you can read the office doc:

the view support style:View style props

the text support style:Text style props

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.