@@ -5,22 +5,27 @@ import styled from "styled-components/native";
55
66const StyledView = styled . View `
77 display: flex;
8- flex-direction: row;
98 align-items: center;
109 justify-content: center;
10+ flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
1111` ;
1212const BackgroundStars = styled . View `
1313 display: flex;
14- flex-direction: row;
1514 position: relative;
15+ flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
1616` ;
1717const ColoredStars = styled . View `
18- width: ${ ( { percentage } ) => `${ percentage } %` } ;
1918 display: flex;
20- flex-direction: row;
2119 overflow: hidden;
2220 position: absolute;
23- top: 0;
21+ flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
22+ width: ${ ( { percentage, dir } ) =>
23+ dir === "column" || dir === "column-reverse" ? `100%` : `${ percentage } %` } ;
24+ height: ${ ( { percentage, dir } ) =>
25+ dir === "row" || dir === "row-reverse" ? `100%` : `${ percentage } %` } ;
26+
27+ top: ${ ( { dir } ) => ( dir === "column" ? 0 : "auto" ) } ;
28+ bottom: ${ ( { dir } ) => ( dir === "column-reverse" ? 0 : "auto" ) } ;
2429` ;
2530
2631const Rating = ( {
@@ -33,11 +38,12 @@ const Rating = ({
3338 marginBetweenRatingIcon,
3439 readonly,
3540 onStarTap,
41+ direction,
3642} ) => {
3743 const percentage = ( rated / totalCount ) * 100 ;
3844 return (
39- < StyledView >
40- < BackgroundStars >
45+ < StyledView dir = { direction } >
46+ < BackgroundStars dir = { direction } >
4147 { Array . from ( { length : totalCount } , ( _ , i ) => (
4248 < StarButton
4349 name = { icon }
@@ -50,7 +56,7 @@ const Rating = ({
5056 readonly = { readonly }
5157 />
5258 ) ) }
53- < ColoredStars percentage = { percentage } >
59+ < ColoredStars percentage = { percentage } dir = { direction } >
5460 { Array . from ( { length : totalCount } , ( _ , i ) => (
5561 < StarButton
5662 name = { icon }
@@ -78,6 +84,7 @@ Rating.defaultProps = {
7884 icon : "ios-star" ,
7985 marginBetweenRatingIcon : 1 ,
8086 readonly : false ,
87+ direction : "row" ,
8188} ;
8289
8390Rating . propTypes = {
@@ -90,6 +97,12 @@ Rating.propTypes = {
9097 marginBetweenRatingIcon : PropTypes . number ,
9198 readonly : PropTypes . bool ,
9299 onStarTap : PropTypes . func ,
100+ direction : PropTypes . oneOf ( [
101+ "row" ,
102+ "row-reverse" ,
103+ "column" ,
104+ "column-reverse" ,
105+ ] ) ,
93106} ;
94107
95108export default Rating ;
0 commit comments