Skip to content

Commit

Permalink
feat: user can specify how long tab hide animation should take (#8587)
Browse files Browse the repository at this point in the history
  • Loading branch information
spencercarli committed Jul 28, 2020
1 parent 0b455af commit b0cafb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/bottom-tabs/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ export type BottomTabNavigationOptions = {
*/
tabBarVisible?: boolean;

/**
* Milliseconds that it should take for the animation of a hidden tab bar to become visible.
*/
tabBarShowAnimationDuration?: number;

/**
* Milliseconds that it should take for the animation of a visible tab bar to become hidden.
*/
tabBarHideAnimationDuration?: number;

/**
* Function which returns a React element to render as the tab bar button.
* Renders `TouchableWithoutFeedback` by default.
Expand Down
19 changes: 16 additions & 3 deletions packages/bottom-tabs/src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export default function BottomTabBar({
const shouldShowTabBar =
focusedOptions.tabBarVisible !== false &&
!(keyboardHidesTabBar && isKeyboardShown);
const tabBarShowAnimationDuration =
typeof focusedOptions.tabBarShowAnimationDuration === 'undefined'
? 250
: focusedOptions.tabBarShowAnimationDuration;
const tabBarHideAnimationDuration =
typeof focusedOptions.tabBarHideAnimationDuration === 'undefined'
? 200
: focusedOptions.tabBarHideAnimationDuration;

const [isTabBarHidden, setIsTabBarHidden] = React.useState(!shouldShowTabBar);

Expand All @@ -73,7 +81,7 @@ export default function BottomTabBar({
if (shouldShowTabBar) {
Animated.timing(visible, {
toValue: 1,
duration: 250,
duration: tabBarShowAnimationDuration,
useNativeDriver,
}).start(({ finished }) => {
if (finished) {
Expand All @@ -85,11 +93,16 @@ export default function BottomTabBar({

Animated.timing(visible, {
toValue: 0,
duration: 200,
duration: tabBarHideAnimationDuration,
useNativeDriver,
}).start();
}
}, [shouldShowTabBar, visible]);
}, [
shouldShowTabBar,
visible,
tabBarShowAnimationDuration,
tabBarHideAnimationDuration,
]);

const [layout, setLayout] = React.useState({
height: 0,
Expand Down

0 comments on commit b0cafb3

Please sign in to comment.