1
+ /* @flow */
2
+
1
3
import React from 'react' ;
2
4
import createReactClass from 'create-react-class' ;
3
5
import PropTypes from 'prop-types' ;
4
- import { FlatList } from 'react-native' ;
6
+ import { FlatList , Platform } from 'react-native' ;
5
7
import KeyboardAwareMixin from './KeyboardAwareMixin' ;
6
8
7
9
const KeyboardAwareFlatList = createReactClass ( {
@@ -11,27 +13,51 @@ const KeyboardAwareFlatList = createReactClass({
11
13
x : PropTypes . number ,
12
14
y : PropTypes . number ,
13
15
} ) ,
16
+ onScroll : PropTypes . func ,
17
+ enableOnAndroid : PropTypes . bool ,
14
18
} ,
15
19
mixins : [ KeyboardAwareMixin ] ,
16
20
17
21
componentWillMount : function ( ) {
18
- this . setViewIsInsideTabBar ( this . props . viewIsInsideTabBar )
19
- this . setResetScrollToCoords ( this . props . resetScrollToCoords )
22
+ this . setViewIsInsideTabBar ( ! ! this . props . viewIsInsideTabBar )
23
+ if ( this . props . resetScrollToCoords ) {
24
+ this . setResetScrollToCoords ( this . props . resetScrollToCoords )
25
+ }
26
+ } ,
27
+
28
+ onScroll : function ( e : SyntheticEvent & { nativeEvent : { contentOffset : number } } ) {
29
+ this . handleOnScroll ( e )
30
+ this . props . onScroll && this . props . onScroll ( e )
20
31
} ,
21
32
22
33
render : function ( ) {
34
+ const {
35
+ enableOnAndroid,
36
+ contentContainerStyle,
37
+ } = this . props
38
+
39
+ const {
40
+ keyboardSpace,
41
+ } = this . state
42
+
43
+ let newContentContainerStyle
44
+
45
+ if ( Platform . OS === 'android' && enableOnAndroid ) {
46
+ newContentContainerStyle = Object . assign ( { } , contentContainerStyle )
47
+ newContentContainerStyle . paddingBottom = ( newContentContainerStyle . paddingBottom || 0 ) + keyboardSpace
48
+ }
49
+
23
50
return (
24
51
< FlatList
25
52
ref = '_rnkasv_keyboardView'
26
53
keyboardDismissMode = 'interactive'
27
- contentInset = { { bottom : this . state . keyboardSpace } }
54
+ contentInset = { { bottom : keyboardSpace } }
55
+ automaticallyAdjustContentInsets = { false }
28
56
showsVerticalScrollIndicator = { true }
29
57
scrollEventThrottle = { 0 }
30
58
{ ...this . props }
31
- onScroll = { e => {
32
- this . handleOnScroll ( e )
33
- this . props . onScroll && this . props . onScroll ( e )
34
- } }
59
+ contentContainerStyle = { newContentContainerStyle || contentContainerStyle }
60
+ onScroll = { this . onScroll }
35
61
/>
36
62
)
37
63
} ,
0 commit comments