From 736f241dab811cc3159a9b44b10297aa387516b5 Mon Sep 17 00:00:00 2001 From: Mohammad Rajabifard Date: Tue, 31 Oct 2017 23:35:47 +0330 Subject: [PATCH 1/2] fix: make optimizing SVG optional with a checkbox (remove react-native-svg) --- pages/html-to-jsx.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/pages/html-to-jsx.js b/pages/html-to-jsx.js index 27cf8da..2aa921c 100644 --- a/pages/html-to-jsx.js +++ b/pages/html-to-jsx.js @@ -1,6 +1,5 @@ import React, { PureComponent } from 'react' import HTMLtoJSX from '@tsuyoshiwada/htmltojsx' -import convertSvgString from 'transform-svg-to-native' import Layout from '../components/Layout' import ConversionPanel from '../components/ConversionPanel' import isSvg from 'is-svg' @@ -16,11 +15,11 @@ const defaultText = ` { - if (isSvg(html)) { + if (isSvg(html) && this.state.shouldOptimize) { return new Promise(resolve => { svgo.optimize(html, result => { resolve(converter.convert(result.data)) @@ -31,17 +30,7 @@ export default class Css2Js extends PureComponent { } getTransformedValue = async (newValue: string) => { - if (this.state.native && !isSvg(newValue)) { - throw new Error( - 'You can only convert an SVG in this mode. Try turning off the react-native-svg checkbox.' - ) - } - - return this.state.native - ? new Promise(resolve => - convertSvgString(newValue, code => resolve(code)) - ) - : this.convertHtmlToJsx(newValue) + return this.convertHtmlToJsx(newValue) } render () { @@ -56,11 +45,11 @@ export default class Css2Js extends PureComponent { getTransformedValue={this.getTransformedValue} name={'html_to_jsx'} defaultText={defaultText} - checkboxText='react-native-svg' + checkboxText='Optimize SVG' extensions={['.svg', '.html']} - initialCheckboxValue={this.state.native} + initialCheckboxValue={this.state.shouldOptimize} onCheckboxChange={(checked: boolean, cb: Function) => - this.setState({ native: checked }, cb)} + this.setState({ shouldOptimize: checked }, cb)} /> ) From 16e5a58a13af456bbdb171432359036e6a247437 Mon Sep 17 00:00:00 2001 From: Mohammad Rajabifard Date: Wed, 1 Nov 2017 00:08:56 +0330 Subject: [PATCH 2/2] 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',