Skip to content
This repository has been archived by the owner on Feb 25, 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 61fc92a commit 2efe799
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/navigators/createMaterialTopTabNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Config = {
initialLayout?: { width?: number; height?: number };
lazy?: boolean;
lazyPlaceholderComponent?: React.ComponentType<{ route: Route }>;
pagerComponent?: React.ComponentType<
Parameters<React.ComponentProps<typeof TabView>['renderPager']>[0]
>;
tabBarComponent?: React.ComponentType<any>;
tabBarOptions?: MaterialTabBarOptions;
tabBarPosition?: 'top' | 'bottom';
Expand All @@ -42,17 +45,7 @@ type Props = NavigationViewProps &
};

class MaterialTabView extends React.PureComponent<Props> {
_renderLazyPlaceholder = (props: { route: Route }) => {
const { lazyPlaceholderComponent: LazyPlaceholder } = this.props;

if (LazyPlaceholder != null) {
return <LazyPlaceholder {...props} />;
}

return null;
};

_renderTabBar = (props: SceneRendererProps) => {
private renderTabBar = (props: SceneRendererProps) => {
const { state } = this.props.navigation;
const route = state.routes[state.index];
const { descriptors } = this.props;
Expand Down Expand Up @@ -107,10 +100,11 @@ class MaterialTabView extends React.PureComponent<Props> {
onTabPress,
onTabLongPress,
screenProps,
lazyPlaceholderComponent,
tabBarComponent,
tabBarOptions,
/* eslint-enable @typescript-eslint/no-unused-vars */
lazyPlaceholderComponent,
pagerComponent,
navigation,
descriptors,
...rest
Expand All @@ -137,8 +131,17 @@ class MaterialTabView extends React.PureComponent<Props> {
{...rest}
navigationState={navigation.state}
swipeEnabled={swipeEnabled}
renderTabBar={this._renderTabBar}
renderLazyPlaceholder={this._renderLazyPlaceholder}
renderTabBar={this.renderTabBar}
renderLazyPlaceholder={
lazyPlaceholderComponent !== undefined
? props => React.createElement(lazyPlaceholderComponent, props)
: undefined
}
renderPager={
pagerComponent !== undefined
? props => React.createElement(pagerComponent, props)
: undefined
}
/>
);
}
Expand Down

0 comments on commit 2efe799

Please sign in to comment.