Skip to content

Commit a5ca63e

Browse files
authored
Merge pull request PedroBern#395 from Kerumen/fix/indicator-display-for-single-tab
fix: indicator display for single tab
2 parents e5d3455 + 9c69642 commit a5ca63e

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

example/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import RevealHeaderOnScroll from './RevealHeaderOnScroll'
3232
import RevealHeaderOnScrollSnap from './RevealHeaderOnScrollSnap'
3333
import ScrollOnHeader from './ScrollOnHeader'
3434
import ScrollableTabs from './ScrollableTabs'
35+
import SingleTab from './SingleTab'
3536
import Snap from './Snap'
3637
import StartOnSpecificTab from './StartOnSpecificTab'
3738
import UndefinedHeaderHeight from './UndefinedHeaderHeight'
@@ -61,6 +62,7 @@ const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
6162
AnimatedHeader,
6263
AndroidSharedPullToRefresh,
6364
HeaderOverscrollExample,
65+
SingleTab,
6466
]
6567

6668
const ExampleList: React.FC<object> = () => {

example/src/Shared/ExampleComponentFlashList.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header'
1313

1414
type Props = {
1515
emptyContacts?: boolean
16-
hideArticleTab?: boolean
1716
} & Partial<CollapsibleProps>
1817

1918
const Example = React.forwardRef<CollapsibleRef, Props>(
2019
({ emptyContacts, ...props }, ref) => {
2120
return (
2221
<Tabs.Container ref={ref} headerHeight={HEADER_HEIGHT} lazy {...props}>
23-
{props.hideArticleTab ? (
24-
<Tabs.Tab name="article" label="Article">
25-
<Article />
26-
</Tabs.Tab>
27-
) : null}
22+
<Tabs.Tab name="article" label="Article">
23+
<Article />
24+
</Tabs.Tab>
2825
<Tabs.Tab name="albums" label="Albums">
2926
<Albums />
3027
</Tabs.Tab>

example/src/Shared/ExampleComponentMasonryFlashList.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header'
1313

1414
type Props = {
1515
emptyContacts?: boolean
16-
hideArticleTab?: boolean
1716
} & Partial<CollapsibleProps>
1817

1918
const Example = React.forwardRef<CollapsibleRef, Props>(
2019
({ emptyContacts, ...props }, ref) => {
2120
return (
2221
<Tabs.Container ref={ref} headerHeight={HEADER_HEIGHT} lazy {...props}>
23-
{props.hideArticleTab ? (
24-
<Tabs.Tab name="article" label="Article">
25-
<Article />
26-
</Tabs.Tab>
27-
) : null}
22+
<Tabs.Tab name="article" label="Article">
23+
<Article />
24+
</Tabs.Tab>
2825
<Tabs.Tab name="albums" label="Albums">
2926
<Albums />
3027
</Tabs.Tab>

example/src/SingleTab.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react'
2+
import { StyleSheet } from 'react-native'
3+
import { Tabs, MaterialTabBar } from 'react-native-collapsible-tab-view'
4+
5+
import { ArticleContent } from './Shared/Article'
6+
import { HEADER_HEIGHT, buildHeader } from './Shared/Header'
7+
import { ExampleComponentType } from './types'
8+
9+
const title = 'Single Tab'
10+
11+
const Header = buildHeader(title)
12+
13+
const SingleTabExample: ExampleComponentType = () => {
14+
return (
15+
<Tabs.Container
16+
renderHeader={Header}
17+
headerHeight={HEADER_HEIGHT}
18+
renderTabBar={(props) => (
19+
<MaterialTabBar
20+
{...props}
21+
scrollEnabled
22+
contentContainerStyle={styles.padding}
23+
/>
24+
)}
25+
>
26+
<Tabs.Tab name="article" label="Article">
27+
<Tabs.ScrollView>
28+
<ArticleContent />
29+
</Tabs.ScrollView>
30+
</Tabs.Tab>
31+
</Tabs.Container>
32+
)
33+
}
34+
35+
SingleTabExample.title = title
36+
37+
export default SingleTabExample
38+
39+
const styles = StyleSheet.create({
40+
padding: { paddingHorizontal: 30 },
41+
})

src/MaterialTabBar/Indicator.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ const Indicator: React.FC<IndicatorProps> = ({
1919
const opacity = useSharedValue(fadeIn ? 0 : 1)
2020

2121
const stylez = useAnimatedStyle(() => {
22-
const transform =
23-
itemsLayout.length > 1
24-
? [
25-
{
26-
translateX: interpolate(
22+
const firstItemX = itemsLayout[0]?.x ?? 0
23+
24+
const transform = [
25+
{
26+
translateX:
27+
itemsLayout.length > 1
28+
? interpolate(
2729
indexDecimal.value,
2830
itemsLayout.map((_, i) => i),
2931
// when in RTL mode, the X value should be inverted
3032
itemsLayout.map((v) => (isRTL ? -1 * v.x : v.x))
31-
),
32-
},
33-
]
34-
: undefined
33+
)
34+
: isRTL
35+
? -1 * firstItemX
36+
: firstItemX,
37+
},
38+
]
3539

3640
const width =
3741
itemsLayout.length > 1

0 commit comments

Comments
 (0)