@@ -4,27 +4,45 @@ import IconBar from "./components/IconBar";
44import styled from "styled-components/native" ;
55
66const StyledView = styled . View `
7- display: flex;
8- align-items: center;
9- justify-content: center;
107 flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
118` ;
129const BackgroundIcons = styled . View `
13- display: flex;
1410 position: relative;
1511 flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
12+ ${ ( { type, dir } ) =>
13+ type !== "custom" &&
14+ dir === "row-reverse" &&
15+ `
16+ flex-direction: row;
17+ ` }
18+ ${ ( { type, dir } ) =>
19+ type !== "custom" &&
20+ dir === "column-reverse" &&
21+ `
22+ flex-direction: column;
23+ ` }
1624` ;
1725const ColoredIcons = styled . View `
18- display: flex;
1926 overflow: hidden;
2027 position: absolute;
2128 flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
29+ ${ ( { type, dir } ) =>
30+ type !== "custom" &&
31+ dir === "row-reverse" &&
32+ `
33+ flex-direction: row;
34+ ` } ;
35+ ${ ( { type, dir } ) =>
36+ type !== "custom" &&
37+ dir === "column-reverse" &&
38+ `
39+ flex-direction: column;
40+ ` } ;
2241 width: ${ ( { percentage, dir } ) =>
23- dir === "column" || dir === "column-reverse" ? `100% ` : `${ percentage } %` } ;
42+ dir === "column" || dir === "column-reverse" ? `auto ` : `${ percentage } %` } ;
2443 height: ${ ( { percentage, dir } ) =>
25- dir === "row" || dir === "row-reverse" ? `100%` : `${ percentage } %` } ;
26-
27- top: ${ ( { dir } ) => ( dir === "column" ? 0 : "auto" ) } ;
44+ dir === "row" || dir === "row-reverse" ? `auto` : `${ percentage } %` } ;
45+ top: 0;
2846 bottom: ${ ( { dir } ) => ( dir === "column-reverse" ? 0 : "auto" ) } ;
2947` ;
3048
@@ -43,23 +61,30 @@ const Rating = ({
4361 selectedIconImage,
4462 emptyIconImage,
4563} ) => {
46- const percentage = ( rated / totalCount ) * 100 ;
47-
64+ const isReverse = [ "row-reverse" , "column-reverse" ] . includes ( direction ) ;
65+ let percentage = ( rated / totalCount ) * 100 ;
66+ if ( isReverse && type !== "custom" ) {
67+ percentage = 100 - percentage ;
68+ }
4869 return (
4970 < StyledView
5071 dir = { direction }
5172 accessible = { ! readonly }
5273 importantForAccessibility = { ! readonly ? "yes" : "no" }
5374 >
54- < BackgroundIcons dir = { direction } >
75+ < BackgroundIcons dir = { direction } type = { type } >
5576 { Array . from ( { length : totalCount } , ( _ , i ) => (
5677 < IconBar
5778 isAccessible
5879 name = { icon }
5980 key = { `bgstar_${ i } ` }
6081 size = { size }
61- position = { i }
62- color = { ratingBackgroundColor }
82+ position = { isReverse && type !== "custom" ? totalCount - ( i + 1 ) : i }
83+ color = {
84+ isReverse && type !== "custom"
85+ ? ratingColor
86+ : ratingBackgroundColor
87+ }
6388 margin = { marginBetweenRatingIcon }
6489 onIconTap = { onIconTap }
6590 readonly = { readonly }
@@ -69,15 +94,21 @@ const Rating = ({
6994 totalCount = { totalCount }
7095 />
7196 ) ) }
72- < ColoredIcons percentage = { percentage } dir = { direction } >
97+ < ColoredIcons percentage = { percentage } dir = { direction } type = { type } >
7398 { Array . from ( { length : totalCount } , ( _ , i ) => (
7499 < IconBar
75100 filled
76101 name = { icon }
77102 key = { `cstar_${ i } ` }
78103 size = { size }
79- position = { i }
80- color = { ratingColor }
104+ position = {
105+ isReverse && type !== "custom" ? totalCount - ( i + 1 ) : i
106+ }
107+ color = {
108+ isReverse && type !== "custom"
109+ ? ratingBackgroundColor
110+ : ratingColor
111+ }
81112 margin = { marginBetweenRatingIcon }
82113 onIconTap = { onIconTap }
83114 readonly = { readonly }
0 commit comments