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
84 changes: 38 additions & 46 deletions StarButton.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
// React and react native imports
import React, { Component } from 'react';
import { Image, StyleSheet, ViewPropTypes } from 'react-native';
import PropTypes from 'prop-types';
import { createIconSetFromIcoMoon } from 'react-native-vector-icons';
import React, { Component } from "react";
import { Image, StyleSheet, ViewPropTypes } from "react-native";
import PropTypes from "prop-types";
import { createIconSetFromIcoMoon } from "react-native-vector-icons";

// Third party imports
import Button from 'react-native-button';
import EntypoIcons from 'react-native-vector-icons/Entypo';
import EvilIconsIcons from 'react-native-vector-icons/EvilIcons';
import FeatherIcons from 'react-native-vector-icons/Feather';
import FontAwesomeIcons from 'react-native-vector-icons/FontAwesome';
import FoundationIcons from 'react-native-vector-icons/Foundation';
import IoniconsIcons from 'react-native-vector-icons/Ionicons';
import MaterialIconsIcons from 'react-native-vector-icons/MaterialIcons';
import MaterialCommunityIconsIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import OcticonsIcons from 'react-native-vector-icons/Octicons';
import ZocialIcons from 'react-native-vector-icons/Zocial';
import SimpleLineIconsIcons from 'react-native-vector-icons/SimpleLineIcons';
import Button from "react-native-button";
import EntypoIcons from "react-native-vector-icons/Entypo";
import EvilIconsIcons from "react-native-vector-icons/EvilIcons";
import FeatherIcons from "react-native-vector-icons/Feather";
import FontAwesomeIcons from "react-native-vector-icons/FontAwesome";
import FontAwesome5Icons from "react-native-vector-icons/FontAwesome5";
import FoundationIcons from "react-native-vector-icons/Foundation";
import IoniconsIcons from "react-native-vector-icons/Ionicons";
import MaterialIconsIcons from "react-native-vector-icons/MaterialIcons";
import MaterialCommunityIconsIcons from "react-native-vector-icons/MaterialCommunityIcons";
import OcticonsIcons from "react-native-vector-icons/Octicons";
import ZocialIcons from "react-native-vector-icons/Zocial";
import SimpleLineIconsIcons from "react-native-vector-icons/SimpleLineIcons";
import FontistoIcons from "react-native-vector-icons/Fontisto";
import AntDesignIcons from "react-native-vector-icons/AntDesign";

const iconSets = {
Entypo: EntypoIcons,
EvilIcons: EvilIconsIcons,
Feather: FeatherIcons,
FontAwesome: FontAwesomeIcons,
FontAwesome5: FontAwesome5Icons,
Foundation: FoundationIcons,
Ionicons: IoniconsIcons,
MaterialIcons: MaterialIconsIcons,
MaterialCommunityIcons: MaterialCommunityIconsIcons,
Octicons: OcticonsIcons,
Zocial: ZocialIcons,
SimpleLineIcons: SimpleLineIconsIcons,
Fontisto: FontistoIcons,
AntDesign: AntDesignIcons,
};

