From 4a8a5685a6f3e60e7c5945625f335b05a8b506a1 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Thu, 1 Aug 2019 09:33:22 +0300 Subject: [PATCH] redesign for tabbar --- package.json | 1 + .../bottomTabBar/view/bottomTabBarView.js | 41 ++--- src/components/bottomTabBar/view/tabbar.js | 172 ++++++++++++++++++ src/navigation/baseNavigator.js | 29 +-- 4 files changed, 198 insertions(+), 45 deletions(-) create mode 100644 src/components/bottomTabBar/view/tabbar.js diff --git a/package.json b/package.json index c765aad08..16e6c50b6 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "react-native-scrollable-tab-view": "^0.10.0", "react-native-slider": "^0.11.0", "react-native-snap-carousel": "^3.8.0", + "react-native-svg": "^9.5.3", "react-native-vector-icons": "^6.0.2", "react-native-version": "^3.1.0", "react-native-version-number": "^0.3.5", diff --git a/src/components/bottomTabBar/view/bottomTabBarView.js b/src/components/bottomTabBar/view/bottomTabBarView.js index 433f5ac3f..027e41c04 100644 --- a/src/components/bottomTabBar/view/bottomTabBarView.js +++ b/src/components/bottomTabBar/view/bottomTabBarView.js @@ -1,5 +1,5 @@ import React, { PureComponent } from 'react'; -import { TouchableOpacity, SafeAreaView } from 'react-native'; +import { TouchableOpacity, SafeAreaView, View, Dimensions } from 'react-native'; import { connect } from 'react-redux'; import ViewOverflow from 'react-native-view-overflow'; @@ -10,6 +10,7 @@ import { updateActiveBottomTab } from '../../../redux/actions/uiAction'; import ROUTES from '../../../constants/routeNames'; // Components +import TabBar from './tabbar'; // Styles import styles from './bottomTabBarStyles'; @@ -71,27 +72,23 @@ class BottomTabBarView extends PureComponent { } = this.props; return ( - - - {routes.map((route, idx) => ( - - this._jumpTo(route)}> - {renderIcon({ - route, - focused: index === idx, - tintColor: index === idx ? activeTintColor : inactiveTintColor, - })} - - - ))} - - + + + ); } } diff --git a/src/components/bottomTabBar/view/tabbar.js b/src/components/bottomTabBar/view/tabbar.js new file mode 100644 index 000000000..3c1a4e393 --- /dev/null +++ b/src/components/bottomTabBar/view/tabbar.js @@ -0,0 +1,172 @@ +/* eslint-disable */ +import { StyleSheet, View, TouchableHighlight, Animated, Image } from 'react-native'; +import React, { Component } from 'react'; + +import Svg, { Circle, Path } from 'react-native-svg'; + +const AnimatedCircle = Animated.createAnimatedComponent(Circle); +const AnimatedPath = Animated.createAnimatedComponent(Path); + +export default class TabBar extends Component { + constructor(props) { + super(props); + + this.state = { + selectedIndex: 2, + circleRadius: new Animated.Value(331), + pathD: new Animated.Value(240), + pathX: 240, + showIcon: true, + }; + + this.state.circleRadius.addListener(circleRadius => { + this._myCircle.setNativeProps({ cx: parseInt(circleRadius.value) }); + }); + + this.state.pathD.addListener(a => { + console.log(this.state.pathD); + this.setState({ + pathX: parseInt(a.value), + }); + }); + } + + _renderButtonContent = (i, selectedIndex, showIcon, route) => { + const { renderIcon, inactiveTintColor, activeTintColor } = this.props; + if (selectedIndex == i) { + if (showIcon) { + return ( + + {renderIcon({ + route, + focused: true, + tintColor: activeTintColor, + })} + + ); + } + return ; + } + return ( + + {renderIcon({ + route, + focused: false, + tintColor: inactiveTintColor, + })} + + ); + }; + + _onPress = (i, route) => { + const { onPress } = this.props; + this.update(i); + onPress(route); + }; + + render() { + const { children, itemList } = this.props; + const { selectedIndex, showIcon, pathX } = this.state; + + return ( + + + + {itemList.map((route, i) => ( + (selectedIndex !== i ? this._onPress(i, route) : null)} + > + {this._renderButtonContent(i, selectedIndex, showIcon, route)} + + ))} + + + + + (this._myCircle = ref)} + fill="#f0f0f0" + cx="331" + cy="50.5" + r="50" + /> + + + + ); + } + update(index) { + const value = 120; + let that = this; + that.setState({ + selectedIndex: index, + showIcon: false, + }); + + Animated.spring(that.state.pathD, { + toValue: 0 + index * value, + duration: 10, + friction: 10, + }).start(); + setTimeout(function() { + that.setState({ + showIcon: true, + }); + }, 100); + Animated.spring(that.state.circleRadius, { + toValue: 91 + index * value, + friction: 10, + }).start(); + } +} +const styles = StyleSheet.create({ + container: { + flex: 1, + overflow: 'hidden', + }, + subContent: { + flexDirection: 'row', + marginLeft: 19, + marginRight: 19, + marginBottom: 10, + zIndex: 1, + position: 'absolute', + bottom: 5, + }, + navItem: { + flex: 1, + paddingTop: 6, + paddingBottom: 6, + alignItems: 'center', + zIndex: 0, + }, + navImage: { + width: 45, + height: 45, + }, + circle: { + bottom: 28, + }, +}); diff --git a/src/navigation/baseNavigator.js b/src/navigation/baseNavigator.js index 44c8cce96..ccfab9e9c 100644 --- a/src/navigation/baseNavigator.js +++ b/src/navigation/baseNavigator.js @@ -16,13 +16,7 @@ const BaseNavigator = createBottomTabNavigator( screen: Home, navigationOptions: () => ({ tabBarIcon: ({ tintColor }) => ( - + ), }), }, @@ -37,7 +31,6 @@ const BaseNavigator = createBottomTabNavigator( name="notifications" color={tintColor} size={26} - style={{ padding: 15 }} /> ), }), @@ -45,20 +38,16 @@ const BaseNavigator = createBottomTabNavigator( [ROUTES.TABBAR.POSTBUTTON]: { screen: () => null, navigationOptions: { - tabBarIcon: , + tabBarIcon: ({ tintColor }) => ( + + ), }, }, [ROUTES.TABBAR.POINTS]: { screen: Points, navigationOptions: () => ({ tabBarIcon: ({ tintColor }) => ( - + ), }), }, @@ -66,13 +55,7 @@ const BaseNavigator = createBottomTabNavigator( screen: Profile, navigationOptions: () => ({ tabBarIcon: ({ tintColor }) => ( - + ), }), },