File tree 2 files changed +10
-6
lines changed
2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,10 @@ class SwipeRatingScreen extends Component {
23
23
</ View >
24
24
< ScrollView style = { styles . flex } contentContainerStyle = { styles . center } >
25
25
< Card title = "DEFAULT" containerStyle = { styles . card } >
26
- < Rating showRating = { false } fractions = { false } />
26
+ < Rating showRating = { false } fractions = { false } />
27
27
</ Card >
28
- < Card title = "WITH RATING" containerStyle = { styles . card } >
29
- < Rating showRating = { true } fractions = { false } />
28
+ < Card title = "WITH RATING(custom start value) " containerStyle = { styles . card } >
29
+ < Rating showRating = { true } fractions = { false } startingValue = { 4 } />
30
30
</ Card >
31
31
< Card title = "WITH FRACTIONS" containerStyle = { styles . card } >
32
32
< Rating
Original file line number Diff line number Diff line change @@ -104,13 +104,15 @@ export default class SwipeRating extends Component {
104
104
105
105
componentDidMount ( ) {
106
106
try {
107
- this . setState ( { display : true , isComponentMounted : true } ) ;
107
+ this . setState (
108
+ { display : true , isComponentMounted : true } ,
109
+ ( ) => this . setCurrentRating ( this . props . startingValue )
110
+ ) ;
108
111
} catch ( err ) {
109
112
// eslint-disable-next-line no-console
110
113
console . log ( err )
111
114
}
112
115
113
- this . setCurrentRating ( this . props . startingValue ) ;
114
116
}
115
117
116
118
componentDidUpdate ( prevProps ) {
@@ -203,7 +205,9 @@ export default class SwipeRating extends Component {
203
205
} else if ( value < - ratingCount * imageSize / 2 ) {
204
206
currentRating = this . props . minValue ? this . props . minValue : 0 ;
205
207
} else if ( value <= imageSize || value > imageSize ) {
206
- currentRating = ( startingValue + value ) / imageSize ;
208
+ const diff = value / imageSize
209
+
210
+ currentRating = startingValue + diff ;
207
211
currentRating = fractions ? Number ( currentRating . toFixed ( fractions ) ) : Math . ceil ( currentRating ) ;
208
212
} else {
209
213
currentRating = fractions ? Number ( startingValue . toFixed ( fractions ) ) : Math . ceil ( startingValue ) ;
You can’t perform that action at this time.
0 commit comments