@@ -4,27 +4,45 @@ import IconBar from "./components/IconBar";
4
4
import styled from "styled-components/native" ;
5
5
6
6
const StyledView = styled . View `
7
- display: flex;
8
- align-items: center;
9
- justify-content: center;
10
7
flex-direction: ${ ( { dir } ) => `${ dir } ` } ;
11
8
` ;
12
9
const BackgroundIcons = styled . View `
13
- display: flex;
14
10
position: relative;
15
11
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
+ ` }
16
24
` ;
17
25
const ColoredIcons = styled . View `
18
- display: flex;
19
26
overflow: hidden;
20
27
position: absolute;
21
28
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
+ ` } ;
22
41
width: ${ ( { percentage, dir } ) =>
23
- dir === "column" || dir === "column-reverse" ? `100% ` : `${ percentage } %` } ;
42
+ dir === "column" || dir === "column-reverse" ? `auto ` : `${ percentage } %` } ;
24
43
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;
28
46
bottom: ${ ( { dir } ) => ( dir === "column-reverse" ? 0 : "auto" ) } ;
29
47
` ;
30
48
@@ -43,23 +61,30 @@ const Rating = ({
43
61
selectedIconImage,
44
62
emptyIconImage,
45
63
} ) => {
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
+ }
48
69
return (
49
70
< StyledView
50
71
dir = { direction }
51
72
accessible = { ! readonly }
52
73
importantForAccessibility = { ! readonly ? "yes" : "no" }
53
74
>
54
- < BackgroundIcons dir = { direction } >
75
+ < BackgroundIcons dir = { direction } type = { type } >
55
76
{ Array . from ( { length : totalCount } , ( _ , i ) => (
56
77
< IconBar
57
78
isAccessible
58
79
name = { icon }
59
80
key = { `bgstar_${ i } ` }
60
81
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
+ }
63
88
margin = { marginBetweenRatingIcon }
64
89
onIconTap = { onIconTap }
65
90
readonly = { readonly }
@@ -69,15 +94,21 @@ const Rating = ({
69
94
totalCount = { totalCount }
70
95
/>
71
96
) ) }
72
- < ColoredIcons percentage = { percentage } dir = { direction } >
97
+ < ColoredIcons percentage = { percentage } dir = { direction } type = { type } >
73
98
{ Array . from ( { length : totalCount } , ( _ , i ) => (
74
99
< IconBar
75
100
filled
76
101
name = { icon }
77
102
key = { `cstar_${ i } ` }
78
103
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
+ }
81
112
margin = { marginBetweenRatingIcon }
82
113
onIconTap = { onIconTap }
83
114
readonly = { readonly }
0 commit comments