PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How to disable tab switching on tab press?

 November 06, 2022     android, cross-platform, ios, react-native, reactjs     No comments   

Issue

I am using react-native-tab-view for tabs. now i have a very strange use case that i don't want user to traverse to other tabs by clicking on the tab i.e on tab press.

I want to use custom buttons on each tab to traverse back and forth.


Solution

Answering my own question.

For this, there is one prop called onTabPress in TabBar props in react-native-tab-view.

use the following function: preventDefault().

you can do the following to disable tab click.

  • If you want to disable it for particular tab than...
<TabBar onTabPress={({ route, preventDefault }) => {
     // here `route.key` will be your particular tab's route key
     if (route.key === 'home') {
       preventDefault();

      // Do something else
     }   
    }} 
    ... 
    />
  • If you want to disable tab click for all the tabs.

       <TabBar
       {...props}
       onTabPress={({preventDefault}) => {
        preventDefault();
       }}
       />
    

Note: This will work with react navigation as well. Attaching the link: https://reactnavigation.org/docs/navigation-events/



Answered By - Shail Patel
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing