-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rating value param to onRatingStart + onRatingEnd props (#74)
* feat: add rating value param to onRatingStart + onRatingEnd props * chore: upgrade typescript --------- Co-authored-by: Benedikt Viebahn <benedikt.viebahn@live-eo.com>
- Loading branch information
Showing
11 changed files
with
309 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import StarRating from 'react-native-star-rating-widget'; | ||
import ExampleContainer from './ExampleContainer'; | ||
|
||
export default function ClearOnCurrentRatingTapExample() { | ||
const [rating, setRating] = React.useState(3); | ||
|
||
const beforeStartRating = React.useRef(rating); | ||
const preventClear = React.useRef(false); | ||
|
||
const handleChange = (newRating: number) => { | ||
setRating(newRating); | ||
|
||
// You likely only want to clear the rating if the user taps on the current rating, | ||
// and prevent clearing the rating when the user swipes to the current rating. | ||
// If onChange is called it means the user did not tap on the current rating, | ||
// so we don't want to clear it when the interaction ends. | ||
preventClear.current = true; | ||
}; | ||
|
||
const handleRatingStart = () => { | ||
beforeStartRating.current = rating; | ||
preventClear.current = false; | ||
}; | ||
|
||
const handleRatingEnd = (endRating: number) => { | ||
if (!preventClear.current && endRating === beforeStartRating.current) { | ||
setRating(0); | ||
} | ||
}; | ||
|
||
return ( | ||
<ExampleContainer title="Clear rating when tapping on current rating Example"> | ||
<StarRating | ||
rating={rating} | ||
onChange={handleChange} | ||
onRatingStart={handleRatingStart} | ||
onRatingEnd={handleRatingEnd} | ||
/> | ||
</ExampleContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.