Giter Site home page Giter Site logo

satish1020 / react-native-svg-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from target/react-native-svg-parser

0.0 1.0 0.0 134 KB

Parses SVG files and converts to 'react-native-svg' format objects. NOTE: This project has been archived.

License: MIT License

JavaScript 100.00%

react-native-svg-parser's Introduction

react-native-svg-parser

This project is a proof of concept only. It is not actively maintained. 

npm version Build Status

An SVG/XML parser that converts to react-native-svg format. This project was created in order to make it easy to use existing SVG files with the react-native-svg project, which only supports a subset of SVG and does not provide a method for directly rendering SVG from an SVG/XML format file.

Installation

npm i @target-corp/react-native-svg-parser

Usage

import ReactNativeSvgParser from 'react-native-svg-parser'

const svgNode = ReactNativeSvgParser(`YOUR SVG XML STRING`, `YOUR CSS STYLESHEET STRING`)

....

render() {
  return <View>
    { svgNode }
  </View>
}

Options

The parser takes a third parameter, and object with config options. You can specify the following values:

Prop name Type Description
width number overrides the width provided by viewbox, becomes "width" prop on Svg element
height number overrides the height provided by viewbox, becomes "height" prop on Svg element
viewBox string overrides the viewbox element on the SVG and is added as a prop on Svg element
DOMParser object this is passed directly to xmldom.DOMParser, see xmldom docs for options available
omitById array an optional array of ids to omit from the SVG output object

Example usage:

import ReactNativeSvgParser from 'react-native-svg-parser'

const svgString = `<svg height="100" width="100">
  <circle cx="50" cy="50" r="40" class="red-circle" />
</svg>
`
const cssString = `
.red-circle {
  fill: red;
  stroke: black;
  stroke-width: 3;
}
`

const svgNode = ReactNativeSvgParser(svgString, cssString, {width: 111, height: 222})

.... // (will render a red circle with a black stroke)

render() {
  return <View>
    { svgNode }
  </View>
}

Developing: Lint test and build

In order to test and develop locally you will need to install the peer dependencies (React and React Native). However, we have you covered. Just run this command:

npm run install-peers

Then you can run test lint and build using this command:

npm run ci

Console warning, on transform prop

On v5.5.1 react-native-svg enforced prop type of "object" on transform attribute. However, as of v6.0.0 this is changed to:

    transform: PropTypes.oneOfType([PropTypes.object, PropTypes.string])

https://github.com/react-native-community/react-native-svg/blob/master/lib/props.js#L69

Therefore, the minimum version compatibility for this libaray with react-native-svg is version 6.0.0.

Changelog

v1.0.5

Fixed text node rendering.

react-native-svg-parser's People

Contributors

bobschultz avatar a-r-d avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.