Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
264 additions
and
238 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
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,143 @@ | ||
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'; | ||
import { | ||
createBottomTabNavigator, | ||
SceneStyleInterpolator, | ||
TransitionSpecs, | ||
useBottomTabBarHeight, | ||
} from '@react-navigation/bottom-tabs'; | ||
import { HeaderBackButton, useHeaderHeight } from '@react-navigation/elements'; | ||
import { | ||
getFocusedRouteNameFromRoute, | ||
NavigatorScreenParams, | ||
ParamListBase, | ||
useIsFocused, | ||
} from '@react-navigation/native'; | ||
import type { StackScreenProps } from '@react-navigation/stack'; | ||
import { BlurView } from 'expo-blur'; | ||
import * as React from 'react'; | ||
import { ScrollView, StatusBar, StyleSheet } from 'react-native'; | ||
|
||
import { Albums } from '../Shared/Albums'; | ||
import { Chat } from '../Shared/Chat'; | ||
import { Contacts } from '../Shared/Contacts'; | ||
import { SimpleStack, SimpleStackParams } from './SimpleStack'; | ||
|
||
const getTabBarIcon = | ||
(name: React.ComponentProps<typeof MaterialCommunityIcons>['name']) => | ||
({ color, size }: { color: string; size: number }) => | ||
<MaterialCommunityIcons name={name} color={color} size={size} />; | ||
|
||
type BottomTabParams = { | ||
TabStack: NavigatorScreenParams<SimpleStackParams>; | ||
TabAlbums: undefined; | ||
TabContacts: undefined; | ||
TabChat: undefined; | ||
}; | ||
|
||
const AlbumsScreen = () => { | ||
const headerHeight = useHeaderHeight(); | ||
const tabBarHeight = useBottomTabBarHeight(); | ||
const isFocused = useIsFocused(); | ||
|
||
return ( | ||
<> | ||
{isFocused && <StatusBar barStyle="light-content" />} | ||
<ScrollView | ||
contentContainerStyle={{ | ||
paddingTop: headerHeight, | ||
paddingBottom: tabBarHeight, | ||
}} | ||
> | ||
<Albums scrollEnabled={false} /> | ||
</ScrollView> | ||
</> | ||
); | ||
}; | ||
|
||
const Tab = createBottomTabNavigator<BottomTabParams>(); | ||
|
||
export function BottomTabsAnimated({ | ||
navigation, | ||
route, | ||
}: StackScreenProps<ParamListBase, string>) { | ||
const routeName = getFocusedRouteNameFromRoute(route) ?? 'Article'; | ||
|
||
React.useLayoutEffect(() => { | ||
navigation.setOptions({ | ||
headerShown: false, | ||
title: routeName, | ||
}); | ||
}, [navigation, routeName]); | ||
|
||
return ( | ||
<Tab.Navigator | ||
screenOptions={{ | ||
headerLeft: (props) => ( | ||
<HeaderBackButton {...props} onPress={navigation.goBack} /> | ||
), | ||
sceneAnimationOptions: { | ||
animationEnabled: true, | ||
transitionSpec: TransitionSpecs.CrossFadeAnimationSpec, | ||
styleInterpolator: ({ current }) => | ||
SceneStyleInterpolator.forCrossFade({ current }), | ||
}, | ||
}} | ||
> | ||
<Tab.Screen | ||
name="TabStack" | ||
component={SimpleStack} | ||
options={{ | ||
title: 'Article', | ||
tabBarIcon: getTabBarIcon('file-document'), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="TabChat" | ||
component={Chat} | ||
options={{ | ||
tabBarLabel: 'Chat', | ||
tabBarIcon: getTabBarIcon('message-reply'), | ||
tabBarBadge: 2, | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="TabContacts" | ||
component={Contacts} | ||
options={{ | ||
title: 'Contacts', | ||
tabBarIcon: getTabBarIcon('contacts'), | ||
}} | ||
/> | ||
<Tab.Screen | ||
name="TabAlbums" | ||
component={AlbumsScreen} | ||
options={{ | ||
title: 'Albums', | ||
headerTintColor: '#fff', | ||
headerTransparent: true, | ||
headerBackground: () => ( | ||
<BlurView | ||
tint="dark" | ||
intensity={100} | ||
style={StyleSheet.absoluteFill} | ||
/> | ||
), | ||
tabBarIcon: getTabBarIcon('image-album'), | ||
tabBarInactiveTintColor: 'rgba(255, 255, 255, 0.5)', | ||
tabBarActiveTintColor: '#fff', | ||
tabBarStyle: { | ||
position: 'absolute', | ||
borderTopColor: 'rgba(0, 0, 0, .2)', | ||
}, | ||
tabBarBackground: () => ( | ||
<BlurView | ||
tint="dark" | ||
intensity={100} | ||
style={StyleSheet.absoluteFill} | ||
/> | ||
), | ||
}} | ||
/> | ||
</Tab.Navigator> | ||
); | ||
} |
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], | ||
}), | ||
}, | ||
}; | ||
} |
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: 400, | ||
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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
import type { NavigationRoute, ParamListBase } from '@react-navigation/routers'; | ||
import * as React from 'react'; | ||
import { Animated } from 'react-native'; | ||
|
||
export function useAnimatedValueObject( | ||
routes: NavigationRoute<ParamListBase, string>[] | ||
) { | ||
const refs = React.useRef<Record<string, Animated.Value>>({}); | ||
const previous = refs.current; | ||
refs.current = {}; | ||
|
||
routes.forEach(({ key }) => { | ||
refs.current[key] = previous[key] ?? new Animated.Value(0); | ||
}); | ||
|
||
return refs.current; | ||
} |
Oops, something went wrong.