Skip to content

Commit

Permalink
chore: extract AnimatedTabBar props to types file
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jul 18, 2020
1 parent 0df4d8d commit 4d38cf8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
52 changes: 18 additions & 34 deletions src/AnimatedTabBar.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
import React, { useMemo, useCallback } from 'react';
import { Insets } from 'react-native';
import { useSafeArea } from 'react-native-safe-area-context';
import { AnimatedTabBarView } from './AnimatedTabBarView';
import { useStableCallback } from './utilities';
import Presets, { PresetEnum } from './presets';
import { TabsConfig, AnimatedTabBarViewProps } from './types';

type AnimatedTabBarProps<T extends PresetEnum> = {
/**
* Tabs configurations.
*/
tabs: TabsConfig<typeof Presets[T]['$t']>;

/**
* React Navigation Props
*/
state?: any;
navigation?: any;
descriptors?: any;
onTabPress?: any;
onTabLongPress?: any;
safeAreaInsets?: Insets;
} & Omit<
AnimatedTabBarViewProps<T>,
'index' | 'tabs' | 'onIndexChange' | 'onLongPress' | 'animatedOnChange'
>;
import { PresetEnum } from './presets';
import { AnimatedTabBarProps } from './types';

interface Route {
name: string;
key: string;
}

export function AnimatedTabBar<T extends PresetEnum>({
tabs,
state,
navigation,
descriptors,
onTabPress,
onTabLongPress,
style: overrideStyle,
safeAreaInsets: overrideSafeAreaInsets,
...rest
}: AnimatedTabBarProps<T>) {
export function AnimatedTabBar<T extends PresetEnum>(
props: AnimatedTabBarProps<T>
) {
// props
const {
tabs,
state,
navigation,
descriptors,
onTabPress,
onTabLongPress,
style: overrideStyle,
safeAreaInsets: overrideSafeAreaInsets,
...rest
} = props;

//#region styles
const { bottom: _safeBottomArea } = useSafeArea();
const safeBottomArea = useMemo(
Expand Down
30 changes: 29 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleProp, ViewStyle } from 'react-native';
import { StyleProp, ViewStyle, Insets } from 'react-native';
import Animated from 'react-native-reanimated';
import Presets, { PresetEnum } from './presets';

Expand Down Expand Up @@ -96,6 +96,34 @@ export interface TabBarItemProps
label: string;
}

export type AnimatedTabBarProps<T extends PresetEnum = 'bubble'> = {
/**
* Animation preset.
*/
preset?: T;

/**
* Tabs configurations.
*/
tabs: TabsConfig<typeof Presets[T]['$t']>;

/**
* Root container style.
*/
style?: StyleProp<ViewStyle>;

/**
* React Navigation Props
*/
state?: any;
navigation?: any;
descriptors?: any;
onTabPress?: any;
onTabLongPress?: any;
safeAreaInsets?: Insets;
} & Omit<TabBarConfigurableProps, 'onLongPress'> &
ExtractPresetConfig<T>;

export type AnimatedTabBarViewProps<T extends PresetEnum> = {
/**
* Initial index.
Expand Down

0 comments on commit 4d38cf8

Please sign in to comment.