const propTypes = {
Expand All @@ -49,13 +55,15 @@ const propTypes = {
starSize: PropTypes.number.isRequired,
activeOpacity: PropTypes.number.isRequired,
starStyle: ViewPropTypes.style,
iconSolid: PropTypes.bool,
onStarButtonPress: PropTypes.func.isRequired,
};

const defaultProps = {
buttonStyle: {},
icoMoonJson: undefined,
starStyle: {},
iconSolid: false,
};

class StarButton extends Component {
Expand All @@ -66,12 +74,7 @@ class StarButton extends Component {
}

onButtonPress(event) {
const {
halfStarEnabled,
starSize,
rating,
onStarButtonPress,
} = this.props;
const { halfStarEnabled, starSize, rating, onStarButtonPress } = this.props;

let addition = 0;

Expand All @@ -84,10 +87,7 @@ class StarButton extends Component {
}

iconSetFromProps() {
const {
icoMoonJson,
iconSet,
} = this.props;
const { icoMoonJson, iconSet } = this.props;
if (icoMoonJson) {
return createIconSetFromIcoMoon(icoMoonJson);
}
Expand All @@ -102,56 +102,48 @@ class StarButton extends Component {
starIconName,
starSize,
starStyle,
iconSolid,
} = this.props;

const Icon = this.iconSetFromProps();
let iconElement;

const newStarStyle = {
transform: [{
scaleX: reversed ? -1 : 1,
}],
transform: [
{
scaleX: reversed ? -1 : 1,
},
],
...StyleSheet.flatten(starStyle),
};

if (typeof starIconName === 'string') {
if (typeof starIconName === "string") {
iconElement = (
<Icon
name={starIconName}
size={starSize}
color={starColor}
style={newStarStyle}
solid={iconSolid}
/>
);
} else {
const imageStyle = {
width: starSize,
height: starSize,
resizeMode: 'contain',
resizeMode: "contain",
};

const iconStyles = [
imageStyle,
newStarStyle,
];
const iconStyles = [imageStyle, newStarStyle];

iconElement = (
<Image
source={starIconName}
style={iconStyles}
/>
);
iconElement = <Image source={starIconName} style={iconStyles} />;
}

return iconElement;
}

render() {
const {
activeOpacity,
buttonStyle,
disabled,
} = this.props;
const { activeOpacity, buttonStyle, disabled } = this.props;

return (
<Button
Expand Down
61 changes: 35 additions & 26 deletions StarRating.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// React and react native imports
import React, { Component } from 'react';
import { View, ViewPropTypes, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import { View as AnimatableView } from 'react-native-animatable';
import React, { Component } from "react";
import { View, ViewPropTypes, StyleSheet } from "react-native";
import PropTypes from "prop-types";
import { View as AnimatableView } from "react-native-animatable";

// Local file imports
import StarButton from './StarButton';
import StarButton from "./StarButton";

const ANIMATION_TYPES = [
'bounce',
'flash',
'jello',
'pulse',
'rotate',
'rubberBand',
'shake',
'swing',
'tada',
'wobble',
"bounce",
"flash",
"jello",
"pulse",
"rotate",
"rubberBand",
"shake",
"swing",
"tada",
"wobble",
];

const propTypes = {
Expand Down Expand Up @@ -54,6 +54,7 @@ const propTypes = {
starSize: PropTypes.number,
starStyle: ViewPropTypes.style,
selectedStar: PropTypes.func,
iconSolid: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -62,21 +63,22 @@ const defaultProps = {
buttonStyle: {},
containerStyle: {},
disabled: false,
emptyStar: 'star-o',
emptyStarColor: 'gray',
fullStar: 'star',
fullStarColor: 'black',
halfStar: 'star-half-o',
emptyStar: "star-o",
emptyStarColor: "gray",
fullStar: "star",
fullStarColor: "black",
halfStar: "star-half-o",
halfStarColor: undefined,
halfStarEnabled: false,
icoMoonJson: undefined,
iconSet: 'FontAwesome',
iconSet: "FontAwesome",
maxStars: 5,
rating: 0,
reversed: false,
starSize: 40,
starStyle: {},
selectedStar: () => {},
iconSolid: false,
};

class StarRating extends Component {
Expand Down Expand Up @@ -114,11 +116,12 @@ class StarRating extends Component {
reversed,
starSize,
starStyle,
iconSolid,
} = this.props;

const newContainerStyle = {
flexDirection: reversed ? 'row-reverse' : 'row',
justifyContent: 'space-between',
flexDirection: reversed ? "row-reverse" : "row",
justifyContent: "space-between",
...StyleSheet.flatten(containerStyle),
};

Expand All @@ -145,7 +148,9 @@ class StarRating extends Component {
const starButtonElement = (
<AnimatableView
key={i}
ref={(node) => { this.starRef.push(node); }}
ref={(node) => {
this.starRef.push(node);
}}
>
<StarButton
activeOpacity={activeOpacity}
Expand All @@ -154,10 +159,11 @@ class StarRating extends Component {
halfStarEnabled={halfStarEnabled}
icoMoonJson={icoMoonJson}
iconSet={iconSet}
iconSolid={iconSolid}
onStarButtonPress={(event) => {
if (animation && ANIMATION_TYPES.includes(animation)) {
for (let s = 0; s <= i; s++) {
this.starRef[s][animation](1000 + (s * 200));
this.starRef[s][animation](1000 + s * 200);
}
}
this.onStarButtonPress(event);
Expand All @@ -177,7 +183,10 @@ class StarRating extends Component {
}

return (
<View style={newContainerStyle} pointerEvents={disabled ? 'none' : 'auto'}>
<View
style={newContainerStyle}
pointerEvents={disabled ? "none" : "auto"}
>
{starButtons}
</View>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"prop-types": "^15.5.10",
"react-native-animatable": "^1.2.4",
"react-native-button": "^2.3.0",
"react-native-vector-icons": "^4.5.0"
"react-native-vector-icons": "^7.0.0"
},
"repository": {
"type": "git",
Expand Down