forked from vergnet/application-amicale
Added padding to tab bar bottom for iPhoneX devices
This commit is contained in:
parent
9cf3484dbf
commit
e2cdc26442
3 changed files with 33 additions and 23 deletions
17
App.js
17
App.js
|
@ -17,6 +17,7 @@ import URLHandler from "./src/utils/URLHandler";
|
||||||
import {setSafeBounceHeight} from "react-navigation-collapsible";
|
import {setSafeBounceHeight} from "react-navigation-collapsible";
|
||||||
import SplashScreen from 'react-native-splash-screen'
|
import SplashScreen from 'react-native-splash-screen'
|
||||||
import {OverflowMenuProvider} from "react-navigation-header-buttons";
|
import {OverflowMenuProvider} from "react-navigation-header-buttons";
|
||||||
|
import {SafeAreaProvider} from "react-native-safe-area-context";
|
||||||
|
|
||||||
// Native optimizations https://reactnavigation.org/docs/react-native-screens
|
// Native optimizations https://reactnavigation.org/docs/react-native-screens
|
||||||
// Crashes app when navigating away from webview on android 9+
|
// Crashes app when navigating away from webview on android 9+
|
||||||
|
@ -192,12 +193,16 @@ export default class App extends React.Component<Props, State> {
|
||||||
<PaperProvider theme={this.state.currentTheme}>
|
<PaperProvider theme={this.state.currentTheme}>
|
||||||
<OverflowMenuProvider>
|
<OverflowMenuProvider>
|
||||||
<View style={{backgroundColor: ThemeManager.getCurrentTheme().colors.background, flex: 1}}>
|
<View style={{backgroundColor: ThemeManager.getCurrentTheme().colors.background, flex: 1}}>
|
||||||
<NavigationContainer theme={this.state.currentTheme} ref={this.navigatorRef}>
|
<SafeAreaProvider
|
||||||
<MainNavigator
|
edges={['bottom']}
|
||||||
defaultHomeRoute={this.defaultHomeRoute}
|
>
|
||||||
defaultHomeData={this.defaultHomeData}
|
<NavigationContainer theme={this.state.currentTheme} ref={this.navigatorRef}>
|
||||||
/>
|
<MainNavigator
|
||||||
</NavigationContainer>
|
defaultHomeRoute={this.defaultHomeRoute}
|
||||||
|
defaultHomeData={this.defaultHomeData}
|
||||||
|
/>
|
||||||
|
</NavigationContainer>
|
||||||
|
</SafeAreaProvider>
|
||||||
</View>
|
</View>
|
||||||
</OverflowMenuProvider>
|
</OverflowMenuProvider>
|
||||||
</PaperProvider>
|
</PaperProvider>
|
||||||
|
|
|
@ -3,7 +3,8 @@ import {withTheme} from 'react-native-paper';
|
||||||
import TabIcon from "./TabIcon";
|
import TabIcon from "./TabIcon";
|
||||||
import TabHomeIcon from "./TabHomeIcon";
|
import TabHomeIcon from "./TabHomeIcon";
|
||||||
import {Animated} from 'react-native';
|
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 = {
|
type Props = {
|
||||||
state: Object,
|
state: Object,
|
||||||
|
@ -11,6 +12,7 @@ type Props = {
|
||||||
navigation: Object,
|
navigation: Object,
|
||||||
theme: Object,
|
theme: Object,
|
||||||
collapsibleStack: Object,
|
collapsibleStack: Object,
|
||||||
|
safeArea: EdgeInsets
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
|
@ -37,13 +39,6 @@ class CustomTabBar extends React.Component<Props, State> {
|
||||||
barSynced: false,// Is the bar synced with the header for animations?
|
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) {
|
onItemPress(route: Object, currentIndex: number, destIndex: number) {
|
||||||
const event = this.props.navigation.emit({
|
const event = this.props.navigation.emit({
|
||||||
type: 'tabPress',
|
type: 'tabPress',
|
||||||
|
@ -135,28 +130,24 @@ class CustomTabBar extends React.Component<Props, State> {
|
||||||
render() {
|
render() {
|
||||||
this.props.navigation.addListener('state', this.onRouteChange);
|
this.props.navigation.addListener('state', this.onRouteChange);
|
||||||
return (
|
return (
|
||||||
<SafeAreaView>
|
|
||||||
<Animated.View
|
<Animated.View
|
||||||
ref={this.tabRef}
|
useNativeDriver
|
||||||
// animation={"fadeInUp"}
|
|
||||||
// duration={500}
|
|
||||||
// useNativeDriver
|
|
||||||
style={{
|
style={{
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
height: CustomTabBar.TAB_BAR_HEIGHT,
|
height: CustomTabBar.TAB_BAR_HEIGHT + this.props.safeArea.bottom,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
backgroundColor: this.props.theme.colors.surface,
|
backgroundColor: this.props.theme.colors.surface,
|
||||||
transform: [{translateY: this.state.translateY}]
|
transform: [{translateY: this.state.translateY}],
|
||||||
|
paddingBottom: this.props.safeArea.bottom,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{this.props.state.routes.map(this.renderIcon)}
|
{this.props.state.routes.map(this.renderIcon)}
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</SafeAreaView>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withTheme(CustomTabBar);
|
export default withSafeArea(withTheme(CustomTabBar));
|
||||||
|
|
14
src/utils/withSafeArea.js
Normal file
14
src/utils/withSafeArea.js
Normal file
|
@ -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 <Component
|
||||||
|
safeArea={safeArea}
|
||||||
|
ref={ref}
|
||||||
|
{...props}
|
||||||
|
/>;
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in a new issue