Hướng dẫn native-html/table-plugin
⚠️ This documentation is for react-native-render-html v6 (@native-html/). For v5 and below, go here.
🔠 A WebView-based plugin to render tables in react-native-render-html.
npm add --save @native-html/table-plugin yarn add @native-html/table-plugin Features:
Known Limitations:
Compat Table
Minimal working exampleFull example You need 2 steps to get to a working example:
import React from 'react'; import { ScrollView } from 'react-native'; import HTML from 'react-native-render-html'; import TableRenderer, { tableModel } from '@native-html/table-plugin'; import WebView from 'react-native-webview'; const html = ` API ReferenceThe complete API reference is available here: docs/table-plugin.md. Most notably, check Landmark exports:
Other exports:
TroubleshootingErrors when importing WebView component
Setting up
FAQHow to easily style the table?Use import TableRenderer { defaultTableStylesSpecs, cssRulesFromSpecs } from '@native-html/table-plugin'; const htmlProps = { renderers: { table: TableRenderer }, renderersProps: { table: { tableStyleSpecs: { // my style specs } } } }; How to disable autoheight?Pass import TableRenderer { defaultTableStylesSpecs, cssRulesFromSpecs } from '@native-html/table-plugin'; const htmlProps = { renderers: { table: TableRenderer }, renderersProps: { table: { computeContainerHeight() { return null; } } } }; How to extend default or custom styles?A: Use import TableRenderer { defaultTableStylesSpecs, cssRulesFromSpecs } from '@native-html/table-plugin'; const cssRules = cssRulesFromSpecs(defaultTableStylesSpecs) + ` a { text-transform: uppercase; } `; const tableConfig = { cssRules } const htmlProps = { renderers: { table: TableRenderer }, renderersProps: { table: { cssRules } } }; How to customize the Table component?A:
See How to load custom fonts?A: Extend styles and add import TableRenderer, { defaultTableStylesSpecs, cssRulesFromSpecs } from '@native-html/table-plugin'; import { Platform } from 'react-native'; function getFontAssetURL(fontFileName: string) { return Platform.select({ ios: `url(${fontFileName})`, android: `url(file://android_asset/fonts/${fontFileName})` }); } const openSansUnicodeRanges = 'U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD'; const openSansRegular = getFontAssetURL('OpenSans-Regular.ttf'); const cssRules = cssRulesFromSpecs({ ...defaultTableStylesSpecs, fontFamily: '"Open Sans"' // beware to quote font family name! }) + ` @font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 400; src: ${openSansRegular}, format('ttf'); unicode-range: ${openSansUnicodeRanges}; } `; const htmlProps = { renderers: { table: TableRenderer }, renderersProps: { table: { cssRules } } }; |