diff --git a/example/src/App.tsx b/example/src/App.tsx index 87b5516..79f1064 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -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' @@ -61,6 +62,7 @@ const EXAMPLE_COMPONENTS: ExampleComponentType[] = [ AnimatedHeader, AndroidSharedPullToRefresh, HeaderOverscrollExample, + SingleTab, ] const ExampleList: React.FC = () => { diff --git a/example/src/Shared/ExampleComponentFlashList.tsx b/example/src/Shared/ExampleComponentFlashList.tsx index 2ca75c6..f4fb8c9 100644 --- a/example/src/Shared/ExampleComponentFlashList.tsx +++ b/example/src/Shared/ExampleComponentFlashList.tsx @@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header' type Props = { emptyContacts?: boolean - hideArticleTab?: boolean } & Partial const Example = React.forwardRef( ({ emptyContacts, ...props }, ref) => { return ( - {props.hideArticleTab ? ( - -
- - ) : null} + +
+ diff --git a/example/src/Shared/ExampleComponentMasonryFlashList.tsx b/example/src/Shared/ExampleComponentMasonryFlashList.tsx index e3a00ad..acbfdcc 100644 --- a/example/src/Shared/ExampleComponentMasonryFlashList.tsx +++ b/example/src/Shared/ExampleComponentMasonryFlashList.tsx @@ -13,18 +13,15 @@ import { HEADER_HEIGHT } from './Header' type Props = { emptyContacts?: boolean - hideArticleTab?: boolean } & Partial const Example = React.forwardRef( ({ emptyContacts, ...props }, ref) => { return ( - {props.hideArticleTab ? ( - -
- - ) : null} + +
+ diff --git a/example/src/SingleTab.tsx b/example/src/SingleTab.tsx new file mode 100644 index 0000000..c5d7466 --- /dev/null +++ b/example/src/SingleTab.tsx @@ -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 ( + ( + + )} + > + + + + + + + ) +} + +SingleTabExample.title = title + +export default SingleTabExample + +const styles = StyleSheet.create({ + padding: { paddingHorizontal: 30 }, +}) diff --git a/src/MaterialTabBar/Indicator.tsx b/src/MaterialTabBar/Indicator.tsx index 6f8d718..360694c 100644 --- a/src/MaterialTabBar/Indicator.tsx +++ b/src/MaterialTabBar/Indicator.tsx @@ -19,19 +19,23 @@ const Indicator: React.FC = ({ 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