Skip to content

Commit

Permalink
fix: don't render badge on bottom tabs if not visible. closes #8577
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 14, 2020
1 parent cf09f00 commit 2f74541
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions packages/bottom-tabs/src/views/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,33 @@ export default function Badge({
...rest
}: Props) {
const [opacity] = React.useState(() => new Animated.Value(visible ? 1 : 0));
const [rendered, setRendered] = React.useState(visible ? true : false);

const theme = useTheme();

React.useEffect(() => {
if (!rendered) {
return;
}

Animated.timing(opacity, {
toValue: visible ? 1 : 0,
duration: 150,
useNativeDriver: true,
}).start();
}, [opacity, visible]);
}).start(({ finished }) => {
if (finished && !visible) {
setRendered(false);
}
});
}, [opacity, rendered, visible]);

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

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

// @ts-expect-error: backgroundColor definitely exists
const { backgroundColor = theme.colors.notification, ...restStyle } =
Expand All @@ -55,6 +72,14 @@ export default function Badge({
style={[
{
opacity,
transform: [
{
scale: opacity.interpolate({
inputRange: [0, 1],
outputRange: [0.5, 1],
}),
},
],
backgroundColor,
color: textColor,
fontSize,
Expand Down

0 comments on commit 2f74541

Please sign in to comment.