Skip to content

Commit cc02400

Browse files
Rishabh Sharma - CONTRACTRishabh Sharma - CONTRACT
authored andcommitted
column reverse bug fixed
1 parent 0a16675 commit cc02400

File tree

4 files changed

+4510
-21
lines changed

4 files changed

+4510
-21
lines changed

.vscode/settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
"activityBarBadge.background": "#310f14",
99
"activityBarBadge.foreground": "#e7e7e7",
1010
"statusBar.background": "#283482",
11-
"statusBar.border": "#283482",
1211
"statusBar.foreground": "#e7e7e7",
1312
"statusBarItem.hoverBackground": "#3444a9",
1413
"titleBar.activeBackground": "#283482",
1514
"titleBar.activeForeground": "#e7e7e7",
16-
"titleBar.border": "#283482",
1715
"titleBar.inactiveBackground": "#28348299",
1816
"titleBar.inactiveForeground": "#e7e7e799"
1917
},

src/Rating/components/IconBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ const IconBar = ({
3535
accessibilityLabel={`Press to rate ${position + 1} out of ${totalCount}`}
3636
accessibilityRole="button"
3737
onPress={() => {
38-
if (!readonly) {
39-
onIconTap && onIconTap(position + 1);
38+
if (!readonly && onIconTap) {
39+
onIconTap(position + 1);
4040
}
4141
}}
4242
>

src/Rating/index.js

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,45 @@ import IconBar from "./components/IconBar";
44
import styled from "styled-components/native";
55

66
const StyledView = styled.View`
7-
display: flex;
8-
align-items: center;
9-
justify-content: center;
107
flex-direction: ${({ dir }) => `${dir}`};
118
`;
129
const 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
`;
1725
const 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

Comments
 (0)