mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-06 16:32:24 +00:00
Fix handling of numeric gradient offsets, closes #827
This commit is contained in:
@@ -9,7 +9,10 @@ import units from "../units";
|
||||
const percentReg = /^([+\-]?\d+(?:\.\d+)?(?:[eE][+\-]?\d+)?)(%?)$/;
|
||||
|
||||
function percentToFloat(percent) {
|
||||
const matched = percent.toString().match(percentReg);
|
||||
if (typeof percent === 'number') {
|
||||
return percent;
|
||||
}
|
||||
const matched = percent.match(percentReg);
|
||||
if (!matched) {
|
||||
console.warn(
|
||||
`\`${percent}\` is not a valid number or percentage string.`,
|
||||
@@ -26,15 +29,18 @@ export default function(props) {
|
||||
}
|
||||
|
||||
const stops = {};
|
||||
Children.forEach(props.children, child => {
|
||||
if (child.props.stopColor && child.props.offset) {
|
||||
// convert percent to float.
|
||||
const offset = percentToFloat(child.props.offset);
|
||||
|
||||
// add stop
|
||||
Children.forEach(props.children, ({
|
||||
props: {
|
||||
offset,
|
||||
stopColor,
|
||||
stopOpacity,
|
||||
}
|
||||
}) => {
|
||||
offset = percentToFloat(offset);
|
||||
if (stopColor && !isNaN(offset)) {
|
||||
//noinspection JSUnresolvedFunction
|
||||
stops[offset] = Color(child.props.stopColor).alpha(
|
||||
extractOpacity(child.props.stopOpacity),
|
||||
stops[offset] = Color(stopColor).alpha(
|
||||
extractOpacity(stopOpacity),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user