@@ -13,7 +13,12 @@ import { ThemeColors, ThemeContext, NavigationRoute } from 'react-navigation';
1313
1414import CrossFadeIcon from './CrossFadeIcon' ;
1515import withDimensions from '../utils/withDimensions' ;
16- import { BottomTabBarProps , ButtonComponentProps } from '../types' ;
16+ import {
17+ BottomTabBarProps ,
18+ ButtonComponentProps ,
19+ KeyboardHidesTabBarAnimationConfig ,
20+ KeyboardAnimationConfig ,
21+ } from '../types' ;
1722
1823type State = {
1924 layout : { height : number ; width : number } ;
@@ -26,6 +31,22 @@ const isIos = Platform.OS === 'ios';
2631const isIOS11 = majorVersion >= 11 && isIos ;
2732
2833const DEFAULT_MAX_TAB_ITEM_WIDTH = 125 ;
34+ const DEFAULT_KEYBOARD_ANIMATION_CONFIG : KeyboardHidesTabBarAnimationConfig = {
35+ show : {
36+ animation : 'timing' ,
37+ config : {
38+ useNativeDriver : true ,
39+ duration : 150 ,
40+ } ,
41+ } ,
42+ hide : {
43+ animation : 'timing' ,
44+ config : {
45+ useNativeDriver : true ,
46+ duration : 100 ,
47+ } ,
48+ } ,
49+ } ;
2950
3051class TouchableWithoutFeedbackWrapper extends React . Component <
3152 ButtonComponentProps
@@ -64,6 +85,7 @@ class TouchableWithoutFeedbackWrapper extends React.Component<
6485class TabBarBottom extends React . Component < BottomTabBarProps , State > {
6586 static defaultProps = {
6687 keyboardHidesTabBar : true ,
88+ keyboardHidesTabBarAnimationConfig : DEFAULT_KEYBOARD_ANIMATION_CONFIG ,
6789 activeTintColor : {
6890 light : '#007AFF' ,
6991 dark : '#fff' ,
@@ -115,23 +137,58 @@ class TabBarBottom extends React.Component<BottomTabBarProps, State> {
115137 // @ts -ignore
116138 context : 'light' | 'dark' ;
117139
118- _handleKeyboardShow = ( ) =>
119- this . setState ( { keyboard : true } , ( ) =>
120- Animated . timing ( this . state . visible , {
140+ _getKeyboardAnimationConfigByType = (
141+ type : keyof KeyboardHidesTabBarAnimationConfig
142+ ) : KeyboardAnimationConfig => {
143+ const { keyboardHidesTabBarAnimationConfig } = this . props ;
144+ const defaultKeyboardAnimationConfig =
145+ DEFAULT_KEYBOARD_ANIMATION_CONFIG [ type ] ;
146+ const keyboardAnimationConfig =
147+ ( keyboardHidesTabBarAnimationConfig &&
148+ keyboardHidesTabBarAnimationConfig [ type ] ) ||
149+ defaultKeyboardAnimationConfig ;
150+
151+ // merge config only `timing` animation
152+ if (
153+ keyboardAnimationConfig &&
154+ keyboardAnimationConfig . animation === 'timing'
155+ ) {
156+ return {
157+ ...defaultKeyboardAnimationConfig ,
158+ ...keyboardAnimationConfig ,
159+ config : {
160+ ...defaultKeyboardAnimationConfig . config ,
161+ ...keyboardAnimationConfig . config ,
162+ } ,
163+ } ;
164+ }
165+
166+ return keyboardAnimationConfig as KeyboardAnimationConfig ;
167+ } ;
168+
169+ _handleKeyboardShow = ( ) => {
170+ this . setState ( { keyboard : true } , ( ) => {
171+ const { animation, config } = this . _getKeyboardAnimationConfigByType (
172+ 'show'
173+ ) ;
174+ Animated [ animation ] ( this . state . visible , {
121175 toValue : 0 ,
122- duration : 150 ,
123- useNativeDriver : true ,
124- } ) . start ( )
125- ) ;
176+ ... config ,
177+ } ) . start ( ) ;
178+ } ) ;
179+ } ;
126180
127- _handleKeyboardHide = ( ) =>
128- Animated . timing ( this . state . visible , {
181+ _handleKeyboardHide = ( ) => {
182+ const { animation, config } = this . _getKeyboardAnimationConfigByType (
183+ 'hide'
184+ ) ;
185+ Animated [ animation ] ( this . state . visible , {
129186 toValue : 1 ,
130- duration : 100 ,
131- useNativeDriver : true ,
187+ ...config ,
132188 } ) . start ( ( ) => {
133189 this . setState ( { keyboard : false } ) ;
134190 } ) ;
191+ } ;
135192
136193 _handleLayout = ( e : LayoutChangeEvent ) => {
137194 const { layout } = this . state ;
0 commit comments