1+ /* @flow */
2+
13import React from 'react' ;
24import createReactClass from 'create-react-class' ;
35import PropTypes from 'prop-types' ;
4- import { FlatList } from 'react-native' ;
6+ import { FlatList , Platform } from 'react-native' ;
57import KeyboardAwareMixin from './KeyboardAwareMixin' ;
68
79const KeyboardAwareFlatList = createReactClass ( {
@@ -11,27 +13,51 @@ const KeyboardAwareFlatList = createReactClass({
1113 x : PropTypes . number ,
1214 y : PropTypes . number ,
1315 } ) ,
16+ onScroll : PropTypes . func ,
17+ enableOnAndroid : PropTypes . bool ,
1418 } ,
1519 mixins : [ KeyboardAwareMixin ] ,
1620
1721 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 )
2031 } ,
2132
2233 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+
2350 return (
2451 < FlatList
2552 ref = '_rnkasv_keyboardView'
2653 keyboardDismissMode = 'interactive'
27- contentInset = { { bottom : this . state . keyboardSpace } }
54+ contentInset = { { bottom : keyboardSpace } }
55+ automaticallyAdjustContentInsets = { false }
2856 showsVerticalScrollIndicator = { true }
2957 scrollEventThrottle = { 0 }
3058 { ...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 }
3561 />
3662 )
3763 } ,
0 commit comments