react-native-figma-squircle
Version:
Figma-flavored squircles for React Native
47 lines (44 loc) • 1.33 kB
JavaScript
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { useState } from 'react';
import Svg, { Path } from 'react-native-svg';
import { getSvgPath } from 'figma-squircle';
function SquircleView({
squircleParams,
children,
...rest
}) {
return /*#__PURE__*/React.createElement(View, rest, /*#__PURE__*/React.createElement(SquircleBackground, squircleParams), children);
}
function SquircleBackground({
cornerRadius,
cornerSmoothing,
fillColor = '#000',
strokeColor = '#000',
strokeWidth = 0
}) {
const [squircleSize, setSquircleSize] = useState(null);
return /*#__PURE__*/React.createElement(View, {
style: StyleSheet.absoluteFill,
onLayout: e => {
setSquircleSize({
width: e.nativeEvent.layout.width,
height: e.nativeEvent.layout.height
});
}
}, /*#__PURE__*/React.createElement(Svg, null, /*#__PURE__*/React.createElement(Path, {
d: squircleSize ? getSvgPath({
width: squircleSize.width - strokeWidth,
height: squircleSize.height - strokeWidth,
cornerSmoothing,
cornerRadius
}) : '',
translateX: strokeWidth / 2,
translateY: strokeWidth / 2,
fill: fillColor,
stroke: strokeColor,
strokeWidth: strokeWidth
})));
}
export { SquircleView };
//# sourceMappingURL=index.js.map