Skip to content

Commit

Permalink
Remove height offset in coordinate calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
isilher committed Jan 13, 2021
1 parent b88de39 commit 1fc38b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Tooltip extends React.Component<Props, State> {
ScreenWidth,
ScreenHeight,
width,
height,
withPointer,
);

Expand Down
13 changes: 3 additions & 10 deletions src/getTooltipCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { Dimensions } from 'react-native';

function convertDimensionToNumber(dimension, screenDimension) {
if (dimension === 'auto') return 0;

if (typeof dimension === 'string' && dimension.includes('%')) {
const decimal = Number(dimension.replace(/%/, '')) / 100;
return decimal * screenDimension;
Expand All @@ -30,7 +28,7 @@ type Coord = {
The tooltip coordinates are based on the element which it is wrapping.
We take the x and y coordinates of the element and find the best position
to place the tooltip. To find the best position we look for the side with the
most space. In order to find the side with the most space we divide the the
most space. In order to find the side with the most space we divide the the
surroundings in four quadrants and check for the one with biggest area.
Once we know the quandrant with the biggest area it place the tooltip in that
direction.
Expand All @@ -50,7 +48,6 @@ const getTooltipCoordinate = (
ScreenWidth: number,
ScreenHeight: number,
receivedTooltipWidth: number | string,
receivedTooltipHeight: number | string,
withPointer: boolean,
): Coord => {
const screenDims = Dimensions.get('screen');
Expand All @@ -59,10 +56,6 @@ const getTooltipCoordinate = (
receivedTooltipWidth,
screenDims.width,
);
const tooltipHeight = convertDimensionToNumber(
receivedTooltipHeight,
screenDims.height,
);
// The following are point coordinates: [x, y]
const center = [x + width / 2, y + height / 2];
const pOne = [center[0], 0];
Expand Down Expand Up @@ -98,8 +91,8 @@ const getTooltipCoordinate = (
// Deslocate the coordinates in the direction of the quadrant.
const directionCorrection = [[-1, -1], [1, -1], [1, 1], [-1, 1]];
const deslocateReferencePoint = [
[-tooltipWidth, -tooltipHeight],
[0, -tooltipHeight],
[-tooltipWidth, 0],
[0, 0],
[0, 0],
[-tooltipWidth, 0],
];
Expand Down

0 comments on commit 1fc38b7

Please sign in to comment.