Skip to content

Commit 79317e8

Browse files
mmalfertheinervonovak
authored andcommitted
Fix issue react-navigation#618 - TabBarBottom should hide itself when Keyboard is activated (react-navigation#1764)
* Fix issue react-navigation#618 - TabBarBottom should hide when Keyboard is activated * fix undefined check for _keyboardDidHideSub * fix prettier * Update TabBarBottom.js * Update TabBarBottom.js * Update TabBarBottom.js * Update TabBarBottom.js * Update TabBarBottom.js
1 parent ffb95fd commit 79317e8

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

src/views/TabView/TabBarBottom.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
StyleSheet,
88
View,
99
Platform,
10+
Keyboard,
1011
} from 'react-native';
1112
import TabBarIcon from './TabBarIcon';
1213
import SafeAreaView from '../SafeAreaView';
@@ -46,11 +47,15 @@ type Props = {
4647
isLandscape: boolean,
4748
};
4849

50+
type State = {
51+
isVisible: boolean,
52+
};
53+
4954
const majorVersion = parseInt(Platform.Version, 10);
5055
const isIos = Platform.OS === 'ios';
5156
const useHorizontalTabs = majorVersion >= 11 && isIos;
5257

53-
class TabBarBottom extends React.PureComponent<Props> {
58+
class TabBarBottom extends React.PureComponent<Props, State> {
5459
// See https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/UIKitUICatalog/UITabBar.html
5560
static defaultProps = {
5661
activeTintColor: '#3478f6', // Default active tint color in iOS 10
@@ -64,6 +69,41 @@ class TabBarBottom extends React.PureComponent<Props> {
6469

6570
props: Props;
6671

72+
state: State = {
73+
isVisible: true,
74+
};
75+
76+
_keyboardDidShowSub = undefined;
77+
_keyboardDidHideSub = undefined;
78+
79+
componentWillMount() {
80+
this._keyboardDidShowSub = Keyboard.addListener(
81+
'keyboardDidShow',
82+
this._keyboardDidShow
83+
);
84+
this._keyboardDidHideSub = Keyboard.addListener(
85+
'keyboardDidHide',
86+
this._keyboardDidHide
87+
);
88+
}
89+
90+
componentWillUnmount() {
91+
this._keyboardDidShowSub !== undefined && this._keyboardDidShowSub.remove();
92+
this._keyboardDidHideSub !== undefined && this._keyboardDidHideSub.remove();
93+
}
94+
95+
_keyboardDidShow = () => {
96+
this.setState({
97+
isVisible: false,
98+
});
99+
};
100+
101+
_keyboardDidHide = () => {
102+
this.setState({
103+
isVisible: true,
104+
});
105+
};
106+
67107
_renderLabel = (scene: TabScene) => {
68108
const {
69109
position,
@@ -178,7 +218,7 @@ class TabBarBottom extends React.PureComponent<Props> {
178218
style,
179219
];
180220

181-
return (
221+
return this.state.isVisible ? (
182222
<Animated.View>
183223
<SafeAreaView
184224
style={tabBarStyle}
@@ -228,7 +268,7 @@ class TabBarBottom extends React.PureComponent<Props> {
228268
})}
229269
</SafeAreaView>
230270
</Animated.View>
231-
);
271+
) : null;
232272
}
233273
}
234274

0 commit comments

Comments
 (0)