react-native-skia-responsive-text
Version:
A library providing a wrapper for the React Native Skia Text component, offering features like user-friendly text alignment, efficient multiline text management, and straightforward text truncation.
44 lines (41 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getVerticalAlignmentOffset = exports.getTextLinesAlignment = void 0;
const getTextLinesAlignment = function (lines, width) {
'worklet';
let alignment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'left';
switch (alignment) {
case 'right':
return lines.map(line => width - line.width);
case 'center':
return lines.map(line => (width - line.width) / 2);
case 'center-left':
case 'center-right':
const longestLineWidth = Math.max(...lines.map(line => line.width));
return lines.map(line => alignment === 'center-left' ? (width - longestLineWidth) / 2 : (width + longestLineWidth) / 2 - line.width);
case 'left':
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return lines.map(_ => 0);
}
};
exports.getTextLinesAlignment = getTextLinesAlignment;
const getVerticalAlignmentOffset = function (componentHeight) {
'worklet';
let parentHeight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
let verticalAlignment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'top';
switch (verticalAlignment) {
case 'top':
return 0;
case 'center':
if (componentHeight >= parentHeight) {
return 0;
}
return (parentHeight - componentHeight) / 2;
case 'bottom':
return parentHeight && parentHeight - componentHeight;
}
};
exports.getVerticalAlignmentOffset = getVerticalAlignmentOffset;
//# sourceMappingURL=alignment.js.map