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

feat(Container.tsx, types.ts): add support for custom background component. #340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [Tabs.Container](#tabscontainer)
- [Tabs.Lazy](#tabslazy)
- [Tabs.FlatList](#tabsflatlist)
- [Tabs.FlashList](#tabsflashlist)
- [Tabs.FlashList](#tabsflatlist)
- [Tabs.SectionList](#tabssectionlist)
- [Tabs.ScrollView](#tabsscrollview)
- [Ref](#ref)
Expand Down Expand Up @@ -194,6 +194,7 @@ const Example = () => {
|`onIndexChange`|`((index: number) => void) \| undefined`||Callback fired when the index changes. It receives the current index.|
|`onTabChange`|`(data: { prevIndex: number index: number prevTabName: T tabName: T }) => void`||Callback fired when the tab changes. It receives the previous and current index and tabnames.|
|`pagerProps`|`Omit<FlatListProps<number>, 'data' \| 'keyExtractor' \| 'renderItem' \| 'horizontal' \| 'pagingEnabled' \| 'onScroll' \| 'showsHorizontalScrollIndicator' \| 'getItemLayout'>`||Props passed to the pager. If you want for example to disable swiping, you can pass `{ scrollEnabled: false }`|
|`renderBackground`|`((props: TabBarProps<string>) => ReactElement<any, string \| ((props: any) => ReactElement<any, any> \| null) \| (new (props: any) => Component<any, any, any>)> \| null) \| undefined`|||
|`renderHeader`|`(props: TabBarProps<TabName>) => React.ReactElement \| null`|||
|`renderTabBar`|`(props: TabBarProps<TabName>) => React.ReactElement \| null`|`(props: TabBarProps<TabName>) => MaterialTabBar`||
|`revealHeaderOnScroll`|`boolean \| undefined`||Reveal header when scrolling down. Implements diffClamp.|
Expand Down Expand Up @@ -229,19 +230,16 @@ Typically used internally, but if you want to mix lazy and regular screens you c

#### Props

|name|type|
|:----:|:----:|
|`cancelLazyFadeIn`|`boolean \| undefined`|
|`startMounted`|`boolean \| undefined`|
|name|type|default|description|
|:----:|:----:|:----:|:----:|
|`cancelLazyFadeIn`|`boolean \| undefined`||Whether to cancel the lazy fade in animation. Defaults to false.|
|`mountDelayMs`|`number \| undefined`|`50`|How long to wait before mounting the children.|
|`startMounted`|`boolean \| undefined`||Whether to start mounted. Defaults to true if we are the focused tab.|

### Tabs.FlatList

Use like a regular FlatList.

### Tabs.FlashList

Use like a regular FlashList.

### Tabs.ScrollView

Use like a regular ScrollView.
Expand Down
11 changes: 11 additions & 0 deletions src/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const Container = React.memo(
onTabChange,
width: customWidth,
allowHeaderOverscroll,
renderBackground,
},
ref
) => {
Expand Down Expand Up @@ -381,6 +382,16 @@ export const Container = React.memo(
onLayout={onLayout}
pointerEvents="box-none"
>
{renderBackground &&
renderBackground({
containerRef,
index,
tabNames: tabNamesArray,
focusedTab,
indexDecimal,
onTabPress,
tabProps,
})}
<Animated.View
pointerEvents="box-none"
style={[
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export type CollapsibleProps = {

renderTabBar?: (props: TabBarProps<TabName>) => React.ReactElement | null

renderBackground?: (props: TabBarProps<TabName>) => React.ReactElement | null

headerContainerStyle?: StyleProp<Animated.AnimateStyle<ViewStyle>>
containerStyle?: StyleProp<ViewStyle>
cancelTranslation?: boolean
Expand Down