react-native - 如何在topBar React Native Navigation下添加可点击的rightButtons?

标签 react-native react-native-ios react-native-navigation

我已经集成了 React Native 导航包。我想在我的 topBar rightButton 上添加带有动态值的徽章。
包的 Github 链接:: https://github.com/wix/react-native-navigation

我想要这样的输出。您可以查看此屏幕截图::

enter image description here

问题::

如果我在通知图标上添加计数值,那么当我尝试单击按钮时不会发生任何事件。单击此按钮后,我想打开通知屏幕。

代码:

static options({ menuIcon }) {
        return {
            topBar: {
                title: {
                    fontFamily: font,
                    fontSize: fontSize.heading,
                    color: colors.white,
                    alignment: 'center',
                    text: strings.dashboard
                },
                alignment: 'center',
                elevation: 0,
                noBorder: true,
                background: {
                    color: colors.dark
                },
                leftButtons: [
                    {
                        id: 'openSideMenu',
                        icon: menuIcon ? menuIcon : APIURLServiceSingleton.getInstance()._menuIcon
                    }
                ],
                rightButtons: [
                    {
                        id: 'notificationButton',
                        component: {
                            name: 'component.notificationButton'
                        }
                    }
                ]
            }
        }
    }

我的自定义组件的代码::
<TouchableOpacity
    onPress={() => this.openSystemAlerts()}
    style={{ position: 'absolute', right: 0, bottom: -13 }}
>
    <View style={styles.button}>
        <View style={[posRelative]}>
            <Icon
                name="notifications-none"
                size={27}
                color={colors.white}
            />
            {(unseen_count && unseen_count > 0) &&
                <Text style={styles.badge}>{unseen_count}</Text>
            }
        </View>
    </View>
</TouchableOpacity>

环境
  • react 原生导航版本:2.12.0
  • react native 版本:0.58
  • 平台:仅限 IOS(版本 10.0)
  • 最佳答案

    看来,position:'absolute'正在制造问题,

    任何一个 ,

    添加 zIndex:2 ...这里,数字必须大于任何其他 zIndex在其父级中,或者如果没有任何 zIndex使用然后任何数字> 0 都可以。

    或者

    删除 position:'absolute'并尝试在没有它的情况下进行造型。

    关于react-native - 如何在topBar React Native Navigation下添加可点击的rightButtons?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54919086/

    相关文章:

    react-native - I18Next - 等待使用本地数据设置 Redux 存储

    android - list 合并失败。添加并链接 react-native-device-info 后

    react-native - 未找到 React/RCTBridge.h' 文件?

    javascript - (wix)react-native-navigation 应用程序中的全局状态?

    react-native - react 原生抽屉不会在 map 上滑动时打开

    android - 使用 expo kit 在 React Native 中加载自定义原生组件

    用于图像的 React-Native AsyncStorage

    javascript - 如何在 Alert 函数 [React-Native] 上从 onPress 调用方法

    react-native - React Native CFBundleIdentifier 不存在

    react-native-navigation - 如何在 Android (react-native) 上禁用设备后退按钮?