-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add animation prop to bottom tab (#11323)
**Description** ---- This PR adds properties to `bottom-tabs` navigation `screenOptions` to enable animation (as `animationEnabled`), add custom animations or use presets (as `styleInterpolator`), and also let you set transition config (as `transitionSpec`) hence, providing a medium to animate bottoms-tabs screens. **Video Walkthrough** ---- The tabs as shown in the video currently uses a custom `fade` preset. https://user-images.githubusercontent.com/22779249/234637219-9456967d-55c7-4318-9c7e-41a842747c12.mov **Quality check** ---- The change takes into account lint, typescript and test checks (all passing). --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: osdnk <micosa97@gmail.com>
- Loading branch information
1 parent
ba53154
commit 8d2a6d8
Showing
11 changed files
with
231 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/bottom-tabs/src/TransitionConfigs/SceneStyleInterpolators.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { | ||
BottomTabSceneInterpolatedStyle, | ||
BottomTabSceneInterpolationProps, | ||
} from '../types'; | ||
|
||
/** | ||
* Simple cross fade animation | ||
*/ | ||
export function forCrossFade({ | ||
current, | ||
}: BottomTabSceneInterpolationProps): BottomTabSceneInterpolatedStyle { | ||
return { | ||
sceneStyle: { | ||
opacity: current.interpolate({ | ||
inputRange: [-1, 0, 1], | ||
outputRange: [0, 1, 0], | ||
}), | ||
}, | ||
}; | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/bottom-tabs/src/TransitionConfigs/TransitionPresets.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { BottomTabTransitionPreset } from '../types'; | ||
import { forCrossFade } from './SceneStyleInterpolators'; | ||
import { CrossFadeAnimationSpec } from './TransitionSpecs'; | ||
|
||
export const FadeTransition: BottomTabTransitionPreset = { | ||
animationEnabled: true, | ||
transitionSpec: CrossFadeAnimationSpec, | ||
sceneStyleInterpolator: forCrossFade, | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/bottom-tabs/src/TransitionConfigs/TransitionSpecs.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Easing } from 'react-native'; | ||
|
||
import type { TransitionSpec } from '../types'; | ||
|
||
export const CrossFadeAnimationSpec: TransitionSpec = { | ||
animation: 'timing', | ||
config: { | ||
duration: 1000, | ||
easing: Easing.ease, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type { Route } from '@react-navigation/routers'; | ||
import * as React from 'react'; | ||
import { Animated } from 'react-native'; | ||
|
||
export function useAnimatedHashMap(routes: Route<string>[]) { | ||
const refs = React.useRef<Record<string, Animated.Value>>({}); | ||
const previous = refs.current; | ||
const routeKeys = Object.keys(previous); | ||
if ( | ||
routes.length === routeKeys.length && | ||
routes.every((route) => routeKeys.includes(route.key)) | ||
) { | ||
return previous; | ||
} | ||
refs.current = {}; | ||
|
||
routes.forEach(({ key }) => { | ||
refs.current[key] = previous[key] ?? new Animated.Value(0); | ||
}); | ||
|
||
return refs.current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters