Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure the options menu appears correctly relative to the three-dot icon #295

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions JoyboyCommunity/src/components/Menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Menu: React.FC<MenuProps> & MenuSubComponents = ({handle, open, onClose, c
const handleRef = useAnimatedRef<Animated.View>();
const animation = useSharedValue(0);

const {width} = useWindowDimensions();
const {width, height} = useWindowDimensions();

useEffect(() => {
animation.value = withTiming(open ? 1 : 0, {duration: 150});
Expand All @@ -58,7 +58,15 @@ const Menu: React.FC<MenuProps> & MenuSubComponents = ({handle, open, onClose, c
if (!handleBounds) return {};

const X = handleBounds.pageX;
const Y = handleBounds.pageY + handleBounds.height + 8;
let Y;

if (handleBounds.pageY + handleBounds.height + 40 > height) {
// If the handle is near the bottom, position the menu above the handle
Y = handleBounds.pageY - handleBounds.height - 8;
} else {
// Otherwise, position the menu below the handle
Y = handleBounds.pageY + handleBounds.height + 8;
}

if (X + menuWidth > width) {
return {
Expand All @@ -73,7 +81,7 @@ const Menu: React.FC<MenuProps> & MenuSubComponents = ({handle, open, onClose, c
left: X,
};
}
}, [width, animation]);
}, [width, height, animation]);

return (
<View style={styles.container}>
Expand Down
Loading