-
Notifications
You must be signed in to change notification settings - Fork 98
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
[android] Fixed menu list remained tappable after dismiss on android #115
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ const MenuListComponent = () => { | |
const { state, theme, menuProps } = useInternal(); | ||
|
||
const [itemList, setItemList] = React.useState<MenuItemProps[]>([]); | ||
const [isVisible, setIsVisible] = React.useState<boolean>(state.value === CONTEXT_MENU_STATE.ACTIVE); | ||
|
||
const menuHeight = useDerivedValue(() => { | ||
const itemsWithSeparator = menuProps.value.items.filter( | ||
|
@@ -64,16 +65,20 @@ const MenuListComponent = () => { | |
); | ||
|
||
const _leftPosition = leftOrRight(menuProps); | ||
const isMenuActive = state.value === CONTEXT_MENU_STATE.ACTIVE | ||
|
||
const menuScaleAnimation = () => | ||
state.value === CONTEXT_MENU_STATE.ACTIVE | ||
isMenuActive | ||
? withSpring(1, SPRING_CONFIGURATION_MENU) | ||
: withTiming(0, { | ||
duration: HOLD_ITEM_TRANSFORM_DURATION, | ||
}); | ||
duration: HOLD_ITEM_TRANSFORM_DURATION, | ||
}, finished => { | ||
if (finished && !isMenuActive) | ||
runOnJS(setIsVisible)(false) | ||
}); | ||
|
||
const opacityAnimation = () => | ||
withTiming(state.value === CONTEXT_MENU_STATE.ACTIVE ? 1 : 0, { | ||
withTiming(isMenuActive ? 1 : 0, { | ||
duration: HOLD_ITEM_TRANSFORM_DURATION, | ||
}); | ||
|
||
|
@@ -101,8 +106,8 @@ const MenuListComponent = () => { | |
? 'rgba(255, 255, 255, .75)' | ||
: 'rgba(255, 255, 255, .95)' | ||
: IS_IOS | ||
? 'rgba(0,0,0,0.5)' | ||
: 'rgba(39, 39, 39, .8)', | ||
? 'rgba(0,0,0,0.5)' | ||
: 'rgba(39, 39, 39, .8)', | ||
}; | ||
}, [theme]); | ||
|
||
|
@@ -115,6 +120,15 @@ const MenuListComponent = () => { | |
prevList.value = items; | ||
}; | ||
|
||
useAnimatedReaction( | ||
() => state.value === CONTEXT_MENU_STATE.ACTIVE, | ||
isMenuActive => { | ||
if (isMenuActive) | ||
runOnJS(setIsVisible)(true) | ||
}, | ||
[state] | ||
) | ||
|
||
useAnimatedReaction( | ||
() => menuProps.value.items, | ||
_items => { | ||
|
@@ -125,22 +139,27 @@ const MenuListComponent = () => { | |
[menuProps] | ||
); | ||
|
||
if (!isVisible) | ||
return null | ||
Comment on lines
+142
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not test it, but I guess that this will break the animation when closing the menu. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't brake, you can check it |
||
|
||
return ( | ||
<AnimatedView | ||
intensity={100} | ||
animatedProps={animatedProps} | ||
style={[styles.menuContainer, messageStyles]} | ||
> | ||
<Animated.View | ||
style={[ | ||
StyleSheet.absoluteFillObject, | ||
styles.menuInnerContainer, | ||
animatedInnerContainerStyle, | ||
]} | ||
<Animated.View style={[styles.menuContainer, messageStyles]}> | ||
<AnimatedView | ||
intensity={100} | ||
animatedProps={animatedProps} | ||
style={StyleSheet.absoluteFillObject} | ||
> | ||
<MenuItems items={itemList} /> | ||
</Animated.View> | ||
</AnimatedView> | ||
<Animated.View | ||
style={[ | ||
StyleSheet.absoluteFillObject, | ||
styles.menuInnerContainer, | ||
animatedInnerContainerStyle, | ||
]} | ||
> | ||
Comment on lines
+146
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this change do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is applying the fix from this PR: https://github.com/enesozturk/react-native-hold-menu/pull/112/files |
||
<MenuItems items={itemList} /> | ||
</Animated.View> | ||
</AnimatedView> | ||
</Animated.View> | ||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think because we have these styles already in the
styles.holdItem