Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
"url": "https://github.com/Monte9/react-native-ratings/issues"
},
"homepage": "https://github.com/Monte9/react-native-ratings#readme",
"dependencies": {
"lodash": "^4.17.15"
},
"devDependencies": {
"@types/node": "^14.14.37",
"@types/react": "^17.0.3",
Expand Down
42 changes: 19 additions & 23 deletions src/SwipeRating.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from "react";
import times from "lodash/times";

import {
View,
Expand Down Expand Up @@ -209,12 +208,8 @@ export default class SwipeRating extends Component<

constructor( props ) {
super( props );
const {
onStartRating,
onSwipeRating,
onFinishRating,
fractions
} = this.props;
const { onStartRating, onSwipeRating, onFinishRating, fractions } =
this.props;
const position = new Animated.ValueXY();

const panResponder = PanResponder.create( {
Expand Down Expand Up @@ -366,15 +361,20 @@ export default class SwipeRating extends Component<
renderRatings() {
const { imageSize, ratingCount, type, tintColor } = this.props;
const { source } = TYPES[type];
const rating_array = [];

for ( let i = 0; i < ratingCount; i += 1 ) {
rating_array.push(
<View key={i} style={styles.starContainer}>
<Image
source={source}
style={{ width: imageSize, height: imageSize, tintColor }}
/>
</View>
);
}

return times( ratingCount, index =>
<View key={index} style={styles.starContainer}>
<Image
source={source}
style={{ width: imageSize, height: imageSize, tintColor }}
/>
</View>
);
return rating_array;
}

// eslint-disable-next-line max-statements
Expand Down Expand Up @@ -443,13 +443,8 @@ export default class SwipeRating extends Component<
}

displayCurrentRating() {
const {
ratingCount,
type,
readonly,
showReadOnlyText,
ratingTextColor
} = this.props;
const { ratingCount, type, readonly, showReadOnlyText, ratingTextColor } =
this.props;
const color = ratingTextColor || TYPES[type].color;

return (
Expand Down Expand Up @@ -573,5 +568,6 @@ const styles = StyleSheet.create( {
textAlign: "center",
fontFamily: Platform.OS === "ios" ? "Trebuchet MS" : null,
color: "#34495e"
}
},
starContainer: {}
} );
22 changes: 7 additions & 15 deletions src/TapRating.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from "lodash";

import React, { useState, useEffect } from "react";

import { StyleSheet, Text, View, StyleProp, ViewStyle } from "react-native";
Expand Down Expand Up @@ -64,7 +62,7 @@ export type TapRatingProps = {
*
* Default is none
*/
ratingContainerStyle?: StyleProp<ViewStyle>;
ratingContainerStyle?: StyleProp<ViewStyle>;

/**
* Callback method when the user finishes rating. Gives you the final rating value as a whole number
Expand Down Expand Up @@ -111,12 +109,6 @@ const TapRating: React.FunctionComponent<TapRatingProps> = props => {
}
}, [props.defaultRating] );

const renderStars = rating_array => {
return _.map( rating_array, star => {
return star;
} );
};

const starSelectedInPosition = position => {
const { onFinishRating } = props;

Expand All @@ -141,19 +133,19 @@ const TapRating: React.FunctionComponent<TapRatingProps> = props => {
ratingContainerStyle.push( props.ratingContainerStyle );
}

_.times( count, index => {
for ( let i = 0; i < count; i += 1 ) {
rating_array.push(
<Star
key={index}
position={index + 1}
key={i}
position={i + 1}
starSelectedInPosition={value => {
starSelectedInPosition( value );
}}
fill={position >= index + 1}
fill={position >= i + 1}
{...props}
/>
);
} );
}

return (
<View style={ratingContainerStyle}>
Expand All @@ -167,7 +159,7 @@ const TapRating: React.FunctionComponent<TapRatingProps> = props => {
{reviews[position - 1]}
</Text>
}
<View style={starContainerStyle}>{renderStars( rating_array )}</View>
<View style={starContainerStyle}>{rating_array}</View>
</View>
);
};
Expand Down