@@ -13,7 +13,12 @@ import { ThemeColors, ThemeContext, NavigationRoute } from 'react-navigation';
13
13
14
14
import CrossFadeIcon from './CrossFadeIcon' ;
15
15
import withDimensions from '../utils/withDimensions' ;
16
- import { BottomTabBarProps , ButtonComponentProps } from '../types' ;
16
+ import {
17
+ BottomTabBarProps ,
18
+ ButtonComponentProps ,
19
+ KeyboardHidesTabBarAnimationConfig ,
20
+ KeyboardAnimationConfig ,
21
+ } from '../types' ;
17
22
18
23
type State = {
19
24
layout : { height : number ; width : number } ;
@@ -26,6 +31,22 @@ const isIos = Platform.OS === 'ios';
26
31
const isIOS11 = majorVersion >= 11 && isIos ;
27
32
28
33
const 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
+ } ;
29
50
30
51
class TouchableWithoutFeedbackWrapper extends React . Component <
31
52
ButtonComponentProps
@@ -64,6 +85,7 @@ class TouchableWithoutFeedbackWrapper extends React.Component<
64
85
class TabBarBottom extends React . Component < BottomTabBarProps , State > {
65
86
static defaultProps = {
66
87
keyboardHidesTabBar : true ,
88
+ keyboardHidesTabBarAnimationConfig : DEFAULT_KEYBOARD_ANIMATION_CONFIG ,
67
89
activeTintColor : {
68
90
light : '#007AFF' ,
69
91
dark : '#fff' ,
@@ -115,23 +137,58 @@ class TabBarBottom extends React.Component<BottomTabBarProps, State> {
115
137
// @ts -ignore
116
138
context : 'light' | 'dark' ;
117
139
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 , {
121
175
toValue : 0 ,
122
- duration : 150 ,
123
- useNativeDriver : true ,
124
- } ) . start ( )
125
- ) ;
176
+ ... config ,
177
+ } ) . start ( ) ;
178
+ } ) ;
179
+ } ;
126
180
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 , {
129
186
toValue : 1 ,
130
- duration : 100 ,
131
- useNativeDriver : true ,
187
+ ...config ,
132
188
} ) . start ( ( ) => {
133
189
this . setState ( { keyboard : false } ) ;
134
190
} ) ;
191
+ } ;
135
192
136
193
_handleLayout = ( e : LayoutChangeEvent ) => {
137
194
const { layout } = this . state ;
0 commit comments