Giter Site home page Giter Site logo

react-native-icon-badge's Introduction

react-native-icon-badge

npm

Icon badge is used to create icon badge on some element, such as avatar, icon, image.... The badge is used to give some alert to user of specific element.

For example: demo

How to use

Install package:

npm install --save react-native-icon-badge

Import to your app:

...
import IconBadge from 'react-native-icon-badge';
...

Use the component:

<View style={{flexDirection: 'row',alignItems: 'center',justifyContent: 'center',}}>
  <IconBadge
    MainElement={
      <View style={{backgroundColor:'#489EFE',
        width:50,
        height:50,
        margin:6
      }}/>
    }
    BadgeElement={
      <Text style={{color:'#FFFFFF'}}>{this.state.BadgeCount}</Text>
    }
    IconBadgeStyle={
      {width:30,
      height:30,
      backgroundColor: '#FF00EE'}
    }
    Hidden={this.state.BadgeCount==0}
    />
</View>

API

API table

API name Usage
MainElement The background element.
BadgeElement The badge element, normally it is a Text.
IconBadgeStyle Customized badge style.(Optional)
Hidden Hides badge.(Optional)

Default badge style

IconBadge: {
  position:'absolute',
  top:1,
  right:1,
  minWidth:20,
  height:20,
  borderRadius:15,
  alignItems: 'center',
  justifyContent: 'center',
  backgroundColor: '#FF0000'
}

react-native-icon-badge's People

Contributors

aaronvasquez avatar beausmith avatar janhesters avatar muhaimincs avatar shuchenliu avatar suniahk avatar yanqiw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-icon-badge's Issues

How to add marginLeft in IconBadgeStyle.

I want add marginLeft in IconBadge Here is my code:
<IconBadge MainElement={ <View style={{ backgroundColor: '#489EFE', width: 50, height: 50, margin: 6, }} /> } BadgeElement={ <Text style={{ color: '#FFFFFF' }}>3</Text> } IconBadgeStyle={ { width: 30, height: 30, backgroundColor: '#FF00EE', # marginLeft:100 } } />
But iconBadge not change:
screen shot 2018-01-22 at 10 10 59 am

Seem my issue just appear which marginLeft because I try change 'marginLeft' to marginRight it work well.
screen shot 2018-01-22 at 10 09 39 am
Pls help me
P/s I want my MainElement not moving and iconBadge moving.

How to add Padding

Hello, I placed my object on a tab, but the badge is not positioned correctly, it need more padding bottom and left. Where should I place these styles? I tried on MainView, IconBadge and IconBadgeElement, but they are not affecting it correctly.

Please let me know how to fix this! thanks

Round edges blurry or overgrowing?

Hi, my badges are not very clean. When rendered, they seem blurry. (React Native 0.55.4)

Style:

badgeIcon: {
  alignItems: 'center',
  backgroundColor: colors.black,
  borderColor: colors.red,
  borderRadius: 50,
  borderWidth: 1.5,
  height: 20,
  justifyContent: 'center',
  minWidth: 20,
  position: 'absolute',
  right: -12,
  top: -5
}

Results:
bildschirmfoto 2019-02-14 um 18 40 00

bildschirmfoto 2019-02-14 um 18 49 54

bildschirmfoto 2019-02-14 um 18 50 42

No matter the colors, the border width or border radius, the color pierces the edges.
Is there a way to avoid this?

Comparable styling in the web is rendered like this:
bildschirmfoto 2019-02-14 um 19 05 56

Cannot modify width to be smaller than default width

<IconBadge MainElement={<Image source={require('path/to/image.png'} />} IconBadgeStyle={{ width:10, height:10, borderRadius:5, }} />

In this example, the height of the badge changes but the width does not.

I think that this is because the source code is using minWidth instead of width.

Badge is not displayed in Android.

Hi, I am running sample app. I am using this module it's working fine.
In iOS badge is displayed like below image.
screen shot 2018-03-08 at 12 32 32 pm
In Android badge is not displayed. Here is the image for android.
screen shot 2018-03-08 at 12 34 07 pm
here is my code:

<View style={styles.numberWrap}>
       <IconBadge
         IconBadgeStyle={{
           width: 25,
           height: 25,
           backgroundColor: Color.error
         }}
         BadgeElement={<Text style={{ color: '#FFFFFF' }}>{number}</Text>}
         Hidden={number == 0}
       />
     </View>
const styles = StyleSheet.create({
numberWrap: {
   position: 'absolute',
   top: -15,
   right: -10,
   backgroundColor: 'white',
   borderRadius: 10
 },
})

Please give me any suggestion. Thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.