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
26 changes: 12 additions & 14 deletions src/TapRating.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,26 @@ export type TapRatingProps = {
starStyle?: StyleProp<ViewStyle>;
};

const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
const [position, setPosition] = useState<number>(props.defaultRating);
const TapRating: React.FunctionComponent<TapRatingProps> =
({
defaultRating = 3,
reviews = ["Terrible", "Bad", "Okay", "Good", "Great"],
count = 5,
showRating = true,
reviewColor = "rgba(230, 196, 46, 1)",
reviewSize = 25,
...props
}) => {
const [position, setPosition] = useState<number>(defaultRating);

useEffect(() => {
const { defaultRating } = props;

if (defaultRating === null || defaultRating === undefined) {
setPosition(3);
} else {
setPosition(defaultRating);
}
}, [props.defaultRating]);
}, [defaultRating]);

const renderStars = (rating_array) => {
return _.map(rating_array, (star) => {
Expand All @@ -138,7 +146,6 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
setPosition(position);
};

const { count, reviews, showRating, reviewColor, reviewSize } = props;
const rating_array = [];
const starContainerStyle = [styles.starContainer];

Expand Down Expand Up @@ -183,15 +190,6 @@ const TapRating: React.FunctionComponent<TapRatingProps> = (props) => {
);
};

TapRating.defaultProps = {
defaultRating: 3,
reviews: ["Terrible", "Bad", "Okay", "Good", "Great"],
count: 5,
showRating: true,
reviewColor: "rgba(230, 196, 46, 1)",
reviewSize: 25,
};

const styles = StyleSheet.create({
ratingContainer: {
backgroundColor: "transparent",
Expand Down
11 changes: 1 addition & 10 deletions src/components/Star.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type StarProps = {
starSelectedInPosition?: ( number ) => void;
};

const Star: React.FunctionComponent<StarProps> = props => {
const Star: React.FunctionComponent<StarProps> = ({starImage = STAR_IMAGE, selectedColor = "#f1c40f", unSelectedColor = "#BDC3C7", ...props}) => {
const [selected, setSelected] = useState<boolean>( false );
const springValue = new Animated.Value( 1 );

Expand All @@ -45,11 +45,8 @@ const Star: React.FunctionComponent<StarProps> = props => {
};

const {
starImage,
fill,
size,
selectedColor,
unSelectedColor,
isDisabled,
starStyle
} = props;
Expand All @@ -76,12 +73,6 @@ const Star: React.FunctionComponent<StarProps> = props => {
);
};

Star.defaultProps = {
starImage: STAR_IMAGE,
selectedColor: "#f1c40f",
unSelectedColor: "#BDC3C7"
};

export default Star;

const styles = StyleSheet.create( {
Expand Down