如何在React Native中的工具栏图标中显示通知数

时间:2018-09-10 16:33:23

标签: javascript reactjs react-native mobile react-native-navigation

我想为我的应用程序创建一个本机响应计数。我一直在寻找上周没有任何运气。我想做下面的图片。任何指导或报告将不胜感激。

image

import React, {Component} from 'react';
import {Image, TouchableHighlight, Button, Platform, StyleSheet, Text, View, AppRegistry} from 'react-native';
import {createStackNavigator, createDrawerNavigator} from 'react-navigation';

const StackNav = createStackNavigator(
  {
   Home:{
  screen: HomeScreen,
  navigationOptions: ({navigation}) => ({
    headerRight: (
      <TouchableHighlight onPress={() => navigation.openDrawer()}>
          <Image source=.{require('./images/baseline_menu_black_48dp.png')} style={{height:50, width:50}}/>
      <Badge count={4}/>
      </TouchableHighlight>
    )
  })
},
 const styles = StyleSheet.Create({
circle:{
width:36,
height:36,
borderRadius:18,   //half radius will make it cirlce,
backgroundColor:'red'
},
count:{color:'#FFF'}
})
const Badge = ({count})=>(
<View style ={styles.cirlce}>
<Text style={style.count}>{count}</Text>
</View>
);

1 个答案:

答案 0 :(得分:1)

只需创建一个带有带有文本圆的组件。

const styles = StyleSheet.Create({
  circle:{
   width:36,
   height:36,
   borderRadius:18   //half radius will make it cirlce,
   backgroundColor;'red'
  },
  count:{color:'#FFF'}
})
const Badge = ({count})=>(
  <View style ={styles.cirlce}>
    <Text style={style.count}>{count}</Text>
  </View>
);

现在只需在

之类的地方使用
<Badge count={4}/>