简体   繁体   English

如何在React Native中将底部栏标签视为按钮?

[英]How to treat a bottom bar tab as a button in React Native?

So I have a bottom navigation bar with three tabs: HomeView, UploadVideo and Messages. 因此,我有一个带有三个选项卡的底部导航栏:HomeView,UploadVideo和Messages。 Basically, what I would like to do is when the user clicks on the UploadVideo tab, it will behave kind of the way Instagram does it. 基本上,我想做的是当用户单击“ UploadVideo”选项卡时,它的行为将类似于Instagram的行为。 Where it will open up the image library, and allow the to select a media item and moves them to a screen where they can enter in their details. 它将在其中打开图像库,并允许选择一个媒体项目并将其移动到屏幕上,以便在其中输入详细信息。 And if the user goes through the upload process entirely or cancels it will take them back to the page they were originally on before clicking the Upload tab/button. 而且,如果用户完全执行了上传过程或取消了上传过程,它将带他们回到原来的页面,然后单击“上传”选项卡/按钮。

Currently, what I have is when the User clicks Upload Video it will open up a screen with the tab bar hidden with an icon to open the Image library and a form to enter in the video data. 目前,我所拥有的是,当用户单击“上载视频”时,它将打开一个屏幕,其中标签栏隐藏着一个图标,用于打开图像库和用于输入视频数据的表单。 If the user clicks cancel it will take them back to the HomeView (programmed this way) regardless of where they were when they click on the UploadVideo tab. 如果用户单击“取消”,则无论单击“ UploadVideo”选项卡时位于何处,都将带他们回到HomeView(以这种方式编程)。 So basically I guess to summarize my question, how can I get a tab to act more as a button? 因此,基本上我想总结一下我的问题,我如何才能获得一个标签,使其更多地充当按钮?

You could immediately open a picker when the tab is rendered and navigate away once a video has been selected, something like this: 您可以在呈现标签后立即打开选择器,并在选择视频后立即离开浏览器,如下所示:

class HomeTab extends React.Component {
    render() {
        return (
            <View/>
        );
    }
}

class GalleryTab extends React.Component {
    async componentDidMount() {
        const {cancelled} = await ImagePicker.launchImageLibraryAsync(options);

        if(cancelled){
            navigation.goBack()
        }

        navigation.navigate('detailScreen')
    }

    render() {
        return (
            <View/>
        );
    }
}

const TabNavigator = createBottomTabNavigator({
    Home: HomeTab,
    Gallery: GalleryTab,
});

export default createAppContainer(TabNavigator);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM