Skip to content

Commit

Permalink
Fix SVG styles for mobile (#12608)
Browse files Browse the repository at this point in the history
* Fix SVG styles for mobile

* Simplify condition since className is always a string
  • Loading branch information
Tug committed Dec 6, 2018
1 parent d442d65 commit 5ca5479
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions packages/components/src/primitives/svg/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ export {
} from 'react-native-svg';

export const SVG = ( props ) => {
// We're using the react-native-classname-to-style plugin, so when a `className` prop is passed it gets converted to `style` here.
// Given it carries a string (as it was originally className) but an object is expected for `style`,
// we need to check whether `style` exists and is a string, and convert it to an object

let styleValues = {};
if ( typeof props.style === 'string' ) {
const oneStyle = props.style.split( ' ' ).map( ( element ) => styles[ element ] ).filter( Boolean );
styleValues = Object.assign( styleValues, ...oneStyle );
}

const stylesFromClasses = ( props.className || '' ).split( ' ' ).map( ( element ) => styles[ element ] ).filter( Boolean );
const styleValues = Object.assign( {}, props.style, ...stylesFromClasses );
const safeProps = { ...props, style: styleValues };

return (
Expand Down

0 comments on commit 5ca5479

Please sign in to comment.