@kirz/react-native-toolkit
Version:
Toolkit to speed up React Native development
86 lines • 2.19 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import LinearGradient from 'react-native-linear-gradient';
import { RadialGradient } from '../components/RadialGradient';
export const renderGradient = gradients => {
return /*#__PURE__*/React.createElement(React.Fragment, null, gradients.map((gradient, gradientIdx) => {
if (typeof gradient === 'function') {
const Component = gradient;
return /*#__PURE__*/React.createElement(Component, {
key: gradientIdx
});
}
if ('type' in gradient && gradient.type === 'radial') {
return /*#__PURE__*/React.createElement(RadialGradient, _extends({
key: gradientIdx
}, gradient, {
style: {
position: 'absolute',
left: 0,
top: 0
}
}));
}
const {
direction,
...props
} = gradient;
return /*#__PURE__*/React.createElement(LinearGradient, _extends({
key: gradientIdx
}, props, {
style: [{
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0
}, gradient.style]
}, direction === 'left-right' ? {
start: {
x: 0,
y: 0.5
},
end: {
x: 1,
y: 0.5
}
} : direction === 'right-left' ? {
start: {
x: 1,
y: 0.5
},
end: {
x: 0,
y: 0.5
}
} : direction === 'up-bottom' ? {
start: {
x: 0.5,
y: 0
},
end: {
x: 0.5,
y: 1
}
} : direction === 'bottom-up' ? {
start: {
x: 0.5,
y: 1
},
end: {
x: 0.5,
y: 0
}
} : {
start: props.start ?? {
x: 0,
y: 0.5
},
end: props.end ?? {
x: 1,
y: 0.5
}
}));
}));
};
//# sourceMappingURL=renderGradient.js.map