0.6.1 • Published 4 years ago

react-native-render-html-table-bridge v0.6.1

Weekly downloads
1,117
License
MIT
Repository
github
Last release
4 years ago

Table support for react-native-render-html

npm

npm add --save react-native-render-html-table-bridge
yarn add react-native-render-html-table-bridge

Features:

  • Render HTML tables with a WebView component you provide
  • Supports <HTML>onLinkPress prop to handle clicks
  • Automatic height

Known Limitations:

  • don't forget you're rendering cells inside a webview, so you won't be able to apply your custom renderers there
  • limited support of Expo <33 version ; full support 33 versions (see bellow limitation)
  • autoheight and onLinkPress config options only work with WebView v5.0.0 community edition

Minimal working example

Full example

You need 3 conditions to get to a working example:

  1. If you're not using Expo, install (npm add --save react-native-webview) and link (react-native link react-native-webview) react-native-webview
  2. inject alterNode and ignoredTags props to HTML component
  3. makeTableRenderer and inject renderers prop to HTML component
import React, {PureComponent} from 'react';
import {ScrollView} from 'react-native';
import HTML from 'react-native-render-html';
import { IGNORED_TAGS, alterNode, makeTableRenderer } from 'react-native-render-html-table-bridge';
import WebView from 'react-native-webview';

const html = `
<table>
  <tr>
    <th>Entry Header 1</th>
    <th>Entry Header 2</th>
  </tr>
  <tr>
    <td>Entry First Line 1</td>
    <td>Entry First Line 2</td>
  </tr>
</table>
`;

const config = {
    WebViewComponent: WebView
};

const renderers = {
  table: makeTableRenderer(config)
};

const htmlConfig = {
  alterNode,
  renderers,
  ignoredTags: IGNORED_TAGS
};

export default class Example extends PureComponent<Props> {
  render() {
    return (
      <ScrollView>
        <HTML html={html} {...htmlConfig}/>
      </ScrollView>
    )
  }
}

makeTableRenderer config

This config object will be passed to the HTMLTable component as props. Read through typescript definitions to discover available config options.

WebViewComponent

Required

Your WebView component.

Warning: Features such as autoheight and onLinkPress don't work with the legacy core version or Expo <33 version.

Please use latest community edition instead

autoheight

Optional

Fit height to HTML content.

default: true

Supported WebView: WebView community edition 5.0.0 and Expo SDK 33.

Warning: This prop causes a tiny flicker, because we have to wait the WebView DOM tree to be rendered before receiving the exact height. We use LayoutAnimation when the height changes to soften the transition, but you must enable the feature on android.

0.6.2-alpha.3

4 years ago

0.6.2-alpha.2

4 years ago

0.6.2-alpha.1

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.6.0-alpha.10

4 years ago

0.6.0-alpha.9

4 years ago

0.6.0-alpha.8

4 years ago

0.6.0-alpha.7

4 years ago

0.6.0-alpha.5

4 years ago

0.6.0-alpha.6

4 years ago

0.6.0-alpha.4

4 years ago

0.6.0-alpha.3

4 years ago

0.6.0-alpha.2

4 years ago

0.6.0-alpha.1

4 years ago

6.0.0-beta.1

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.1-rc.0

4 years ago

0.5.0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.4.0-rc.2

5 years ago

0.4.0-rc.1

5 years ago

0.3.1

5 years ago

0.3.1-rc-13.0

5 years ago

0.3.1-rc-12.0

5 years ago

0.3.1-rc-11.0

5 years ago

0.3.1-rc-10.0

5 years ago

0.3.1-rc-9.0

5 years ago

0.3.1-rc-8.0

5 years ago

0.3.1-rc-7.0

5 years ago

0.3.1-rc-6.0

5 years ago

0.3.1-rc-5.0

5 years ago

0.3.1-rc-4.0

5 years ago

0.3.1-rc-3.0

5 years ago

0.3.1-rc-2.0

5 years ago

0.3.1-rc-1.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.2.0-rc1

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago