From 16e5a58a13af456bbdb171432359036e6a247437 Mon Sep 17 00:00:00 2001 From: Mohammad Rajabifard Date: Wed, 1 Nov 2017 00:08:56 +0330 Subject: [PATCH] feat: separate SVG to React Native conversation --- .gitignore | 4 +++- pages/svg-to-react-native.js | 40 ++++++++++++++++++++++++++++++++++++ utils/routes.js | 6 ++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 pages/svg-to-react-native.js diff --git a/.gitignore b/.gitignore index df4c011..9a03b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ node_modules .idea out yarn-error.log -transform \ No newline at end of file +transform + +.vscode diff --git a/pages/svg-to-react-native.js b/pages/svg-to-react-native.js new file mode 100644 index 0000000..c194e30 --- /dev/null +++ b/pages/svg-to-react-native.js @@ -0,0 +1,40 @@ +import React, { PureComponent } from 'react' +import convertSvgString from 'transform-svg-to-native' +import Layout from '../components/Layout' +import ConversionPanel from '../components/ConversionPanel' +import isSvg from 'is-svg' +import svgo from 'transform-svg-to-native/dist/svgo' + +const defaultText = ` + +` + +export default class Svg2ReactNative extends PureComponent { + getTransformedValue = async (newValue: string) => { + if (!isSvg(newValue)) { + throw new Error('Please provide a valid SVG markup.') + } + + return new Promise(resolve => + convertSvgString(newValue, code => resolve(code)) + ) + } + + render () { + return ( + + + + ) + } +} diff --git a/utils/routes.js b/utils/routes.js index e91f8f7..7474313 100644 --- a/utils/routes.js +++ b/utils/routes.js @@ -51,6 +51,12 @@ export const categorizedRoutes = [ desc: 'An online REPL for converting HTML to JSX with proper support for SVG.' }, + { + label: 'SVG to React Native', + path: '/svg-to-react-native', + desc: + 'An online REPL for converting SVG to React Native compatible equivalent.' + }, { label: 'CSS to JS Objects', path: '/css-to-js',