You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Because this uses nanoid instead of allowing the developer to specify their own key values, sometimes the menu onPress does not update when it should.
To Reproduce
Steps to reproduce the behavior:
Add HoldMenuProvider at the top of stack.
Make a list of HoldItem components with items that differ only by the onPress property but have the same titles and icons for each item.
yarn start --resetCache
Open app. Try long pressing a few items back and forth and occasionally the onPress function will get called for the wrong item rather than the one that was long pressed.
Expected behavior
The correct onPress being called for the hold item being long pressed.
Actual behavior
Occasionally the wrong onPress is called for the corresponding hold item. Adding an item with text that is unique across all hold items fixes the problem, but I don't want to make them unique other than the onPress functions.
Can I recommend instead of using a nanoid a timebased uuid like uuid.v1 be used? this solved my issue when i replaced nanoidi with new Date().toString()
Correction -- even using a date string doesnt change it, not a memoized version of the items. only fix is to make the titles unique as shown in screenrecordings
Can we add a key or id property t MenuItemProps? I think the react hooks are not recomputing the items because they don't have anything that differs other than the onPress function
Also, line 91 of HoldItem.tsx has no reactive dependencies, so does that mean it is only computed exactly once on mount?
A HAH! I found the culprit. Line 14 of MenuItems.tsx! Never ever use an index as a key! Adding a key property to MenuItemProps and passing that as the key for MenuItem on line 14 fixes this problem!
Describe the bug
Because this uses
nanoid
instead of allowing the developer to specify their ownkey
values, sometimes the menuonPress
does not update when it should.To Reproduce
Steps to reproduce the behavior:
HoldMenuProvider
at the top of stack.HoldItem
components with items that differ only by theonPress
property but have the same titles and icons for each item.yarn start --resetCache
onPress
function will get called for the wrong item rather than the one that was long pressed.Expected behavior
The correct onPress being called for the hold item being long pressed.
Actual behavior
Occasionally the wrong onPress is called for the corresponding hold item. Adding an item with text that is unique across all hold items fixes the problem, but I don't want to make them unique other than the onPress functions.
Screenshots
If applicable, add screenshots to help explain your problem.
*** Not working as expected. ***
https://github.com/enesozturk/react-native-hold-menu/assets/14790443/88583b0d-a8eb-49bc-8bf3-2b22329452f9
*** Oddly it works when make text unique for each item***
RPReplay_Final1688477184.MP4
Package versions
18.2.0
^0.71.8
^3.3.0
^0.1.6
^48.0.0
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: