bviebahn/react-native-star-rating-widget

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

Closed this issue · 5 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

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?

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.

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.

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.

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