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/tabbed header section list #331

Merged
merged 2 commits into from
Jul 19, 2022
Merged
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
3 changes: 2 additions & 1 deletion docs/docs/headers/avatar-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| tabsContainerBackgroundColor | color - `ColorValue` | - |
| stickyTabs | boolean | true |
| subtitle | string | - |
| subtitleStyle | style - `StyleProp<TextStyle>` | - |
| subtitleTestID | string | - |
| tabsContainerBackgroundColor | color - `ColorValue` | - |
| title | string | - |
| titleStyle | style - `StyleProp<TextStyle>` | - |
| titleTestID | string | - |
1 change: 1 addition & 0 deletions docs/docs/headers/custom-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| onTabsLayout | function - `(e: LayoutChangeEvent) => void` | - |
| renderHeader | render function | - |
| renderTabs | render function | - |
| stickyTabs | boolean | true |
1 change: 1 addition & 0 deletions docs/docs/headers/details-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| subtitle | string | - |
| subtitleStyle | style - `StyleProp<TextStyle>` | - |
| subtitleTestID | string | - |
Expand Down
1 change: 1 addition & 0 deletions docs/docs/headers/tabbed-header-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| tabTextActiveStyle | style - `StyleProp<TextStyle>` | - |
| tabTextContainerStyle | style - `StyleProp<ViewStyle>` | - |
| tabTextContainerActiveStyle | style - `StyleProp<ViewStyle>` | - |
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/headers/tabbed-header-pager.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| backgroundColor | color - `ColorValue` | - |
| backgroundImage | image source - `ImageSourcePropType` | - |
| containerStyle | style - `StyleProp<ViewStyle>` | - |
| disableScrollToPosition | boolean | - |
| foregroundImage | image source - `ImageSourcePropType` | - |
| hasBorderRadius | boolean | - |
| headerHeight | number | 100 |
Expand All @@ -47,7 +48,6 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| logoContainerStyle | style - `StyleProp<ViewStyle>` | - |
| logoResizeMode | image resize mode - `ImageResizeMode` | - |
| logoStyle | style - `StyleProp<ImageStyle>` | - |
| offscreenPageLimit | number | 1 |
| onChangeTab | function - `(prevPage: number, newPage: number) => void` | - |
| onHeaderLayout | function - `(e: LayoutChangeEvent) => void` | - |
| onMomentumScrollBegin | worklet function - `(e: NativeScrollEvent) => void` | - |
Expand All @@ -65,6 +65,7 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| tabTextActiveStyle | style - `StyleProp<TextStyle>` | - |
| tabTextContainerStyle | style - `StyleProp<ViewStyle>` | - |
| tabTextContainerActiveStyle | style - `StyleProp<ViewStyle>` | - |
Expand Down
5 changes: 4 additions & 1 deletion docs/versioned_docs/version-1.0.x/headers/avatar-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| tabsContainerBackgroundColor | color - `ColorValue` | - |
| stickyTabs | boolean | true |
| subtitle | string | - |
| subtitleStyle | style - `StyleProp<TextStyle>` | - |
| subtitleTestID | string | - |
| tabsContainerBackgroundColor | color - `ColorValue` | - |
| title | string | - |
| titleStyle | style - `StyleProp<TextStyle>` | - |
| titleTestID | string | - |
1 change: 1 addition & 0 deletions docs/versioned_docs/version-1.0.x/headers/custom-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| onTabsLayout | function - `(e: LayoutChangeEvent) => void` | - |
| renderHeader | render function | - |
| renderTabs | render function | - |
| stickyTabs | boolean | true |
7 changes: 7 additions & 0 deletions docs/versioned_docs/version-1.0.x/headers/details-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| contentIcon | image source - `ImageSourcePropType` | - |
| contentIconNumber | number | - |
| contentIconNumberStyle | style - `StyleProp<TextStyle>` | - |
| contentIconNumberTestID | string | - |
| leftTopIcon | render function or image source | - |
| leftTopIconAccessibilityLabel | string | - |
| leftTopIconOnPress | function - `() => void` | - |
Expand All @@ -98,8 +99,14 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| subtitle | string | - |
| subtitleStyle | style - `StyleProp<TextStyle>` | - |
| subtitleTestID | string | - |
| tabsContainerBackgroundColor | color - `ColorValue` | - |
| tag | string | - |
| tagStyle | style - `StyleProp<TextStyle>` | - |
| tagTestID | string | - |
| title | string | - |
| titleStyle | style - `StyleProp<TextStyle>` | - |
| titleTestID | string | - |
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| tabTextActiveStyle | style - `StyleProp<TextStyle>` | - |
| tabTextContainerStyle | style - `StyleProp<ViewStyle>` | - |
| tabTextContainerActiveStyle | style - `StyleProp<ViewStyle>` | - |
Expand All @@ -78,6 +79,7 @@ Inherits [SectionListProps](https://reactnative.dev/docs/next/sectionlist#props)
| tabsContainerStyle | style - `StyleProp<ViewStyle>` | - |
| title | string | - |
| titleStyle | style = `StyleProp<TextStyle>` | - |
| titleTestID | string | - |

### Tab

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| backgroundColor | color - `ColorValue` | - |
| backgroundImage | image source - `ImageSourcePropType` | - |
| containerStyle | style - `StyleProp<ViewStyle>` | - |
| disableScrollToPosition | boolean | - |
| foregroundImage | image source - `ImageSourcePropType` | - |
| hasBorderRadius | boolean | - |
| headerHeight | number | 100 |
Expand All @@ -45,7 +46,6 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| logoContainerStyle | style - `StyleProp<ViewStyle>` | - |
| logoResizeMode | image resize mode - `ImageResizeMode` | - |
| logoStyle | style - `StyleProp<ImageStyle>` | - |
| offscreenPageLimit | number | 1 |
| onChangeTab | function - `(prevPage: number, newPage: number) => void` | - |
| onHeaderLayout | function - `(e: LayoutChangeEvent) => void` | - |
| onMomentumScrollBegin | worklet function - `(e: NativeScrollEvent) => void` | - |
Expand All @@ -63,6 +63,7 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| snapStartThreshold | number | - |
| snapStopThreshold | number | - |
| snapToEdge | boolean | true |
| stickyTabs | boolean | true |
| tabTextActiveStyle | style - `StyleProp<TextStyle>` | - |
| tabTextContainerStyle | style - `StyleProp<ViewStyle>` | - |
| tabTextContainerActiveStyle | style - `StyleProp<ViewStyle>` | - |
Expand All @@ -75,6 +76,7 @@ Inherits [ScrollViewProps](https://reactnative.dev/docs/next/scrollview#props)
| tabsContainerStyle | style - `StyleProp<ViewStyle>` | - |
| title | string | - |
| titleStyle | style = `StyleProp<TextStyle>` | - |
| titleTestID | string | - |

### Tab

Expand Down
5 changes: 5 additions & 0 deletions example/src/navigation/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
TabbedHeaderListExample,
TabbedHeaderPagerExample,
} from '../screens/additionalExamples';
import { TabbedHeaderWithSectionListsExample } from '../screens/additionalExamples/TabbedHeaderWithSectionLists';

import { ROUTES } from './routes';
import type { RootStackParamList } from './types';
Expand Down Expand Up @@ -61,6 +62,10 @@ const AppNavigator: React.FC = () => (
name={ROUTES.DETAILS_HEADER_SECTIONLIST}
component={DetailsHeaderSectionListExample}
/>
<Stack.Screen
name={ROUTES.TABBED_HEADER_WITH_SECTION_LISTS}
component={TabbedHeaderWithSectionListsExample}
/>
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
1 change: 1 addition & 0 deletions example/src/navigation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export const ROUTES = {
DETAILS_HEADER_FLATLIST: 'DetailsHeaderFlatList' as const,
DETAILS_HEADER_SCROLLVIEW: 'DetailsHeaderScrollView' as const,
DETAILS_HEADER_SECTIONLIST: 'DetailsHeaderSectionList' as const,
TABBED_HEADER_WITH_SECTION_LISTS: 'TabbedHeaderWithSectionLists' as const,
};
1 change: 1 addition & 0 deletions example/src/navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type RootStackParamList = {
[ROUTES.DETAILS_HEADER_FLATLIST]: undefined;
[ROUTES.DETAILS_HEADER_SCROLLVIEW]: undefined;
[ROUTES.DETAILS_HEADER_SECTIONLIST]: undefined;
[ROUTES.TABBED_HEADER_WITH_SECTION_LISTS]: undefined;
};

export type RootStackNavigationProp = StackNavigationProp<RootStackParamList>;
Expand Down
5 changes: 5 additions & 0 deletions example/src/screens/HomeScreen/ExampleLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export const EXAMPLES: Array<ExampleLinkProps> = [
label: 'Card Screen (SectionList)',
testID: homeScreenTestIDs.detailsHeaderSectionListLink,
},
{
routeName: ROUTES.TABBED_HEADER_WITH_SECTION_LISTS,
label: 'Tabbed Header with SectionList tabs',
testID: homeScreenTestIDs.tabbedHeaderWithSectionLists,
},
];

export const ExampleLink: VFC<ExampleLinkProps> = ({ routeName, label, testID }) => {
Expand Down
1 change: 0 additions & 1 deletion example/src/screens/HomeScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ const HomeScreen: VFC = () => {
title={"Mornin' Mark! \nReady for a quiz?"}
titleStyle={screenStyles.text}
titleTestID={homeScreenTestIDs.headerTitle}
offscreenPageLimit={5}
foregroundImage={photosPortraitMe}
tabs={TABS.map((tab) => ({ title: tab.title, testID: tab.testID }))}
tabTextStyle={screenStyles.text}
Expand Down
1 change: 1 addition & 0 deletions example/src/screens/HomeScreen/testIDs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const homeScreenTestIDs = Object.freeze({
detailsHeaderFlatListLink: 'DetailsHeaderFlatListLinkTestID',
detailsHeaderScrollViewLink: 'DetailsHeaderScrollViewLinkTestID',
detailsHeaderSectionListLink: 'DetailsHeaderSectionListLinkTestID',
tabbedHeaderWithSectionLists: 'TabbedHeaderWithSectionListsTestID',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import type { FC } from 'react';
import React from 'react';
import type { SectionListData } from 'react-native';
import { SectionList, StatusBar, StyleSheet, View, useColorScheme } from 'react-native';
import { TabbedHeaderPager } from 'react-native-sticky-parallax-header';

import type { Question } from '../../assets/data/cards';
import { Brandon, Ewa, Jennifer } from '../../assets/data/cards';
import { logo, photosPortraitMe } from '../../assets/images';
import { QuizCard } from '../../components';
import { TabbedSectionHeader } from '../../components/predefinedComponents/TabbedSectionHeader';
import { colors, screenStyles } from '../../constants';

import { tabbedHeaderTestIDs } from './testIDs';

const QUIZ_SECTIONS: SectionListData<Question>[] = [
{
data: Brandon.cards,
key: Brandon.author,
},
{
data: Ewa.cards,
key: Ewa.author,
},
{
data: Jennifer.cards,
key: Jennifer.author,
},
];

const QUIZ_TAB_SECTIONS = [
{
title: Brandon.author,
testID: Brandon.author + 'QuizTestID',
},
{
title: Ewa.author,
testID: Ewa.author + 'QuizTestID',
},
{
title: Jennifer.author,
testID: Jennifer.author + 'QuizTestID',
},
];

const List: FC<{ startIndex: number }> = ({ startIndex }) => {
return (
<SectionList
sections={QUIZ_SECTIONS.slice(startIndex).concat(QUIZ_SECTIONS.slice(0, startIndex))}
stickySectionHeadersEnabled
renderItem={({ item, index, section }) => {
return <QuizCard data={item} num={index} cardsAmount={section.data.length} />;
}}
renderSectionHeader={({ section }) => {
return <TabbedSectionHeader tabTestID={section.key ?? ''} title={section.key ?? ''} />;
}}
/>
);
};

export const TabbedHeaderWithSectionListsExample: FC = () => {
const isDarkTheme = useColorScheme() === 'dark';

return (
<>
<TabbedHeaderPager
contentContainerStyle={[
isDarkTheme ? screenStyles.darkBackground : screenStyles.lightBackground,
]}
backgroundColor={colors.primaryGreen}
containerStyle={screenStyles.stretchContainer}
foregroundImage={photosPortraitMe}
disableScrollToPosition={true}
rememberTabScrollPosition={false}
logo={logo}
title={"Mornin' Mark! \nReady for a quiz?"}
titleStyle={screenStyles.text}
titleTestID={tabbedHeaderTestIDs.title}
stickyTabs={false}
tabs={QUIZ_TAB_SECTIONS.map((section) => ({
title: section.title,
testID: section.testID,
}))}
tabTextStyle={screenStyles.text}
showsVerticalScrollIndicator={false}>
<View style={styles.content}>
<List startIndex={0} />
</View>
<View style={styles.content}>
<List startIndex={1} />
</View>
<View style={styles.content}>
<List startIndex={2} />
</View>
</TabbedHeaderPager>
<StatusBar barStyle="light-content" backgroundColor={colors.primaryGreen} translucent />
</>
);
};

const styles = StyleSheet.create({
content: {
alignItems: 'center',
alignSelf: 'stretch',
flex: 1,
paddingHorizontal: 24,
},
});
4 changes: 2 additions & 2 deletions src/predefinedComponents/TabbedHeader/TabbedHeaderPager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export const TabbedHeaderPager = forwardRef<ScrollView, TabbedHeaderPagerProps>(
backgroundColor,
children,
contentContainerStyle,
disableScrollToPosition,
decelerationRate = 'fast',
initialPage,
logo,
logoContainerStyle,
logoResizeMode,
logoStyle,
nestedScrollEnabled = true,
offscreenPageLimit,
onChangeTab,
overScrollMode = 'never',
pagerProps,
Expand Down Expand Up @@ -79,9 +79,9 @@ export const TabbedHeaderPager = forwardRef<ScrollView, TabbedHeaderPagerProps>(
scrollEventThrottle={scrollEventThrottle}>
<Pager
{...pagerProps}
disableScrollToPosition={disableScrollToPosition}
initialPage={initialPage}
minScrollHeight={innerScrollHeight}
offscreenPageLimit={offscreenPageLimit}
onChangeTab={(prevPage, newPage) => {
setCurrentPage(newPage);
onChangeTab?.(prevPage, newPage);
Expand Down
10 changes: 2 additions & 8 deletions src/predefinedComponents/TabbedHeader/TabbedHeaderProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export interface PagerMethods {

/** TODO: do not export it when exporting module's components and types */
export interface InternalPagerProps {
disableScrollToPosition?: boolean;
initialPage?: number;
minScrollHeight: number;
offscreenPageLimit?: number;
onChangeTab?: (previousPage: number, newPage: number) => void;
page: number;
pageContainerStyle?: StyleProp<ViewStyle>;
Expand Down Expand Up @@ -77,14 +77,8 @@ export interface TabbedHeaderSharedProps extends SharedPredefinedProps, Partial<
export interface TabbedHeaderPagerProps
extends TabbedHeaderSharedProps,
StickyHeaderScrollViewProps {
disableScrollToPosition?: boolean;
initialPage?: number;
/**
* Set the number of pages that should be retained to either side of the currently visible page(s).
* Pages beyond this limit will be recreated when needed.
* Defaults to 1.
* The given value must be larger than 0.
*/
offscreenPageLimit?: number;
onChangeTab?: (prevPage: number, newPage: number) => void;
pageContainerStyle?: StyleProp<ViewStyle>;
pagerProps?: PagerProps & RefAttributes<PagerMethods>;
Expand Down
3 changes: 2 additions & 1 deletion src/predefinedComponents/TabbedHeader/components/Pager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const Pager = forwardRef<PagerMethods, PagerProps & InternalPagerProps>(
contentContainerStyle,
contentOffset: _contentOffset,
directionalLockEnabled = true,
disableScrollToPosition,
initialPage = 0,
keyboardDismissMode = 'on-drag',
minScrollHeight,
Expand Down Expand Up @@ -169,7 +170,7 @@ export const Pager = forwardRef<PagerMethods, PagerProps & InternalPagerProps>(
}

function handleScrollToTabPosition(prevPage: number, newPage: number) {
if (!data.length || scrollValue.value === 0) {
if (!data.length || scrollValue.value === 0 || disableScrollToPosition) {
return;
}

Expand Down
Loading