Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/components/BottomNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SafeAreaView,
StyleSheet,
Platform,
Keyboard,
} from 'react-native';
import { polyfill } from 'react-lifecycles-compat';
import color from 'color';
Expand All @@ -22,7 +23,6 @@ import type { Theme } from '../types';
import type { IconSource } from './Icon';

const AnimatedText = Animated.createAnimatedComponent(Text);

type Route = $Shape<{
key: string,
title: string,
Expand Down Expand Up @@ -220,6 +220,11 @@ type State = {
* List of loaded tabs, tabs will be loaded when navigated to.
*/
loaded: number[],

/**
* Gracefully shows/hides tabs with respect to keyboards open and close events.
*/
shouldShowTabs: Boolean,
};

const MIN_RIPPLE_SCALE = 0.001; // Minimum scale is not 0 due to bug with animation
Expand Down Expand Up @@ -371,13 +376,29 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
current: index,
previous: 0,
loaded: [index],
shouldShowTabs: true,
};
}

componentDidMount() {
// Workaround for native animated bug in react-native@^0.57
// Context: https://github.com/callstack/react-native-paper/pull/637
this._animateToCurrentIndex();
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow);
this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardDidHide);

}

_keyboardDidShow = () => {
this.setState({
shouldShowTabs: false,
})
}

_keyboardDidHide = () => {
this.setState({
shouldShowTabs: true,
})
}

componentDidUpdate(prevProps) {
Expand Down Expand Up @@ -583,7 +604,7 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
);
})}
</View>
<Surface style={[styles.bar, barStyle, { backgroundColor }]}>
{this.state.shouldShowTabs && <Surface style={[styles.bar, barStyle, { backgroundColor }]}>
<SafeAreaView
style={[styles.items, { maxWidth: maxTabWidth * routes.length }]}
>
Expand Down Expand Up @@ -786,10 +807,15 @@ class BottomNavigation<T: *> extends React.Component<Props<T>, State> {
);
})}
</SafeAreaView>
</Surface>
</Surface>}
</View>
);
}

componentWillUnmount () {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}
}

polyfill(BottomNavigation);
Expand Down