Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
feat: add support for pager component
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jan 5, 2020
1 parent adbeb29 commit dcc5f99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/material-top-tabs/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ export type MaterialTopTabNavigationConfig = Partial<
| 'onSwipeEnd'
| 'renderScene'
| 'renderTabBar'
| 'renderPager'
| 'renderLazyPlaceholder'
>
> & {
/**
* Function that returns a React element to use as the pager.
* The pager handles swipe gestures and page switching.
*/
pager?: React.ComponentProps<typeof TabView>['renderPager'];
/**
* Function that returns a React element to render for routes that haven't been rendered yet.
* Receives an object containing the route as the prop.
Expand Down
14 changes: 4 additions & 10 deletions packages/material-top-tabs/src/views/MaterialTopTabView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { TabView, SceneRendererProps } from 'react-native-tab-view';
import { Route, useTheme } from '@react-navigation/native';
import { useTheme } from '@react-navigation/native';
import { TabNavigationState, TabActions } from '@react-navigation/routers';

import MaterialTopTabBar from './MaterialTopTabBar';
Expand All @@ -19,6 +19,7 @@ type Props = MaterialTopTabNavigationConfig & {
};

export default function MaterialTopTabView({
pager,
lazyPlaceholder,
tabBar = (props: MaterialTopTabBarProps) => <MaterialTopTabBar {...props} />,
tabBarOptions,
Expand All @@ -30,14 +31,6 @@ export default function MaterialTopTabView({
}: Props) {
const { colors } = useTheme();

const renderLazyPlaceholder = (props: { route: Route<string> }) => {
if (lazyPlaceholder != null) {
return lazyPlaceholder(props);
}

return null;
};

const renderTabBar = (props: SceneRendererProps) => {
const route = state.routes[state.index];
const options = descriptors[route.key].options;
Expand Down Expand Up @@ -69,7 +62,8 @@ export default function MaterialTopTabView({
renderScene={({ route }) => descriptors[route.key].render()}
navigationState={state}
renderTabBar={renderTabBar}
renderLazyPlaceholder={renderLazyPlaceholder}
renderPager={pager}
renderLazyPlaceholder={lazyPlaceholder}
onSwipeStart={() => navigation.emit({ type: 'swipeStart' })}
onSwipeEnd={() => navigation.emit({ type: 'swipeEnd' })}
sceneContainerStyle={[
Expand Down

0 comments on commit dcc5f99

Please sign in to comment.