Skip to content

Commit

Permalink
feat: support standalone usage (#38)
Browse files Browse the repository at this point in the history
* chore: extract tabbar view from default animated tabbar

* chore: remove react-navigation dependencies

* chore: updated space interface

* refactor: updated bubble preset styling

* chore: added outer space flashy preset

* chore: updated examples and add standalone

* chore: updated svg icons

* chore: updated bubble standalone example

* chore: added itemcontainerwidth prop

* docs: updated contributing doc

* docs: updated readme file to include itemcontainerwidth

* docs: updated logo link

* docs: updated usage in rn4

* docs: updated standalone example styling
  • Loading branch information
gorhom authored May 20, 2020
1 parent c86b529 commit 343a255
Show file tree
Hide file tree
Showing 28 changed files with 751 additions and 267 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ The `package.json` file contains various scripts for common tasks:
- `yarn bootstrap`: setup project by installing all dependencies and pods.
- `yarn typescript`: type-check files with TypeScript.
- `yarn lint`: lint files with ESLint.
- `yarn test`: run unit tests with Jest.
- `yarn example start`: start the Metro server for the example app.
- `yarn example android`: run the example app on Android.
- `yarn example ios`: run the example app on iOS.
Expand Down
97 changes: 86 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<img src="./preview.gif">

A **60fps** animated tab bar to be used with `React Navigation v4 & v5` with a variety of cool animation presets 😎.
A **60FPS** animated tab bar with a variety of cool animation presets 😎

</div>

Expand Down Expand Up @@ -36,6 +36,82 @@ npm install @gorhom/animated-tabbar
## Usage

Originally `Animated TabBar` worked only with `React Navigation`, but I notice that it could be use as a standalone component and be more useful for the community.

<details>
<summary>Standalone Component</summary>

```tsx
import React, { useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import AnimatedTabBar, {TabsConfig, BubbleTabConfig} from '@gorhom/animated-tabbar';

const tabs: 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)',
},
},
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#999',
},
tabBarContainer: {
borderRadius: 25,
},
});

export default function App() {
const [index, setIndex] = useState(0);
return (
<View style={styles.container}>
<Text>{index}</Text>
<AnimatedTabBarView
tabs={tabs}
itemOuterSpace={{
horizontal: 6,
vertical: 12,
}}
itemInnerSpace={12}
iconSize={20}
style={styles.tabBarContainer}
index={index}
onIndexChange={setIndex}
/>
</View>
)
}
```

</details>
<details>
<summary>React Navigation v5</summary>

Expand Down Expand Up @@ -109,7 +185,6 @@ export default function App() {
import React from 'react';
import {createAppContainer} from 'react-navigation';
import {createBottomTabNavigator} from 'react-navigation-tabs';
import {createStackNavigator} from 'react-navigation-stack';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import AnimatedTabBar, {TabsConfig, BubbleTabConfig} from '@gorhom/animated-tabbar';

Expand Down Expand Up @@ -184,12 +259,13 @@ export default () => (

### [TabBarItemConfigurableProps](./src/types.ts#L26)

| name | description | required | type | default |
| ---------------- | --------------------------------------------------------------------------------- | -------- | --------------------------------------- | ------- |
| `itemInnerSpace` | Inner space to be added to the tab item, this may not be applied on some presets. | NO | number \| [`Space`](./src/types.ts#L21) | 12 |
| `itemOuterSpace` | Outer space to be added to the tab item, this may not be applied on some presets. | NO | number \| [`Space`](./src/types.ts#L21) | 12 |
| `iconSize` | Tab item icon size. | NO | number | 24 |
| `isRTL` | Tab bar layout and animation direction. | NO | boolean | false |
| name | description | required | type | default |
| -------------------- | --------------------------------------------------------------------------------- | -------- | --------------------------------------- | ------- |
| `itemInnerSpace` | Inner space to be added to the tab item, this may not be applied on some presets. | NO | number \| [`Space`](./src/types.ts#L21) | 12 |
| `itemOuterSpace` | Outer space to be added to the tab item, this may not be applied on some presets. | NO | number \| [`Space`](./src/types.ts#L21) | 12 |
| `itemContainerWidth` | Tab Item width stretch strategy, this may not be applied on some presets. | NO | 'auto' \| 'fill' | 'auto' |
| `iconSize` | Tab item icon size. | NO | number | 24 |
| `isRTL` | Tab bar layout and animation direction. | NO | boolean | false |

## Presets

Expand All @@ -210,12 +286,11 @@ Originally `Animated TabBar` started with `Bubble` as the only animation preset
- [react-native-gesture-handler](https://github.com/software-mansion/react-native-gesture-handler)
- [react-native-redash](https://github.com/wcandillon/react-native-redash)
- [react-native-svg](https://github.com/react-native-community/react-native-svg)
- [react-navigation](https://github.com/react-navigation/react-navigation)
- [@react-native-community/bob](https://github.com/react-native-community/bob)

## Author

- [Mo Gorhom](https://twitter.com/gorhom)
- [Mo Gorhom](https://gorhom.dev/)

## License

Expand All @@ -232,5 +307,5 @@ Liked the library? 😇
---

<p align="center">
<a href="https://twitter.com/gorhom"><img src="./logo.png"></a>
<a href="https://gorhom.dev" target="_blank"><img alt="Mo Gorhom" src="./logo.png"></a>
</p>
10 changes: 5 additions & 5 deletions example/android/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@
<orderEntry type="library" name="Gradle: com.facebook.fresco:nativeimagetranscoder:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.facebook.fresco:imagepipeline-okhttp3:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: org.webkit:android-jsc:r245459@aar" level="project" />
<orderEntry type="module" module-name="masked-view-android-react-native-community_masked-view" />
<orderEntry type="module" module-name="react-native-gesture-handler-android-react-native-gesture-handler" />
<orderEntry type="module" module-name="react-native-reanimated-android-react-native-reanimated" />
<orderEntry type="module" module-name="react-native-safe-area-context-android-react-native-safe-area-context" />
<orderEntry type="module" module-name="react-native-screens-android-react-native-screens" />
<orderEntry type="module" module-name="react-native-community_masked-view" />
<orderEntry type="module" module-name="react-native-gesture-handler" />
<orderEntry type="module" module-name="react-native-reanimated" />
<orderEntry type="module" module-name="react-native-safe-area-context" />
<orderEntry type="module" module-name="react-native-screens" />
<orderEntry type="module" module-name="react-native-svg" />
</component>
</module>
10 changes: 10 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import RootScreen from './screens/Root';
import BubbleScreen from './screens/Bubble';
import BubbleStyledScreen from './screens/BubbleStyled';
import BubbleRTLScreen from './screens/BubbleRTL';
import BubbleStandaloneScreen from './screens/BubbleStandalone';
import FlashyScreen from './screens/Flashy';
import FlashyStyledScreen from './screens/FlashyStyled';
import FlashyRTLScreen from './screens/FlashyRTL';
import FlashyStandaloneScreen from './screens/FlashyStandalone';

const Stack = createStackNavigator();

Expand All @@ -19,9 +21,17 @@ export default function App() {
<Stack.Screen name="Bubble" component={BubbleScreen} />
<Stack.Screen name="BubbleStyled" component={BubbleStyledScreen} />
<Stack.Screen name="BubbleRTL" component={BubbleRTLScreen} />
<Stack.Screen
name="BubbleStandalone"
component={BubbleStandaloneScreen}
/>
<Stack.Screen name="Flashy" component={FlashyScreen} />
<Stack.Screen name="FlashyStyled" component={FlashyStyledScreen} />
<Stack.Screen name="FlashyRTL" component={FlashyRTLScreen} />
<Stack.Screen
name="FlashyStandalone"
component={FlashyStandaloneScreen}
/>
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
138 changes: 138 additions & 0 deletions example/src/screens/BubbleStandalone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import React, { useState, useMemo } from 'react';
import { View, StyleSheet, Button, StatusBar } from 'react-native';
import {
AnimatedTabBarView,
TabsConfig,
BubbleTabConfig,
} from '@gorhom/animated-tabbar';
import HomeSVG from '../svg/HomeSVG';
import LikeSVG from '../svg/LikeSVG';
import SearchSVG from '../svg/SearchSVG';
import ProfileSVG from '../svg/ProfileSVG';
import { MainTabsParams } from './types';

const tabs: TabsConfig<BubbleTabConfig, MainTabsParams> = {
Home: {
labelStyle: {
color: '#5B37B7',
},
icon: {
component: HomeSVG,
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)',
},
},
Likes: {
labelStyle: {
color: '#C9379D',
},
icon: {
component: LikeSVG,
activeColor: 'rgba(201,55,157,1)',
inactiveColor: 'rgba(0,0,0,1)',
},
background: {
activeColor: 'rgba(247,215,243,1)',
inactiveColor: 'rgba(247,215,243,0)',
},
},
Search: {
labelStyle: {
color: '#E6A919',
},
icon: {
component: SearchSVG,
activeColor: 'rgba(230,169,25,1)',
inactiveColor: 'rgba(0,0,0,1)',
},
background: {
activeColor: 'rgba(251,239,211,1)',
inactiveColor: 'rgba(251,239,211,0)',
},
},
Profile: {
labelStyle: {
color: '#1194AA',
},
icon: {
component: ProfileSVG,
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)',
},
},
};

const BubbleStandaloneScreen = () => {
const [index, setIndex] = useState(0);

const containerStyle = useMemo(
() => [
styles.container,
{
// @ts-ignore
backgroundColor: tabs[Object.keys(tabs)[index]].labelStyle.color,
},
],
[index]
);
return (
<View style={containerStyle}>
<StatusBar barStyle="dark-content" />
<AnimatedTabBarView
preset="bubble"
tabs={tabs}
itemOuterSpace={{
horizontal: 6,
vertical: 12,
}}
itemInnerSpace={12}
iconSize={20}
style={styles.tabBarContainer}
index={index}
onIndexChange={setIndex}
/>

<Button
title="Set Index to 0"
color={'white'}
onPress={() => setIndex(0)}
/>
<Button
title="Set Index to 1"
color={'white'}
onPress={() => setIndex(1)}
/>
<Button
title="Set Index to 2"
color={'white'}
onPress={() => setIndex(2)}
/>
<Button
title="Set Index to 3"
color={'white'}
onPress={() => setIndex(3)}
/>
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
tabBarContainer: {
borderRadius: 25,
},
});

export default BubbleStandaloneScreen;
7 changes: 1 addition & 6 deletions example/src/screens/Flashy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ const FlashyScreen = () => {
return (
<Tab.Navigator
tabBar={props => (
<AnimatedTabBar
preset="flashy"
duration={1000}
tabs={tabs}
{...props}
/>
<AnimatedTabBar preset="flashy" tabs={tabs} {...props} />
)}
>
<Tab.Screen
Expand Down
2 changes: 0 additions & 2 deletions example/src/screens/FlashyRTL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ const FlashyStyledScreen = () => {
tabBar={props => (
<AnimatedTabBar
preset="flashy"
duration={1000}
tabs={tabs}
iconSize={20}
itemInnerSpace={24}
isRTL={true}
{...props}
/>
Expand Down
Loading

0 comments on commit 343a255

Please sign in to comment.