Skip to content

Commit

Permalink
feat: add material preset (#60)
Browse files Browse the repository at this point in the history
* chore: updated reanimation & redash

* chore: added a callback for rawbutton onlayout

* chore: added material preset

* chore: added material preset examples

* fix: fixed usage of useValues

* fix: fixed initial background color

* chore: updated types descriptions

* docs: update readme and added material doc

* docs: update material docs

* docs: update material docs
  • Loading branch information
gorhom authored Jul 18, 2020
1 parent dfdbfae commit 13952a4
Show file tree
Hide file tree
Showing 34 changed files with 1,445 additions and 66 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A **60FPS** animated tab bar with a variety of cool animation presets 😎
5. [Presets](#presets)
1. [Bubble Preset](./docs/bubble-preset.md)
2. [Flashy Preset](./docs/flashy-preset.md)
3. [Material Preset](./docs/material-preset.md)
6. [To Do](#to-do)
7. [Credits](#built-with)
8. [License](#license)
Expand All @@ -34,7 +35,6 @@ A **60FPS** animated tab bar with a variety of cool animation presets 😎
- Accessibility support.
- Written in `TypeScript`.


## Installation

```sh
Expand Down Expand Up @@ -262,7 +262,7 @@ export default () => (

| name | description | required | type | default |
| -------------------- | --------------------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------- | -------- |
| `preset` | Animation preset, currently options are `['bubble', 'flashy']`. | NO | [`PresetEnum`](./src/presets.ts#L15) | 'bubble' |
| `preset` | Animation preset, currently options are `['bubble', 'flashy', 'material']`. | NO | [`PresetEnum`](./src/presets.ts#L8) | 'bubble' |
| `tabs` | Tabs configurations. A generic dictionary of selected preset tab config. | YES | [`TabsConfig<T>`](./src/types.ts#L5) | |
| `style` | View style to be applied to tab bar container, `default value will be based on selected preset`. | NO | StyleProp<ViewStyle> | |
| `duration` | Animation duration, `default value will be based on selected preset`. | NO | number | |
Expand All @@ -278,10 +278,17 @@ export default () => (

Originally `Animated TabBar` started with `Bubble` as the only animation preset embedded. However, I felt the library structure could include many other variety of animation presets.

<table>
<tr><td><a href="./docs/bubble-preset.md">Bubble Preset</a></td><td><a href="./docs/flashy-preset.md">Flashy Preset</a></td></tr>
<tr><td><a href="./docs/bubble-preset.md"><img src="./docs/previews/bubble.gif" /></a></td><td><a href="./docs/flashy-preset.md"><img src="./docs/previews/flashy.gif" /></a></td></tr>
</table>
### [Bubble Preset](./docs/bubble-preset.md)

<a href="./docs/bubble-preset.md"><img height="200" src="./docs/previews/bubble.gif" /></a>

### [Flashy Preset](./docs/flashy-preset.md)

<a href="./docs/flashy-preset.md"><img height="200" src="./docs/previews/flashy.gif" /></a>

### [Material Preset](./docs/material-preset.md)

<a href="./docs/material-preset.md"><img height="200" src="./docs/previews/material-1.gif" /></a>

## To Do

Expand Down
140 changes: 140 additions & 0 deletions docs/material-preset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Material Preset

> This preset is inspired by [timomeh](https://github.com/timomeh) works on [react-native-material-bottom-navigation](https://github.com/timomeh/react-native-material-bottom-navigation).
### Icon with label

<img height="200" src="../docs/previews/material-1.gif" />

### Icon only

<img height="200" src="../docs/previews/material-2.gif" />

### Icon with label on focus

<img height="200" src="../docs/previews/material-3.gif" />

## Interfaces

### MaterialTabBarConfig

| name | description | required | type | default |
| ----------------- | -------------------------------------- | -------- | ------------------------------------------------------- | --------------- |
| `animation` | Material animation preset. | NO | `iconWithLabel` \| `iconOnly` \| `iconWithLabelOnFocus` | `iconWithLabel` |
| `inactiveOpacity` | Tab bar item inactive opacity. | NO | number | 0.75 |
| `inactiveScale` | Tab bar item indicator configurations. | NO | number | 0.85 |

<details>
<summary>TypeScript Interface</summary>

```ts
export interface MaterialTabBarConfig {
/**
* Material animation preset.
* @type {'iconWithLabel' | 'iconOnly' | 'iconWithLabelOnFocus'}
* @default 'iconWithLabel'
*/
animation?: 'iconWithLabel' | 'iconOnly' | 'iconWithLabelOnFocus';
/**
* Tab bar item inactive opacity.
* @type {number}
* @default 0.75
*/
inactiveOpacity?: number;
/**
* Tab bar item inactive scale.
* @type {number}
* @default 0.85
*/
inactiveScale?: number;
}
```

</details>

### MaterialTabBarItemConfig

| name | description | required | type | default |
| ------------ | ------------------------------------------------------------ | -------- | ------------------- | ------------- |
| `labelStyle` | This will apply to the tab bar item label. | NO | TextStyle | |
| `icon` | Icon configurations. | YES | object | |
| `├component` | Icon component, this could be a function or class component. | YES | [`ReactNode`](#L45) | |
| `└color` | Icon color. | YES | string | |
| `ripple` | Tab bar item ripple configurations. | YES | object | |
| `└color` | Ripple color. | NO | string | `label color` |

<details>
<summary>TypeScript Interface</summary>

```ts
export interface MaterialTabBarItemConfig {
/**
* Tab bar item label style.
*/
labelStyle?: StyleProp<TextStyle>;
/**
* Tab bar item icon config.
*/
icon: {
/**
* Tab bar item icon component, this could be a function or
* a react node.
* @type {(props: MaterialTabBarIconProps) => React.ReactNode | React.ReactNode}
*/
component:
| React.FC<MaterialTabBarIconProps>
| React.ComponentClass<MaterialTabBarIconProps>
| React.ReactNode;
/**
* Icon color.
* @type {string}
*/
color: string;
};
/**
* Tab bar item ripple config.
*/
ripple: {
/**
* Tab bar item ripple color.
* @type {string}
*/
color: string;
};
}
```

</details>

### MaterialTabBarIconProps

| name | description | required | type | default |
| --------------- | ---------------------------------- | -------- | ----------------------- | ------- |
| `animatedFocus` | Tab bar item animated focus value. | YES | `Animated.Node<number>` |
| `color` | Tab bar item icon color. | YES | number | |
| `size` | Tab bar item icon size. | YES | number | |

<details>
<summary>TypeScript Interface</summary>

```ts
export interface MaterialTabBarIconProps {
/**
* Tab bar item animated focus value.
* @type {Animated.Node<number>}
*/
animatedFocus: Animated.Node<number>;
/**
* Tab bar item icon color.
* @type {string}
*/
color: string;
/**
* Tab bar item icon size.
* @type {number}
*/
size: number;
}
```

</details>
Binary file added docs/previews/material-1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/previews/material-2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/previews/material-3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion example/android/AnimatedTabbarExample.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="AnimatedTabbarExample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.id="AnimatedTabbarExample" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand Down
16 changes: 8 additions & 8 deletions example/android/app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AnimatedTabbarExample" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -19,8 +19,8 @@
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/src/debug/res;file://$MODULE_DIR$/build/generated/res/react/debug;file://$MODULE_DIR$/build/generated/res/rs/debug;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/androidTest/res;file://$MODULE_DIR$/src/test/res;file://$MODULE_DIR$/src/androidTestDebug/res;file://$MODULE_DIR$/src/testDebug/res;file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug;file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
Expand Down 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="android-react-native-community_masked-view" />
<orderEntry type="module" module-name="android-react-native-gesture-handler" />
<orderEntry type="module" module-name="android-react-native-reanimated" />
<orderEntry type="module" module-name="android-react-native-safe-area-context" />
<orderEntry type="module" module-name="android-react-native-screens" />
<orderEntry type="module" module-name="AnimatedTabbarExample-react-native-community_masked-view" />
<orderEntry type="module" module-name="AnimatedTabbarExample-react-native-gesture-handler" />
<orderEntry type="module" module-name="com.swmansion.reanimated-react-native-reanimated" />
<orderEntry type="module" module-name="AnimatedTabbarExample-react-native-safe-area-context" />
<orderEntry type="module" module-name="com.swmansion.rnscreens-react-native-screens" />
<orderEntry type="module" module-name="react-native-svg" />
</component>
</module>
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ PODS:
- React
- RNGestureHandler (1.6.1):
- React
- RNReanimated (1.8.0):
- RNReanimated (1.9.0):
- React
- RNScreens (2.7.0):
- React
Expand Down Expand Up @@ -388,7 +388,7 @@ SPEC CHECKSUMS:
ReactCommon: ed4e11d27609d571e7eee8b65548efc191116eb3
RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f
RNGestureHandler: 8f09cd560f8d533eb36da5a6c5a843af9f056b38
RNReanimated: 955cf4068714003d2f1a6e2bae3fb1118f359aff
RNReanimated: b5ccb50650ba06f6e749c7c329a1bc3ae0c88b43
RNScreens: cf198f915f8a2bf163de94ca9f5bfc8d326c3706
RNSVG: ce9d996113475209013317e48b05c21ee988d42e
Yoga: 3ebccbdd559724312790e7742142d062476b698e
Expand Down
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.8.0",
"react-native-redash": "^13.6.0",
"react-native-reanimated": "1.9.0",
"react-native-redash": "^14.2.1",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.7.0",
"react-native-svg": "^12.1.0"
Expand Down
26 changes: 26 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import FlashyScreen from './screens/Flashy';
import FlashyStyledScreen from './screens/FlashyStyled';
import FlashyRTLScreen from './screens/FlashyRTL';
import FlashyStandaloneScreen from './screens/FlashyStandalone';
import {
MaterialIconWithLabelScreen,
MaterialIconWithLabelOnFocusScreen,
MaterialIconOnlyScreen,
} from './screens/Material';
import MaterialStyledScreen from './screens/MaterialStyled';
import MaterialRTLScreen from './screens/MaterialRTL';
import MaterialStandaloneScreen from './screens/MaterialStandalone';

const Stack = createStackNavigator();

Expand All @@ -32,6 +40,24 @@ export default function App() {
name="FlashyStandalone"
component={FlashyStandaloneScreen}
/>
<Stack.Screen
name="MaterialIconWithLabel"
component={MaterialIconWithLabelScreen}
/>
<Stack.Screen
name="MaterialIconOnly"
component={MaterialIconOnlyScreen}
/>
<Stack.Screen
name="MaterialIconWithLabelOnFocus"
component={MaterialIconWithLabelOnFocusScreen}
/>
<Stack.Screen name="MaterialStyled" component={MaterialStyledScreen} />
<Stack.Screen name="MaterialRTL" component={MaterialRTLScreen} />
<Stack.Screen
name="MaterialStandalone"
component={MaterialStandaloneScreen}
/>
</Stack.Navigator>
</NavigationContainer>
);
Expand Down
Loading

0 comments on commit 13952a4

Please sign in to comment.