From 8c752c00f4d2ab442b644552d9ef3862abeaa9f2 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Thu, 5 Dec 2019 01:04:09 +0300 Subject: [PATCH] Fixed navbar design issue --- .../bottomTabBar/view/bottomTabBarStyles.js | 10 ++++++---- src/components/bottomTabBar/view/tabbar.js | 8 +++++--- src/components/icon/view/iconView.js | 2 -- src/components/postButton/postButtonView.js | 3 ++- .../postElements/body/view/postBodyView.js | 4 ++-- src/navigation/baseNavigator.js | 9 +++++---- src/utils/scalePx.js | 12 ++++++++++++ 7 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 src/utils/scalePx.js diff --git a/src/components/bottomTabBar/view/bottomTabBarStyles.js b/src/components/bottomTabBar/view/bottomTabBarStyles.js index be73eeab6..fce75287a 100644 --- a/src/components/bottomTabBar/view/bottomTabBarStyles.js +++ b/src/components/bottomTabBar/view/bottomTabBarStyles.js @@ -1,5 +1,6 @@ import EStyleSheet from 'react-native-extended-stylesheet'; import { Dimensions } from 'react-native'; +import scalePx from '../../../utils/scalePx'; const deviceWidth = Dimensions.get('window').width; @@ -16,16 +17,17 @@ export default EStyleSheet.create({ zIndex: 1, position: 'absolute', bottom: 0, - marginHorizontal: 20, + marginHorizontal: scalePx(20), justifyContent: 'space-between', }, navItem: { alignItems: 'center', zIndex: 0, - padding: 20, - width: (deviceWidth - 38) / 5, + paddingVertical: scalePx(8), + paddingHorizontal: scalePx(10), + width: (deviceWidth - scalePx(38)) / 5, }, circle: { - bottom: 25, + bottom: scalePx(25), }, }); diff --git a/src/components/bottomTabBar/view/tabbar.js b/src/components/bottomTabBar/view/tabbar.js index ccb63de69..dba398214 100644 --- a/src/components/bottomTabBar/view/tabbar.js +++ b/src/components/bottomTabBar/view/tabbar.js @@ -1,7 +1,9 @@ -import { View, TouchableHighlight, Animated } from 'react-native'; import React, { Component } from 'react'; +import { View, TouchableHighlight, Animated } from 'react-native'; import Svg, { Circle, Path } from 'react-native-svg'; +import scalePx from '../../../utils/scalePx'; + const AnimatedCircle = Animated.createAnimatedComponent(Circle); const AnimatedPath = Animated.createAnimatedComponent(Path); @@ -110,8 +112,8 @@ export default class TabBar extends Component { x="0px" y="0px" width="100%" - height="100" - viewBox="0 0 661 136" + height={scalePx(100)} + viewBox="0 0 661 100" space="preserve" > ( ( } activeOpacity={1} > - + ); diff --git a/src/components/postElements/body/view/postBodyView.js b/src/components/postElements/body/view/postBodyView.js index 5c36943c7..6d33b4ab2 100644 --- a/src/components/postElements/body/view/postBodyView.js +++ b/src/components/postElements/body/view/postBodyView.js @@ -120,7 +120,7 @@ const PostBody = ({ } }; - const test = body.replace(/ ({ tabBarIcon: ({ tintColor }) => ( - + ), }), }, @@ -29,7 +30,7 @@ const BaseNavigator = createBottomTabNavigator( iconType="MaterialIcons" name="notifications" color={tintColor} - size={26} + size={scalePx(26)} /> ), }), @@ -48,7 +49,7 @@ const BaseNavigator = createBottomTabNavigator( iconType="MaterialIcons" name="account-balance-wallet" color={tintColor} - size={26} + size={scalePx(26)} /> ), }), @@ -57,7 +58,7 @@ const BaseNavigator = createBottomTabNavigator( screen: Profile, navigationOptions: () => ({ tabBarIcon: ({ tintColor }) => ( - + ), }), }, diff --git a/src/utils/scalePx.js b/src/utils/scalePx.js new file mode 100644 index 000000000..92c8d9f8a --- /dev/null +++ b/src/utils/scalePx.js @@ -0,0 +1,12 @@ +import { Dimensions, PixelRatio } from 'react-native'; + +const { width: SCREEN_WIDTH } = Dimensions.get('window'); + +// based on iphone X's scale +const scale = SCREEN_WIDTH / 414; + +export default size => { + const newSize = size * scale; + + return Math.round(PixelRatio.roundToNearestPixel(newSize)); +};