@nguyentc21/react-native-tooltip
Version:
Simple tooltip for React native app
89 lines (88 loc) • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _calculateTooltipOffset = _interopRequireDefault(require("./calculateTooltipOffset"));
var _getLimitTooltipPosition = _interopRequireDefault(require("./getLimitTooltipPosition"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
var _default = params => {
const {
placement,
dimension,
targetContentLayout,
tooltipContentLayout,
safeAreaInsets
} = params;
const {
width,
height
} = dimension;
const {
height: targetHeight,
width: targetWidth,
pageY,
pageX
} = targetContentLayout;
const {
offsetY,
offsetX
} = (0, _calculateTooltipOffset.default)({
targetContentLayout,
tooltipContentLayout
});
const {
minTop,
minBottom,
minLeft,
minRight,
maxTop,
maxBottom,
maxLeft,
maxRight
} = (0, _getLimitTooltipPosition.default)({
dimension,
tooltipContentLayout,
safeAreaInsets
});
let top, bottom, left, right;
if (placement === 'top' || placement === 'bottom') {
left = offsetX - safeAreaInsets.left;
if (placement === 'top') {
bottom = height - pageY - safeAreaInsets.bottom;
} else {
top = pageY - safeAreaInsets.top + targetHeight;
}
} else if (placement === 'left' || placement === 'right') {
top = offsetY - safeAreaInsets.top;
if (placement === 'left') {
right = width - pageX - safeAreaInsets.right;
} else {
left = pageX - safeAreaInsets.left + targetWidth;
}
}
if (top !== undefined) {
if (top < minTop) top = minTop;
if (top > maxTop) top = maxTop;
}
if (left !== undefined) {
if (left < minLeft) left = minLeft;
if (left > maxLeft) left = maxLeft;
}
if (bottom !== undefined) {
if (bottom < minBottom) bottom = minBottom;
if (bottom > maxBottom) bottom = maxBottom;
}
if (right !== undefined) {
if (right < minRight) right = minRight;
if (right > maxRight) right = maxRight;
}
return {
top,
bottom,
left,
right
};
};
exports.default = _default;
//# sourceMappingURL=generateTooltipPosition.js.map