question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Tabs connected to ViewPager

See original GitHub issue

Should be fairly simple to connect the ViewPager to tabs like is done here: https://github.com/madhu314/react-native-tabbed-view-pager-android

The above library is out of date and it uses a broken version of ViewPager. We could offer tabs as optional and nice to have.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Kristonitascommented, Nov 7, 2019

I just found a way to do it out of the box.


const Tabs = () => {
  const [pageIndex, setPageIndex] = useState(0);

  let viewPager;

  const tabsRef = node => {
    if (node !== null) {
      viewPager = node;
    }
  };

  const setPage = (index: number) => {
    setPageIndex(index);
    viewPager && viewPager.setPage(index);
  };

  const onPageSelected = ({ nativeEvent: { position } }: PageSelectedEvent) => {
    setPageIndex(position);
  };

  return (
    <>
      <ViewPager
        initialPage={0}
        ref={tabsRef}
        onPageSelected={onPageSelected}
      >
        <View key="0">
          <Screen text="A" />
        </View>
        <View key="1">
          <Screen text="B" />
        </View>
      </ViewPager>
      <PageButtons currentIndex={pageIndex} setPage={setPage} />
    </>
  );
};

0reactions
troZeecommented, Nov 21, 2022

Closing bc tabview is responsible for adding tabs on top of pager view. More here https://github.com/satya164/react-native-tab-view#readme

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create swipe views with tabs using ViewPager
Create swipe views with tabs using ViewPager ... Swipe views allow you to navigate between sibling screens, such as tabs, with a horizontal...
Read more >
Add tabs to your ViewPager - Create a Flexible and Adaptive ...
Implementing tabs​​ Once the library has been installed we're going to add the view TabLayout (creating our tabs) right above our ViewPager, in ......
Read more >
Android studio: how add tabs with ViewPager - Stack Overflow
Small Code for Tablayout + ViewPager ; // find views by id ViewPager vp= findViewById(R.id.viewpager); TabLayout tl ; = findViewById(R.id.
Read more >
Add Tabs connected to ViewPager · Issue #25 - GitHub
Should be fairly simple to connect the ViewPager to tabs like is done here: ...
Read more >
Android TabLayout and ViewPager - DigitalOcean
Android TabLayout ViewPager Example Code · Import and add the two menu icon drawables · Inflate them in the MainActivity.java in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found