Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A 60FPS animated tab bar with a variety of cool animation presets 😎

License

NotificationsYou must be signed in to change notification settings

gorhom/react-native-animated-tabbar

Repository files navigation

npmnpmnpm

A60FPS animated tab bar with a variety of cool animation presets 😎


Table of Contents

  1. Features
  2. Installation
  3. Usage
    1. Animated Icons
  4. Props
  5. Presets
    1. Bubble Preset
    2. Flashy Preset
    3. Material Preset
  6. Migration
  7. To Do
  8. Credits
  9. License

Features

  • 60FPS smooth animation for all presets.
  • Fully integrated withReact Navigation v4 & v5.
  • Standalone usage.
  • Right-to-left layout support.
  • Accessibility support.
  • Written inTypeScript.

Installation

yarn add @gorhom/animated-tabbar# ornpm install @gorhom/animated-tabbar

Also, you need to installreact-native-reanimated,react-native-gesture-handler &react-native-svg, and follow their installation instructions.

Usage

OriginallyAnimated TabBar worked only withReact Navigation, but I notice that it could be use as a standalone component and be more useful for the community.

Now the library export two main components:

  • AnimatedTabBar (default ) : theReact Navigation integrated tab bar.
  • AnimatedTabBarView: the standalone tab bar.
Standalone Component
importReact,{useState}from'react';import{View,Text,StyleSheet}from'react-native';importAnimatedTabBar,{TabsConfig,BubbleTabBarItemConfig}from'@gorhom/animated-tabbar';consttabs:TabsConfig<BubbleTabBarItemConfig>={Home:{labelStyle:{color:'#5B37B7',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(91,55,183,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(223,215,243,1)',inactiveColor:'rgba(223,215,243,0)',},},Profile:{labelStyle:{color:'#1194AA',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(17,148,170,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(207,235,239,1)',inactiveColor:'rgba(207,235,239,0)',},},};conststyles=StyleSheet.create({container:{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'#999',},tabBarContainer:{borderRadius:25,},});exportdefaultfunctionApp(){const[index,setIndex]=useState(0);return(<Viewstyle={styles.container}><Text>{index}</Text><AnimatedTabBarViewtabs={tabs}itemOuterSpace={{horizontal:6,vertical:12,}}itemInnerSpace={12}iconSize={20}style={styles.tabBarContainer}index={index}onIndexChange={setIndex}/></View>)}
React Navigation v5 (TypeScript)
importReactfrom'react';import{NavigationContainer}from'@react-navigation/native';import{createBottomTabNavigator}from'@react-navigation/bottom-tabs';importAnimatedTabBar,{TabsConfig,BubbleTabBarItemConfig}from'@gorhom/animated-tabbar';consttabs:TabsConfig<BubbleTabBarItemConfig>={Home:{labelStyle:{color:'#5B37B7',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(91,55,183,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(223,215,243,1)',inactiveColor:'rgba(223,215,243,0)',},},Profile:{labelStyle:{color:'#1194AA',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(17,148,170,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(207,235,239,1)',inactiveColor:'rgba(207,235,239,0)',},},};constTab=createBottomTabNavigator();exportdefaultfunctionApp(){return(<NavigationContainer><Tab.NavigatortabBar={props=>(<AnimatedTabBartabs={tabs}{...props}/>)}><Tab.Screenname="Home"component={HomeScreen}/><Tab.Screenname="Profile"component={ProfileScreen}/></Tab.Navigator></NavigationContainer>)}
React Navigation v5 (JavaScript)
importReactfrom'react';import{NavigationContainer}from'@react-navigation/native';import{createBottomTabNavigator}from'@react-navigation/bottom-tabs';importAnimatedTabBarfrom'@gorhom/animated-tabbar';consttabs={Home:{// < Screen namelabelStyle:{color:'#5B37B7',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(91,55,183,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(223,215,243,1)',inactiveColor:'rgba(223,215,243,0)',},},Profile:{// < Screen namelabelStyle:{color:'#1194AA',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(17,148,170,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(207,235,239,1)',inactiveColor:'rgba(207,235,239,0)',},},};constTab=createBottomTabNavigator();exportdefaultfunctionApp(){return(<NavigationContainer><Tab.NavigatortabBar={props=>(<AnimatedTabBartabs={tabs}{...props}/>)}><Tab.Screenname="Home"component={HomeScreen}/><Tab.Screenname="Profile"component={ProfileScreen}/></Tab.Navigator></NavigationContainer>)}
React Navigation v4
importReactfrom'react';import{createAppContainer}from'react-navigation';import{createBottomTabNavigator}from'react-navigation-tabs';import{SafeAreaProvider}from'react-native-safe-area-context';importAnimatedTabBar,{TabsConfig,BubbleTabBarItemConfig}from'@gorhom/animated-tabbar';consttabs:TabsConfig<BubbleTabConfig>={Home:{labelStyle:{color:'#5B37B7',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(91,55,183,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(223,215,243,1)',inactiveColor:'rgba(223,215,243,0)',},},Profile:{labelStyle:{color:'#1194AA',},icon:{component:/* ICON COMPONENT */,activeColor:'rgba(17,148,170,1)',inactiveColor:'rgba(0,0,0,1)',},background:{activeColor:'rgba(207,235,239,1)',inactiveColor:'rgba(207,235,239,0)',},},};constTabNavigator=createBottomTabNavigator({Home:HomeScreen,Profile:ProfileScreen,},{tabBarComponent:props=><AnimatedTabBartabs={tabs}{...props}/>,},);constAppContainer=createAppContainer(TabNavigator);exportdefault()=>(<SafeAreaProvider><AppContainer/></SafeAreaProvider>);

To configure animated icons, please have a look atAnimated Icons.

Props

namedescriptionrequiredtypedefault
presetAnimation preset, currently options are['bubble', 'flashy', 'material'].NOPresetEnum'bubble'
tabsTabs configurations. A generic dictionary of selected preset tab config.YESTabsConfig<T>
styleView style to be applied to tab bar container,default value will be based on selected preset.NOStyleProp
durationAnimation duration,default value will be based on selected preset.NOnumber
easingAnimation easing function,default value will be based on selected preset.NOEasingFunction
itemInnerSpaceTab item inner space to be added to the tab item,default value will be based on selected preset.NOnumber |Space
itemOuterSpaceTab item outer space to be added to the tab item,default value will be based on selected preset.NOnumber |Space
itemContainerWidthTab item width stretch strategy,default value will be based on selected preset.NO'auto' | 'fill'
iconSizeTab item icon size,default value will be based on selected preset.NOnumber
isRTLTab bar layout and animation direction.NObooleanfalse
onLongPressCallback on item long press,by default it is integrated with React Navigation.NO(index: number) => voidnoop

Preset Configurations

Some presets will have its own configurations - likematerial - which they will be added the root view props.

Material Preset Example

notice here we addedanimation,inactiveOpacity &inactiveScale to the root view.

importReactfrom'react';import{NavigationContainer}from'@react-navigation/native';import{createBottomTabNavigator}from'@react-navigation/bottom-tabs';importAnimatedTabBar,{TabsConfig,MaterialTabBarItemConfig}from'@gorhom/animated-tabbar';consttabs:TabsConfig<MaterialTabBarItemConfig>={Home:{icon:{component:/* ICON COMPONENT */,color:'rgba(255,255,255,1)',},ripple:{color:'#5B37B7',},},Profile:{icon:{component:/* ICON COMPONENT */,color:'rgba(255,255,255,1)',},ripple:{color:'#1194AA',},},};constTab=createBottomTabNavigator();exportdefaultfunctionApp(){return(<NavigationContainer><Tab.NavigatortabBar={props=>(<AnimatedTabBarpreset='material'tabs={tabs}animation="iconWithLabelOnFocus"inactiveOpacity={0.25}inactiveScale={0.5}{...props}/>)}><Tab.Screenname="Home"component={HomeScreen}/><Tab.Screenname="Profile"component={ProfileScreen}/></Tab.Navigator></NavigationContainer>)}

Presets

OriginallyAnimated TabBar started withBubble as the only animation preset embedded. However, I felt the library structure could include many other variety of animation presets.

Migration

V1 to V2

Due to extend the library functionality, I had to rename existing interfaces as following:

  • BubbleTabConfig toBubbleTabBarItemConfig
  • BubbleTabIconProps toBubbleTabBarIconProps
  • FlashyTabConfig toFlashyTabBarItemConfig
  • FlashyTabIconProps toFlashyTabBarIconProps

Author

Sponsor & Support

To keep this library maintained and up-to-date please considersponsoring it on GitHub. Or if you are looking for a private support or help in customizing the experience, then reach out to me on Twitter@gorhom.

License

MIT

Built With ❤️


Mo Gorhom

About

A 60FPS animated tab bar with a variety of cool animation presets 😎

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

 

[8]ページ先頭

©2009-2025 Movatter.jp