首页 > 解决方案 > 如何在底部 tabBar onpress 上添加音效?

问题描述

我正在尝试在底部标签栏导航上添加音效。在按下每个选项卡时,它应该播放声音效果。它在按钮上工作,但在 tabBar 导航上工作。

这是tabBar代码:

const Management = props => (
<Screen>
    <ManagementActivity {...props} />
 </Screen>
)
 const Settings = props => (
 <Screen>
    <SettingsActivity {...props} />
</Screen>
)


   <Tabs.Navigator initialRouteName="Dashboard" floating='true' tabBarOptions={{
            activeTintColor: '#34E5C1',
            inactiveTintColor: "#ffffff00",

            floating: true,
            tabStyle: {
                borderRadius: 20,
                bottom: 20,
                margin: 10,
                backgroundColor: '#000',

            },

        }}

            appearance={{
                dotSize: 'small',
                whenActiveShow: 'icon-only',
                whenInactiveShow: 'icon-only',
                tabStyle: {
                    width: 40,
                    height: 40,
                },
                tabButtonLayout: 'horizontal',
                activeTabBackgrounds: '#272727',
                bottomPadding: -25,
                topPadding: 5,
            }}

        >
            <Tabs.Screen
                name="Dashboard"
                component={Dashboard}
                tabBarOptions={{
                    alignSelf: 'center',
                    justifyContent: 'center',
                    alignItems: 'center'
                }}
                options={{
                    tabBarIcon: ({ focused, color }) => (
                        <HomeSvg fill={color} />
                    ),
                }}
            />
  </Tabs.Navigator >

这是我的音效代码:

     soundEffect = () => {
    playButtonPress();
   }

如何在按下的 tabBar 上添加音效?非常感谢任何帮助...

标签: reactjsreact-nativereact-native-navigationtabbar

解决方案


推荐阅读