Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@busfor/react-native-html-to-native

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@busfor/react-native-html-to-native

Create customizable React Native views from HTML markup

  • 1.2.0-rc.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-18.18%
Maintainers
2
Weekly downloads
 
Created
Source

react-native-html-to-native

npm npm (tag)

Library for parsing HTML code into native iOS and Android components with CSS selector-like styling and rendering


Getting started

$ yarn add @busfor/react-native-html-to-native

Usage

import { HTMLView } from '@busfor/react-native-html-to-native'
<HTMLView
  onLinkPress={(url) => console.log(url)}
  onError={(err) => console.log(err)}
  styles={styles}
  renderers={{
    'a.link': (renderedChildren, style, props) => {
      return (
        <TouchableOpacity key={props.key} onPress={() => console.log('Clicked', props.attributes.href)} style={style}>
          {renderedChildren}
        </TouchableOpacity>
      )
    },
  }}
  html={'<div><p>Paragraph</p></div>'}
  onLoading={(loading) => console.log(loading)}
/>

Docs

Properties

NameDescriptionType
html*Raw HTML code to be parsed and presentedstring
renderersHTML nodes render functionsObject
passPropsCustom props passed to node rendererObject
stylesCustom node stylesObject
onErrorError callback functionFunction
onLinkPressLink press callback functionFunction
parserOptionsParser options, see ParserOptions typeParserOptions
onLoadingLoading state callback, only parameter is loadingState of type booleanFunction
renderLoadingFunction to render custom loading indicatorFunction

* - required property

Types

ParserOptions

OptionDescriptionTypeDefault
normalizeWhitespaceIndicates whether whitespace in text nodes should be normalizedbooleanfalse
recognizeSelfClosingRecognize self-closing HTML tagsbooleantrue
decodeEntitiesIf set to true, entities within HTML code will be decodedbooleantrue

ElementRenderer - function for rendering html nodes as native elements

(renderedChildren: Array<ReactNode>, style: StyleProp<any>, props: ElementProps) => ReactNode

Function accepts rendered node's children, node's style and props

Should return ReactNode

For more see Default renderers


ElementProps - props of rendering HTML node

NameDescriptionType
attributesHTML tag attributesObject or undefined
passPropsCustom props passed to component render from HTMLViewObject
handleLinkPressLink press handler functionFunction
nodeHTML node for which element is renderedNode
childrenNode's children arrayArray<Node>
siblingsNode's siblings arrayArray<Node>
parentNode's parentNode
dataText data for text nodesstring
keyUnique key for component renderingstring

Selectors

Selectors system built in a CSS-like manner

To select element by tag name just use it as is: ol, p, etc.

For selecting by class or id use .class and #id. For more specific selection of component with class(same for component with id) use it like: p.class

Also it is possible to select HTML node by path like ol>li or ol.class>li#id etc.

Some HTML node have custom selectors. Text nodes are rendered as React Native <Text> components and can be accessed by TextNode selector. Same for list items indicators nodes - access it by IndicatorNode selector.

For more examples of using selectors see Usage, Example app and Default renderers and styles

Default renderers

Some HTML tags are rendered by default, some are skipped while rendering.

To know how HTML tags are rendered and how to use ElementRenderer functions see default renderers

Default styles

Some default styles for tags could be specified in this library

To see what styles are default for tags see default styles

Issues and contributing

Feel free to report any bug or request any functionality you would like to be done with Open Issue functionality of GitHub

Also feel free to fork and contribute by opening Pull Request. All pull requests will be reviewed and merged if everything is OK!

TODO:

⬜️ Improve CSS selectors

⬜️ Complete example app

⬜️ Add HTML parsing from URL

Keywords

FAQs

Package last updated on 23 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc