Skip to content

Commit

Permalink
Merge pull request #395 from Kerumen/fix/indicator-display-for-single…
Browse files Browse the repository at this point in the history
…-tab

fix: indicator display for single tab
  • Loading branch information
andreialecu authored Apr 15, 2024
2 parents e5d3455 + 9c69642 commit a5ca63e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import RevealHeaderOnScroll from './RevealHeaderOnScroll'
import RevealHeaderOnScrollSnap from './RevealHeaderOnScrollSnap'
import ScrollOnHeader from './ScrollOnHeader'
import ScrollableTabs from './ScrollableTabs'
import SingleTab from './SingleTab'
import Snap from './Snap'
import StartOnSpecificTab from './StartOnSpecificTab'
import UndefinedHeaderHeight from './UndefinedHeaderHeight'
Expand Down Expand Up @@ -61,6 +62,7 @@ const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
AnimatedHeader,
AndroidSharedPullToRefresh,
HeaderOverscrollExample,
SingleTab,
]

const ExampleList: React.FC<object> = () => {
Expand Down
9 changes: 3 additions & 6 deletions example/src/Shared/ExampleComponentFlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header'

type Props = {
emptyContacts?: boolean
hideArticleTab?: boolean
} & Partial<CollapsibleProps>

const Example = React.forwardRef<CollapsibleRef, Props>(
({ emptyContacts, ...props }, ref) => {
return (
<Tabs.Container ref={ref} headerHeight={HEADER_HEIGHT} lazy {...props}>
{props.hideArticleTab ? (
<Tabs.Tab name="article" label="Article">
<Article />
</Tabs.Tab>
) : null}
<Tabs.Tab name="article" label="Article">
<Article />
</Tabs.Tab>
<Tabs.Tab name="albums" label="Albums">
<Albums />
</Tabs.Tab>
Expand Down
9 changes: 3 additions & 6 deletions example/src/Shared/ExampleComponentMasonryFlashList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header'

type Props = {
emptyContacts?: boolean
hideArticleTab?: boolean
} & Partial<CollapsibleProps>

const Example = React.forwardRef<CollapsibleRef, Props>(
({ emptyContacts, ...props }, ref) => {
return (
<Tabs.Container ref={ref} headerHeight={HEADER_HEIGHT} lazy {...props}>
{props.hideArticleTab ? (
<Tabs.Tab name="article" label="Article">
<Article />
</Tabs.Tab>
) : null}
<Tabs.Tab name="article" label="Article">
<Article />
</Tabs.Tab>
<Tabs.Tab name="albums" label="Albums">
<Albums />
</Tabs.Tab>
Expand Down
41 changes: 41 additions & 0 deletions example/src/SingleTab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react'
import { StyleSheet } from 'react-native'
import { Tabs, MaterialTabBar } from 'react-native-collapsible-tab-view'

import { ArticleContent } from './Shared/Article'
import { HEADER_HEIGHT, buildHeader } from './Shared/Header'
import { ExampleComponentType } from './types'

const title = 'Single Tab'

const Header = buildHeader(title)

const SingleTabExample: ExampleComponentType = () => {
return (
<Tabs.Container
renderHeader={Header}
headerHeight={HEADER_HEIGHT}
renderTabBar={(props) => (
<MaterialTabBar
{...props}
scrollEnabled
contentContainerStyle={styles.padding}
/>
)}
>
<Tabs.Tab name="article" label="Article">
<Tabs.ScrollView>
<ArticleContent />
</Tabs.ScrollView>
</Tabs.Tab>
</Tabs.Container>
)
}

SingleTabExample.title = title

export default SingleTabExample

const styles = StyleSheet.create({
padding: { paddingHorizontal: 30 },
})
22 changes: 13 additions & 9 deletions src/MaterialTabBar/Indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ const Indicator: React.FC<IndicatorProps> = ({
const opacity = useSharedValue(fadeIn ? 0 : 1)

const stylez = useAnimatedStyle(() => {
const transform =
itemsLayout.length > 1
? [
{
translateX: interpolate(
const firstItemX = itemsLayout[0]?.x ?? 0

const transform = [
{
translateX:
itemsLayout.length > 1
? interpolate(
indexDecimal.value,
itemsLayout.map((_, i) => i),
// when in RTL mode, the X value should be inverted
itemsLayout.map((v) => (isRTL ? -1 * v.x : v.x))
),
},
]
: undefined
)
: isRTL
? -1 * firstItemX
: firstItemX,
},
]

const width =
itemsLayout.length > 1
Expand Down

0 comments on commit a5ca63e

Please sign in to comment.