Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabBar switching avoid rendering middle tabs #417

Open
kashmiry opened this issue Jun 3, 2024 · 4 comments
Open

TabBar switching avoid rendering middle tabs #417

kashmiry opened this issue Jun 3, 2024 · 4 comments
Labels
question Further information is requested

Comments

@kashmiry
Copy link

kashmiry commented Jun 3, 2024

Hello,
Thank you to everyone contributing to the amazing work on this package.
I am encountering an issue and would appreciate any help or guidance.

Case:
I have three tabs: A, B, C. using lazy to avoid rendering all tabs.

<Tabs.Container lazy ...>
  <Tabs.Tab name="A" label="Tab A">
   <ScreenA />
  </Tabs.Tab>
  <Tabs.Tab name="B" label="Tab B">
   <ScreenB />
  </Tabs.Tab>
    <Tabs.Tab name="C" label="Tab C">
   <ScreenC />
  </Tabs.Tab>
</Tabs.Container>

The issue:
When I press on Tab C from the tab bar, Tab B which is in between the tabs, is also initiated and rendered.
I would like Tab B to render only when I press on it or swipe to it.

Is there a solution or workaround for this behavior?

@kashmiry kashmiry added the question Further information is requested label Jun 3, 2024
@nerodroid
Copy link

@kashmiry have you find any solution ?

@MusabDev
Copy link

MusabDev commented Jul 8, 2024

+1

1 similar comment
@souvenir718
Copy link

+1

@alextbogdanov
Copy link

alextbogdanov commented Sep 5, 2024

Here is my solution:

<Tabs.Container
  renderHeader={() => <Header />}
  renderTabBar={props =>
    <MaterialTabBar
      {...props}
      TabItemComponent={props => 
        <MaterialTabItem
          {...props}
          android_ripple={{ radius: 0 }}
          labelStyle={{ color: COLORS['dark'], fontSize: 16 }}
        >
        </MaterialTabItem>
      }
      indicatorStyle={{ backgroundColor: COLORS['primary'] }}
      contentContainerStyle={{ marginTop: Platform.OS === "android" ? 20 : 0 }}
    />
  }
  headerContainerStyle={{ 
    elevation: 0,
    shadowColor: 'transparent',
    borderBottomWidth: 1,
    borderBottomColor: '#e2e8f0',
  }}
  pagerProps={{ scrollEnabled: false }}
  onIndexChange={(index) => {
    if (Platform.OS === "android") {
      setActiveTab(tabNames[index]);
    }
  }}
>
  <Tabs.Tab name="itinerary" label="Itinerary">
    <Tabs.ScrollView className="bg-background" style={animatedTabViewStyle}>
      {Platform.OS === "android" && activeTab === "itinerary" && <TabView tab="itinerary" />}
      {Platform.OS === "ios" && <TabView tab="itinerary" />}
    </Tabs.ScrollView>
  </Tabs.Tab>
  <Tabs.Tab name="ship" label="Ship">
    <Tabs.ScrollView className="bg-background">
      {Platform.OS === "android" && activeTab === "ship" && <TabView tab="ship" />}
      {Platform.OS === "ios" && <TabView tab="ship" />}
    </Tabs.ScrollView>
  </Tabs.Tab>
  <Tabs.Tab name="people" label="People">
    <Tabs.ScrollView className="bg-background">
      {Platform.OS === "android" &&  activeTab === "people" && (
        <Text>People</Text>
      )}
      {Platform.OS === "ios" && (
        <Text>People</Text>
      )}
    </Tabs.ScrollView>
  </Tabs.Tab>
</Tabs.Container>

Turns out iOS does that automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants