Skip to content

Commit

Permalink
refactor: remove unnecessary conditions in the Badge component (#9412)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislavja committed Feb 1, 2022
1 parent bd7786e commit 9576a69
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/bottom-tabs/src/views/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type Props = {
};

export default function Badge({
visible = true,
size = 18,
children,
style,
visible = true,
size = 18,
...rest
}: Props) {
const [opacity] = React.useState(() => new Animated.Value(visible ? 1 : 0));
const [rendered, setRendered] = React.useState(visible ? true : false);
const [rendered, setRendered] = React.useState(visible);

const theme = useTheme();

Expand All @@ -52,12 +52,12 @@ export default function Badge({
return () => opacity.stopAnimation();
}, [opacity, rendered, visible]);

if (visible && !rendered) {
setRendered(true);
}

if (!visible && !rendered) {
return null;
if (!rendered) {
if (visible) {
setRendered(true);
} else {
return null;
}
}

// @ts-expect-error: backgroundColor definitely exists
Expand All @@ -73,7 +73,6 @@ export default function Badge({
numberOfLines={1}
style={[
{
opacity,
transform: [
{
scale: opacity.interpolate({
Expand All @@ -82,12 +81,13 @@ export default function Badge({
}),
},
],
backgroundColor,
color: textColor,
fontSize,
lineHeight: size - 1,
height: size,
minWidth: size,
opacity,
backgroundColor,
fontSize,
borderRadius,
},
styles.container,
Expand Down

0 comments on commit 9576a69

Please sign in to comment.