From 42beb660ca6209068ae7f0c1ea0e0bec1efac1c7 Mon Sep 17 00:00:00 2001 From: "satyajit.happy" Date: Thu, 10 Oct 2019 14:50:42 +0200 Subject: [PATCH] fix: improve keyboard handling with bottom tab bar --- packages/bottom-tabs/src/types.tsx | 2 +- .../bottom-tabs/src/views/BottomTabBar.tsx | 119 +++++++++--------- 2 files changed, 64 insertions(+), 57 deletions(-) diff --git a/packages/bottom-tabs/src/types.tsx b/packages/bottom-tabs/src/types.tsx index 69886620..c16bdbf8 100644 --- a/packages/bottom-tabs/src/types.tsx +++ b/packages/bottom-tabs/src/types.tsx @@ -139,7 +139,7 @@ export type BottomTabNavigationConfig = { export type BottomTabBarOptions = { /** - * Whether the tab bar gets hidden when the keyboard is shown. + * Whether the tab bar gets hidden when the keyboard is shown. Defaults to `false`. */ keyboardHidesTabBar?: boolean; /** diff --git a/packages/bottom-tabs/src/views/BottomTabBar.tsx b/packages/bottom-tabs/src/views/BottomTabBar.tsx index 614c7e5a..0f996edb 100644 --- a/packages/bottom-tabs/src/views/BottomTabBar.tsx +++ b/packages/bottom-tabs/src/views/BottomTabBar.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { + View, Animated, StyleSheet, Keyboard, @@ -32,7 +33,7 @@ const DEFAULT_MAX_TAB_ITEM_WIDTH = 125; export default class TabBarBottom extends React.Component { static defaultProps = { - keyboardHidesTabBar: true, + keyboardHidesTabBar: false, activeTintColor: '#007AFF', activeBackgroundColor: 'transparent', inactiveTintColor: '#8E8E93', @@ -82,7 +83,7 @@ export default class TabBarBottom extends React.Component { this.setState({ keyboard: true }, () => Animated.timing(this.state.visible, { toValue: 0, - duration: 150, + duration: 200, useNativeDriver: true, }).start() ); @@ -90,10 +91,12 @@ export default class TabBarBottom extends React.Component { private handleKeyboardHide = () => Animated.timing(this.state.visible, { toValue: 1, - duration: 100, + duration: 250, useNativeDriver: true, - }).start(() => { - this.setState({ keyboard: false }); + }).start(({ finished }) => { + if (finished) { + this.setState({ keyboard: false }); + } }); private handleLayout = (e: LayoutChangeEvent) => { @@ -305,58 +308,59 @@ export default class TabBarBottom extends React.Component { pointerEvents={ keyboardHidesTabBar && this.state.keyboard ? 'none' : 'auto' } - onLayout={this.handleLayout} > - {routes.map((route, index) => { - const focused = index === state.index; - const scene = { route, focused }; - const accessibilityLabel = getAccessibilityLabel({ - route, - }); - - const accessibilityRole = getAccessibilityRole({ - route, - }); - - const accessibilityStates = getAccessibilityStates(scene); - - const testID = getTestID({ route }); - - const backgroundColor = focused - ? activeBackgroundColor - : inactiveBackgroundColor; - - const ButtonComponent = - getButtonComponent({ route }) || - TouchableWithoutFeedbackWrapper; - - return ( - - onTabPress({ route })} - onLongPress={() => onTabLongPress({ route })} - testID={testID} - accessibilityLabel={accessibilityLabel} - accessibilityRole={accessibilityRole} - accessibilityStates={accessibilityStates} - style={[ - styles.tab, - { backgroundColor }, - this.shouldUseHorizontalLabels() - ? styles.tabLandscape - : styles.tabPortrait, - tabStyle, - ]} + + {routes.map((route, index) => { + const focused = index === state.index; + const scene = { route, focused }; + const accessibilityLabel = getAccessibilityLabel({ + route, + }); + + const accessibilityRole = getAccessibilityRole({ + route, + }); + + const accessibilityStates = getAccessibilityStates(scene); + + const testID = getTestID({ route }); + + const backgroundColor = focused + ? activeBackgroundColor + : inactiveBackgroundColor; + + const ButtonComponent = + getButtonComponent({ route }) || + TouchableWithoutFeedbackWrapper; + + return ( + - {this.renderIcon(scene)} - {this.renderLabel(scene)} - - - ); - })} + onTabPress({ route })} + onLongPress={() => onTabLongPress({ route })} + testID={testID} + accessibilityLabel={accessibilityLabel} + accessibilityRole={accessibilityRole} + accessibilityStates={accessibilityStates} + style={[ + styles.tab, + { backgroundColor }, + this.shouldUseHorizontalLabels() + ? styles.tabLandscape + : styles.tabPortrait, + tabStyle, + ]} + > + {this.renderIcon(scene)} + {this.renderLabel(scene)} + + + ); + })} + )} @@ -375,9 +379,12 @@ const styles = StyleSheet.create({ backgroundColor: '#fff', borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: 'rgba(0, 0, 0, .3)', - flexDirection: 'row', elevation: 8, }, + content: { + flex: 1, + flexDirection: 'row', + }, tab: { flex: 1, alignItems: isIos ? 'center' : 'stretch',