mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-20 14:05:09 +00:00
56 lines
948 B
JavaScript
56 lines
948 B
JavaScript
/**
|
|
* Format potential percentage props
|
|
*
|
|
* convert somet props like those
|
|
* width="50%"
|
|
* height="500"
|
|
*
|
|
* to
|
|
* {
|
|
* width: {
|
|
* percentage: true,
|
|
* value: 0.5
|
|
* },
|
|
* height: {
|
|
* percentage: false,
|
|
* value: 500
|
|
* }
|
|
* }
|
|
*
|
|
*
|
|
*/
|
|
import percentToFloat from './percentToFloat';
|
|
|
|
function percentageTransform(value) {
|
|
if (typeof value === 'number') {
|
|
return {
|
|
percentage: false,
|
|
value
|
|
};
|
|
}
|
|
|
|
let float = percentToFloat(value);
|
|
|
|
return {
|
|
percentage: float !== +value,
|
|
value: float
|
|
}
|
|
}
|
|
|
|
export default class {
|
|
constructor(props, list) {
|
|
this.shape = {};
|
|
list.forEach(name => {
|
|
if (props[name] != null) {
|
|
this.shape[name] = percentageTransform(props[name]);
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
toJSON = () => {
|
|
return this.shape;
|
|
};
|
|
};
|
|
|