PedroBern / react-native-collapsible-tab-view

A cross-platform Collapsible Tab View component for React Native
MIT License
827 stars 160 forks source link

fix: indicator display for single tab #395

Closed Kerumen closed 2 months ago

Kerumen commented 2 months ago

In my app I added some container style with padding to have a specific display for the tabs. When there is only one tab, the indicator is not shifted accordingly. This is due to the itemsLayout.length > 1 condition and the undefined value of transform. The same way as it's done for the width, I changed the transform to match the first item of the itemsLayout array if there is only one tab.

Before After
andreialecu commented 2 months ago

@Kerumen how did you add the padding style to see this issue?

I'm getting the following result without the need for this PR:

simulator_screenshot_7B1EBD32-E6CE-4AE3-B8BD-F288234A4E48

With this setup:

    <Tabs.Container
      renderHeader={Header}
      headerHeight={HEADER_HEIGHT}
      renderTabBar={(props) => (
        <MaterialTabBar
          {...props}
          scrollEnabled
          style={{ paddingHorizontal: 30 }}
        />
      )}
    >
      <Tabs.Tab name="article" label="Article">
        <Tabs.ScrollView>
          <ArticleContent />
        </Tabs.ScrollView>
      </Tabs.Tab>
    </Tabs.Container>
Kerumen commented 2 months ago

If you have a lot of tabs, the last tab is cropped one when you put the paddingHorizontal as style on the MaterialTabBar. To fix it, I've used contentContainerStyle and it works fine but then there is the indicator issue when there is only one tab.

Screenshot 2024-04-15 at 10 49 08

andreialecu commented 2 months ago

Merged. Thank you for the PR!