【问题标题】:How to display count of notifications in toolbar icon in react native如何在反应原生的工具栏图标中显示通知计数
【发布时间】:2018-09-10 16:33:22
【问题描述】:

我想为我的应用创建一个反应原生徽章计数。上周我一直在寻找没有任何运气。我想做类似下图的事情。任何指导或报告将不胜感激。

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>
);

【问题讨论】:

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


    【解决方案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}/>
    

    【讨论】:

    • 添加你取得的成就的截图
    • 你好,如果我从像 firebase 这样的服务器收到通知,我该如何处理?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 2016-04-10
    • 1970-01-01
    相关资源
    最近更新 更多