Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge content on top of avatars / images #85

Open
madhenry opened this issue Mar 9, 2021 · 1 comment
Open

Badge content on top of avatars / images #85

madhenry opened this issue Mar 9, 2021 · 1 comment

Comments

@madhenry
Copy link

madhenry commented Mar 9, 2021

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-magnus@1.0.62 for the project I'm working on.

With this change I am able to use the (unused?) count prop to set the avatar badge contents when the avatar is a child of Badge. Was it meant for exactly this usecase?

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-magnus/src/ui/badge/badge.component.tsx b/node_modules/react-native-magnus/src/ui/badge/badge.component.tsx
index c8d099f..e8a7a92 100644
--- a/node_modules/react-native-magnus/src/ui/badge/badge.component.tsx
+++ b/node_modules/react-native-magnus/src/ui/badge/badge.component.tsx
@@ -73,6 +73,7 @@ const Badge: React.FunctionComponent<BadgeProps> = (incomingProps) => {
   } = props;
   const { theme } = useTheme();
   const computedStyle = getStyle(theme, props);
+  const badgeContent = count || children
 
   return (
     <RNView style={computedStyle.container}>
@@ -80,12 +81,12 @@ const Badge: React.FunctionComponent<BadgeProps> = (incomingProps) => {
         {typeof children !== 'string' && children}
 
         <RNView style={computedStyle.div} {...rest}>
-          {typeof children === 'string' && (
+          {(typeof badgeContent === 'string' || typeof badgeContent == 'number') && (
             <Text
               {...getSpecificProps(props, ...textProps)}
               style={computedStyle.text}
             >
-              {children}
+              {badgeContent}
             </Text>
           )}
         </RNView>

This issue body was partially generated by patch-package.

<Badge count={2}>
   <Avatar source={{ uri: item.avatar }}>
      Avatar Initials
   </Avatar>
</Badge>

Screenshot 2021-03-09 at 17 56 20

@jsartisan
Copy link
Owner

Hey nice patch. Possible to submit a PR for the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants