Skip to content

Commit

Permalink
Merge pull request #141 from Monte9/bugfix/fix-swipe-rating
Browse files Browse the repository at this point in the history
Bugfix/fix swipe rating
  • Loading branch information
sshivananda authored Apr 2, 2021
2 parents a3a563e + c14cd2b commit 0920189
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions demo/src/SwipeRatingScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class SwipeRatingScreen extends Component {
</View>
<ScrollView style={styles.flex} contentContainerStyle={styles.center}>
<Card title="DEFAULT" containerStyle={styles.card}>
<Rating showRating={false} fractions={false} />
<Rating showRating={false} fractions={false}/>
</Card>
<Card title="WITH RATING" containerStyle={styles.card}>
<Rating showRating={true} fractions={false} />
<Card title="WITH RATING(custom start value)" containerStyle={styles.card}>
<Rating showRating={true} fractions={false} startingValue={ 4 }/>
</Card>
<Card title="WITH FRACTIONS" containerStyle={styles.card}>
<Rating
Expand Down
10 changes: 7 additions & 3 deletions src/SwipeRating.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ export default class SwipeRating extends Component {

componentDidMount() {
try {
this.setState( { display: true, isComponentMounted: true } );
this.setState(
{ display: true, isComponentMounted: true },
() => this.setCurrentRating( this.props.startingValue )
);
} catch ( err ) {
// eslint-disable-next-line no-console
console.log( err )
}

this.setCurrentRating( this.props.startingValue );
}

componentDidUpdate( prevProps ) {
Expand Down Expand Up @@ -203,7 +205,9 @@ export default class SwipeRating extends Component {
} else if ( value < -ratingCount * imageSize / 2 ) {
currentRating = this.props.minValue ? this.props.minValue : 0;
} else if ( value <= imageSize || value > imageSize ) {
currentRating = ( startingValue + value ) / imageSize;
const diff = value / imageSize

currentRating = startingValue + diff;
currentRating = fractions ? Number( currentRating.toFixed( fractions ) ) : Math.ceil( currentRating );
} else {
currentRating = fractions ? Number( startingValue.toFixed( fractions ) ) : Math.ceil( startingValue );
Expand Down

0 comments on commit 0920189

Please sign in to comment.