-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement initial animated tab bar
- Loading branch information
Showing
11 changed files
with
506 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
example/ios/AnimatedTabbarExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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,98 @@ | ||
import React, { useCallback, useMemo } from 'react'; | ||
import Animated from 'react-native-reanimated'; | ||
import { useSafeArea } from 'react-native-safe-area-context'; | ||
import { CommonActions } from '@react-navigation/native'; | ||
import { BottomTabBarProps } from '@react-navigation/bottom-tabs'; | ||
import { AnimatedTabBarItem } from './item'; | ||
import { styles } from './styles'; | ||
import { View } from 'react-native'; | ||
|
||
Animated.addWhitelistedNativeProps({ | ||
width: true, | ||
stroke: true, | ||
backgroundColor: true, | ||
}); | ||
|
||
interface AnimatedTabBarProps extends BottomTabBarProps { | ||
configs: any; | ||
} | ||
|
||
export const AnimatedTabBar = (props: AnimatedTabBarProps) => { | ||
// props | ||
const { state, navigation, descriptors, configs } = props; | ||
const { routes } = state; | ||
|
||
// variables | ||
const safeArea = useSafeArea(); | ||
|
||
// styles | ||
const containerStyle = useMemo( | ||
() => [ | ||
styles.container, | ||
{ | ||
paddingBottom: safeArea.bottom, | ||
}, | ||
], | ||
[safeArea] | ||
); | ||
|
||
// callbacks | ||
const handleItemPress = useCallback( | ||
(name, key, focused) => () => { | ||
const event = navigation.emit({ | ||
type: 'tabPress', | ||
target: key, | ||
canPreventDefault: true, | ||
}); | ||
|
||
if (!focused && !event.defaultPrevented) { | ||
navigation.dispatch({ | ||
...CommonActions.navigate(name), | ||
target: state.key, | ||
}); | ||
} | ||
}, | ||
[navigation, state] | ||
); | ||
|
||
const handleItemLongPress = useCallback( | ||
key => () => { | ||
navigation.emit({ | ||
type: 'tabLongPress', | ||
target: key, | ||
}); | ||
}, | ||
[navigation] | ||
); | ||
|
||
// render | ||
return ( | ||
<View style={containerStyle}> | ||
{routes.map((route, index) => { | ||
const focused = index === state.index; | ||
const { options } = descriptors[route.key]; | ||
const tabConfigs = configs[route.name]; | ||
const label = options.title !== undefined ? options.title : route.name; | ||
const accessibilityLabel = | ||
options.tabBarAccessibilityLabel !== undefined | ||
? options.tabBarAccessibilityLabel | ||
: typeof label === 'string' | ||
? `${label}, tab, ${index + 1} of ${routes.length}` | ||
: undefined; | ||
|
||
return ( | ||
<AnimatedTabBarItem | ||
key={route.key} | ||
configs={tabConfigs} | ||
focused={focused} | ||
label={label} | ||
accessibilityLabel={accessibilityLabel} | ||
testID={options.tabBarTestID} | ||
onPress={handleItemPress(route.name, route.key, focused)} | ||
onLongPress={handleItemLongPress(route.key)} | ||
/> | ||
); | ||
})} | ||
</View> | ||
); | ||
}; |
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,4 @@ | ||
import { AnimatedTabBar } from './AnimatedTabBar'; | ||
export { TabConfig } from './types'; | ||
|
||
export default AnimatedTabBar; |
Oops, something went wrong.