react-native-star-rating-widget icon indicating copy to clipboard operation
react-native-star-rating-widget copied to clipboard

Don't block if the user clicks on the same rating again

Open Jeet-ND opened this issue 9 months ago • 3 comments

Version: 1.7.3

Issue: Suppose the user selects 5 stars, the onChange() is triggered returning the rating as 5.

Now, suppose if the user selects 5 stars again, the onChange() does not fire because of the following condition under StarRating.tsx

if (finalRating !== rating) { onChange(finalRating); }

Kindly remove this condition as it can be handled in the code easily.

@bviebahn

Jeet-ND avatar Apr 26 '24 14:04 Jeet-ND

I think it makes sense the way it is, why do you want the function to be called with the same argument? Can you explain your use-case?

bviebahn avatar May 06 '24 13:05 bviebahn

One of the reasons could be that if you click on the same rating again it should clear the rating. This is not possible right now.

mateogianolio avatar May 22 '24 09:05 mateogianolio

I think it makes sense the way it is, why do you want the function to be called with the same argument? Can you explain your use-case?

I open a modal when any rating is selected by the user, inside of the modal I display the same rating selected outside of it along with the feedback input. In one of the edge cases, when the rating is first selected and the user swipes down the modal without entering any feedback, and wishes to add it later, in this case, they select the same rating again, but it does not open the modal, because the onChange() is not triggered with the same rating again.

I hope it makes sense to you.

Jeet-ND avatar May 22 '24 09:05 Jeet-ND

Sorry, I somehow lost track of this and forgot about it. You're right, these are valid use cases, I'll look into this today.

bviebahn avatar Sep 06 '24 13:09 bviebahn

I just created a new release, v1.9.1, that adds the rating value to the onRatingStart and onRatingEnd props, which should help with both of these use cases. I also added an example for clearing the rating when tapping on it, since there is a small edge case to handle: example/src/ClearOnCurrentRatingTapExample.tsx

bviebahn avatar Sep 07 '24 10:09 bviebahn