Skip to content

Commit

Permalink
remove unnecessary variables for cursorCoordinates, remove unnecessar…
Browse files Browse the repository at this point in the history
…y fallback values, remove irrelevant comment
  • Loading branch information
danstepanov committed Mar 7, 2025
1 parent 6ad3297 commit 8f38734
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/components/AutoCompleteSuggestions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
}

measureParentContainerAndReportCursor(({x, y, width, scrollValue, cursorCoordinates}: MeasureParentContainerAndCursor) => {
// On iOS, if cursor coordinates are not available, use the parent container's position
const effectiveCursorX = cursorCoordinates.x || 0;
const effectiveCursorY = cursorCoordinates.y || 0;

const xCoordinatesOfCursor = x + effectiveCursorX;
const xCoordinatesOfCursor = x + cursorCoordinates.x;
const bigScreenLeftOffset =
xCoordinatesOfCursor + CONST.AUTO_COMPLETE_SUGGESTER.BIG_SCREEN_SUGGESTION_WIDTH > windowWidth
? windowWidth - CONST.AUTO_COMPLETE_SUGGESTER.BIG_SCREEN_SUGGESTION_WIDTH
Expand All @@ -106,19 +102,19 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
const contentMinHeight = measureHeightOfSuggestionRows(suggestionsLength, false);

// Use the parent container's y position if cursor coordinates are not available
let bottomValue = windowHeight - (effectiveCursorY - scrollValue + y) - keyboardHeight;
let bottomValue = windowHeight - (cursorCoordinates.y - scrollValue + y) - keyboardHeight;
const widthValue = shouldUseNarrowLayout ? width : CONST.AUTO_COMPLETE_SUGGESTER.BIG_SCREEN_SUGGESTION_WIDTH;

const isEnoughSpaceToRenderMenuAboveForBig = isEnoughSpaceToRenderMenuAboveCursor({
y,
cursorCoordinates: {x: effectiveCursorX, y: effectiveCursorY},
cursorCoordinates: {x: cursorCoordinates.x, y: cursorCoordinates.y},
scrollValue,
contentHeight: contentMaxHeight,
topInset,
});
const isEnoughSpaceToRenderMenuAboveForSmall = isEnoughSpaceToRenderMenuAboveCursor({
y,
cursorCoordinates: {x: effectiveCursorX, y: effectiveCursorY},
cursorCoordinates: {x: cursorCoordinates.x, y: cursorCoordinates.y},
scrollValue,
contentHeight: contentMinHeight,
topInset,
Expand All @@ -145,15 +141,15 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
} else {
// calculation for big suggestion box below the cursor
measuredHeight = measureHeightOfSuggestionRows(suggestionsLength, true);
bottomValue = windowHeight - y - effectiveCursorY + scrollValue - measuredHeight - CONST.AUTO_COMPLETE_SUGGESTER.SUGGESTION_ROW_HEIGHT - keyboardHeight;
bottomValue = windowHeight - y - cursorCoordinates.y + scrollValue - measuredHeight - CONST.AUTO_COMPLETE_SUGGESTER.SUGGESTION_ROW_HEIGHT - keyboardHeight;
}

setSuggestionHeight(measuredHeight);
setContainerState({
left: leftValue.current,
bottom: bottomValue,
width: widthValue,
cursorCoordinates: {x: effectiveCursorX, y: effectiveCursorY},
cursorCoordinates: {x: cursorCoordinates.x, y: cursorCoordinates.y},
});
});
}, [measureParentContainerAndReportCursor, windowHeight, windowWidth, keyboardHeight, shouldUseNarrowLayout, suggestionsLength, bottomInset, topInset, isKeyboardAnimatingRef]);
Expand Down

0 comments on commit 8f38734

Please sign in to comment.