Skip to content

Commit 6e606a0

Browse files
committed
fix: setting top offset of Menu based on anchorPosition
1 parent 601fc70 commit 6e606a0

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

example/src/Examples/MenuExample.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ const MenuExample = ({ navigation }: Props) => {
146146
</TouchableRipple>
147147
</List.Section>
148148
</View>
149+
<View style={styles.alignCenter}>
150+
<Menu
151+
visible={_getVisible('menu5')}
152+
onDismiss={_toggleMenu('menu5')}
153+
anchorPosition="bottom"
154+
anchor={
155+
<Button mode="outlined" onPress={_toggleMenu('menu5')}>
156+
Menu with anchor position
157+
</Button>
158+
}
159+
>
160+
<Menu.Item onPress={() => {}} title="Item 1" />
161+
<Menu.Item onPress={() => {}} title="Item 2" />
162+
<Menu.Item onPress={() => {}} title="Item 3" />
163+
</Menu>
164+
</View>
149165

150166
<View style={styles.bottomMenu}>
151167
<Menu

src/components/Menu/Menu.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,6 @@ const Menu = ({
441441
updateVisibility(rendered);
442442
}, [rendered, updateVisibility]);
443443

444-
React.useEffect(() => {
445-
if (!isCoordinate(anchorRef.current) && anchorPosition === 'bottom') {
446-
setTop((prev) => prev + anchorLayout.height);
447-
}
448-
}, [anchorPosition, anchorLayout.height]);
449-
450444
// I don't know why but on Android measure function is wrong by 24
451445
const additionalVerticalValue = Platform.select({
452446
android: statusBarHeight,
@@ -456,7 +450,10 @@ const Menu = ({
456450
// We need to translate menu while animating scale to imitate transform origin for scale animation
457451
const positionTransforms = [];
458452
let leftTransformation = left;
459-
let topTransformation = top;
453+
let topTransformation =
454+
!isCoordinate(anchorRef.current) && anchorPosition === 'bottom'
455+
? top + anchorLayout.height
456+
: top;
460457

461458
// Check if menu fits horizontally and if not align it to right.
462459
if (left <= windowLayout.width - menuLayout.width - SCREEN_INDENT) {

0 commit comments

Comments
 (0)