From e2cdc26442e23ecb0d18e8a34c89cfa9ad1546ef Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sun, 31 May 2020 16:30:38 +0200 Subject: [PATCH] Added padding to tab bar bottom for iPhoneX devices --- App.js | 17 +++++++++++------ src/components/Tabbar/CustomTabBar.js | 25 ++++++++----------------- src/utils/withSafeArea.js | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 src/utils/withSafeArea.js diff --git a/App.js b/App.js index 459e45c..1daf54a 100644 --- a/App.js +++ b/App.js @@ -17,6 +17,7 @@ import URLHandler from "./src/utils/URLHandler"; import {setSafeBounceHeight} from "react-navigation-collapsible"; import SplashScreen from 'react-native-splash-screen' import {OverflowMenuProvider} from "react-navigation-header-buttons"; +import {SafeAreaProvider} from "react-native-safe-area-context"; // Native optimizations https://reactnavigation.org/docs/react-native-screens // Crashes app when navigating away from webview on android 9+ @@ -192,12 +193,16 @@ export default class App extends React.Component { - - - + + + + + diff --git a/src/components/Tabbar/CustomTabBar.js b/src/components/Tabbar/CustomTabBar.js index 481a334..12ee0da 100644 --- a/src/components/Tabbar/CustomTabBar.js +++ b/src/components/Tabbar/CustomTabBar.js @@ -3,7 +3,8 @@ import {withTheme} from 'react-native-paper'; import TabIcon from "./TabIcon"; import TabHomeIcon from "./TabHomeIcon"; import {Animated} from 'react-native'; -import {SafeAreaView} from 'react-native-safe-area-context'; +import {withSafeArea} from "../../utils/withSafeArea"; +import {EdgeInsets} from "react-native-safe-area-context"; type Props = { state: Object, @@ -11,6 +12,7 @@ type Props = { navigation: Object, theme: Object, collapsibleStack: Object, + safeArea: EdgeInsets } type State = { @@ -37,13 +39,6 @@ class CustomTabBar extends React.Component { barSynced: false,// Is the bar synced with the header for animations? } - tabRef: Object; - - constructor(props) { - super(props); - this.tabRef = React.createRef(); - } - onItemPress(route: Object, currentIndex: number, destIndex: number) { const event = this.props.navigation.emit({ type: 'tabPress', @@ -135,28 +130,24 @@ class CustomTabBar extends React.Component { render() { this.props.navigation.addListener('state', this.onRouteChange); return ( - {this.props.state.routes.map(this.renderIcon)} - ); } } -export default withTheme(CustomTabBar); +export default withSafeArea(withTheme(CustomTabBar)); diff --git a/src/utils/withSafeArea.js b/src/utils/withSafeArea.js new file mode 100644 index 0000000..dfbe533 --- /dev/null +++ b/src/utils/withSafeArea.js @@ -0,0 +1,14 @@ +import React from 'react'; +import {useSafeArea} from 'react-native-safe-area-context'; + +export const withSafeArea = (Component: any) => { + return React.forwardRef((props: any, ref: any) => { + let safeArea = useSafeArea(); + // safeArea.bottom = 0; + return ; + }); +};